Removing config folder
[project/fb_likebox.git] / lib / Drupal / fb_likebox / Plugin / Block / FBLikeboxBlock.php
1 <?php
2 /**
3 * @file
4 * Contains \Drupal\fb_likebox\Plugin\Block\FBLikeboxBlock.
5 */
6
7 namespace Drupal\fb_likebox\Plugin\Block;
8
9 use Drupal\block\BlockBase;
10 use Drupal\Component\Annotation\Plugin;
11 use Drupal\Core\Annotation\Translation;
12 use Drupal\Core\Config;
13
14 /**
15 * Provides a configurable block with Facebook Likebox's plugin.
16 *
17 * @Plugin(
18 * id = "fb_likebox_block",
19 * admin_label = @Translation("FB Likebox"),
20 * module = "fb_likebox"
21 * )
22 */
23 class FBLikeboxBlock extends BlockBase {
24
25 /**
26 * Overrides \Drupal\block\BlockBase::settings().
27 */
28 public function settings() {
29 return array(
30 'properties' => array(
31 'administrative' => TRUE
32 ),
33 'fb_likebox_url' => 'https://www.facebook.com/wikisaber.es',
34 'fb_likebox_colorscheme' => 'light',
35 'fb_likebox_header' => 'true',
36 'fb_likebox_stream' => 'true',
37 'fb_likebox_show_faces' => 'true',
38 'fb_likebox_force_wall' => 'false',
39 'fb_likebox_width' => 292,
40 'fb_likebox_height' => 556,
41 'fb_likebox_show_border' => 'true',
42 );
43 }
44 /**
45 * Overrides \Drupal\block\BlockBase::blockForm().
46 */
47 public function blockForm($form, &$form_state) {
48 // Facebook Widget settings.
49 $form['fb_likebox_display_settings'] = array(
50 '#type' => 'fieldset',
51 '#title' => t('Display options'),
52 '#collapsible' => FALSE,
53 );
54 $form['fb_likebox_theming_settings'] = array(
55 '#type' => 'fieldset',
56 '#title' => t('Theming Settings'),
57 '#collapsible' => FALSE,
58 );
59 // Display settings.
60 $form['fb_likebox_display_settings']['fb_likebox_url'] = array(
61 '#type' => 'textfield',
62 '#title' => t('Facebook Page URL'),
63 '#default_value' => $this->configuration['fb_likebox_url'],
64 '#description' => t('Enter the Facebook Page URL. I.e.: https://www.facebook.com/wikisaber.es'),
65 '#required' => TRUE,
66 );
67 $form['fb_likebox_display_settings']['fb_likebox_colorscheme'] = array(
68 '#type' => 'select',
69 '#title' => t('Color Scheme'),
70 '#default_value' => $this->configuration['fb_likebox_colorscheme'],
71 '#options' => array(
72 'light' => t('Light'),
73 'dark' => t('Dark'),
74 ),
75 '#description' => t("The color scheme for the plugin. Options: 'light', 'dark'."),
76 '#required' => TRUE,
77 );
78 $form['fb_likebox_display_settings']['fb_likebox_header'] = array(
79 '#type' => 'select',
80 '#title' => t('Header'),
81 '#default_value' => $this->configuration['fb_likebox_header'],
82 '#options' => array(
83 'false' => t('No'),
84 'true' => t('Yes'),
85 ),
86 '#description' => t('Specifies whether to display the Facebook header at the top of the plugin.'),
87 '#required' => TRUE,
88 );
89 $form['fb_likebox_display_settings']['fb_likebox_stream'] = array(
90 '#type' => 'select',
91 '#title' => t('Stream'),
92 '#default_value' => $this->configuration['fb_likebox_stream'],
93 '#options' => array(
94 'false' => t('No'),
95 'true' => t('Yes'),
96 ),
97 '#description' => t("Specifies whether to display a stream of the latest posts from the Page's wall."),
98 '#required' => TRUE,
99 );
100 $form['fb_likebox_display_settings']['fb_likebox_show_faces'] = array(
101 '#type' => 'select',
102 '#title' => t('Show Faces'),
103 '#default_value' => $this->configuration['fb_likebox_show_faces'],
104 '#options' => array(
105 'false' => t('No'),
106 'true' => t('Yes'),
107 ),
108 '#description' => t('Specifies whether or not to display profile photos in the plugin.'),
109 '#required' => TRUE,
110 );
111 $form['fb_likebox_display_settings']['fb_likebox_force_wall'] = array(
112 '#type' => 'select',
113 '#title' => t('Force wall'),
114 '#default_value' => $this->configuration['fb_likebox_force_wall'],
115 '#options' => array(
116 'false' => t('No'),
117 'true' => t('Yes'),
118 ),
119 '#description' => t('For Places: specifies whether the stream contains posts from the Places wall or just checkins from friends.'),
120 '#required' => TRUE,
121 );
122 // Theming settings.
123 $form['fb_likebox_theming_settings']['fb_likebox_width'] = array(
124 '#type' => 'textfield',
125 '#title' => t('Width'),
126 '#default_value' => $this->configuration['fb_likebox_width'],
127 '#description' => t('The width of the Facebook likebox in pixels.'),
128 '#required' => TRUE,
129 );
130 $form['fb_likebox_theming_settings']['fb_likebox_height'] = array(
131 '#type' => 'textfield',
132 '#title' => t('Height'),
133 '#default_value' => $this->configuration['fb_likebox_height'],
134 '#description' => t('The height of the plugin in pixels. The default height provided by Facebook API varies based on number of faces to display, and whether the stream is displayed. With the stream displayed, and 10 faces the default height is 556px. With no faces, and no stream the default height is 63px. You will need to play with these value if you haved disabled those features and you want the block to be displayed without an empty section.'),
135 '#required' => TRUE,
136 );
137 $form['fb_likebox_theming_settings']['fb_likebox_show_border'] = array(
138 '#type' => 'select',
139 '#title' => t('Border'),
140 '#default_value' => $this->configuration['fb_likebox_show_border'],
141 '#options' => array(
142 'false' => t('No'),
143 'true' => t('Yes'),
144 ),
145 '#description' => t('Specifies whether or not to show a border around the plugin. Set to false to style the iframe with your custom CSS.'),
146 '#required' => TRUE,
147 );
148 return $form;
149 }
150
151 /**
152 * Overrides \Drupal\block\BlockBase::blockValidate().
153 */
154 public function blockValidate($form, &$form_state) {
155 // Facebook display settings validation.
156 $fb_url = $form_state['values']['fb_likebox_display_settings']['fb_likebox_url'];
157 if (!valid_url($fb_url, TRUE)) {
158 form_set_error('fb_likebox_url', t('Please enter a valid url'));
159 }
160 // Facebook theming settings validation.
161 $fb_width = $form_state['values']['fb_likebox_theming_settings']['fb_likebox_width'];
162 if (!is_numeric($fb_width) || intval($fb_width) <= 0) {
163 form_set_error('fb_likebox_width', t('Width should be a number bigger than 0'));
164 }
165 $fb_height = $form_state['values']['fb_likebox_theming_settings']['fb_likebox_height'];
166 if (!is_numeric($fb_height) || intval($fb_height) <= 0) {
167 form_set_error('fb_likebox_height', t('Height should be a number bigger than 0'));
168 }
169 }
170
171 /**
172 * Overrides \Drupal\block\BlockBase::blockSubmit().
173 */
174 public function blockSubmit($form, &$form_state) {
175 $this->configuration['fb_likebox_url'] = $form_state['values']['fb_likebox_display_settings']['fb_likebox_url'];
176 $this->configuration['fb_likebox_colorscheme'] = $form_state['values']['fb_likebox_display_settings']['fb_likebox_colorscheme'];
177 $this->configuration['fb_likebox_header'] = $form_state['values']['fb_likebox_display_settings']['fb_likebox_header'];
178 $this->configuration['fb_likebox_stream'] = $form_state['values']['fb_likebox_display_settings']['fb_likebox_stream'];
179 $this->configuration['fb_likebox_show_faces'] = $form_state['values']['fb_likebox_display_settings']['fb_likebox_show_faces'];
180 $this->configuration['fb_likebox_force_wall'] = $form_state['values']['fb_likebox_display_settings']['fb_likebox_force_wall'];
181 $this->configuration['fb_likebox_width'] = $form_state['values']['fb_likebox_theming_settings']['fb_likebox_width'];
182 $this->configuration['fb_likebox_height'] = $form_state['values']['fb_likebox_theming_settings']['fb_likebox_height'];
183 $this->configuration['fb_likebox_show_border'] = $form_state['values']['fb_likebox_theming_settings']['fb_likebox_show_border'];
184 }
185
186 /**
187 * Implements \Drupal\block\BlockBase::build().
188 */
189 public function build() {
190 return array(
191 '#theme' => 'fb_likebox_block',
192 '#fb_url' => $this->configuration['fb_likebox_url'],
193 '#fb_colorscheme' => $this->configuration['fb_likebox_colorscheme'],
194 '#fb_header' => $this->configuration['fb_likebox_header'],
195 '#fb_stream' => $this->configuration['fb_likebox_stream'],
196 '#fb_show_faces' => $this->configuration['fb_likebox_show_faces'],
197 '#fb_force_wall' => $this->configuration['fb_likebox_force_wall'],
198 '#fb_width' => $this->configuration['fb_likebox_width'],
199 '#fb_height' => $this->configuration['fb_likebox_height'],
200 '#fb_show_border' => $this->configuration['fb_likebox_show_border'],
201
202 );
203 }
204 }