Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / block_class / block_class.module
1 <?php
2
3 /**
4  * @file
5  * Module for adding classes to blocks.
6  */
7
8 use Drupal\block\Entity\Block;
9
10 /**
11  * Implements hook_form_FORM_ID_alter().
12  */
13 function block_class_form_block_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
14   if (\Drupal::currentUser()->hasPermission('administer block classes')) {
15
16     /** @var \Drupal\block\BlockInterface $block */
17     $block = $form_state->getFormObject()->getEntity();
18
19     // This will automatically be saved in the third party settings.
20     $form['third_party_settings']['#tree'] = TRUE;
21     $form['third_party_settings']['block_class']['classes'] = array(
22       '#type' => 'textfield',
23       '#title' => t('CSS class(es)'),
24       '#description' => t('Customize the styling of this block by adding CSS classes. Separate multiple classes by spaces.'),
25       '#default_value' => $block->getThirdPartySetting('block_class', 'classes'),
26     );
27
28   }
29 }
30
31 /**
32  * Implements hook_preprocess_HOOK().
33  */
34 function block_class_preprocess_block(&$variables) {
35   // Blocks coming from page manager widget does not have id.
36   if (!empty($variables['elements']['#id'])) {
37     $block = Block::load($variables['elements']['#id']);
38     if ($classes = $block->getThirdPartySetting('block_class', 'classes')) {
39       $variables['attributes']['class'][] = $classes;
40     }
41   }
42 }