087ee672bbd2679e5a6d9a66324460c45a8ce19d
[yaffs-website] / src / Plugin / Preprocess / FieldMultipleValueForm.php
1 <?php
2 /**
3  * @file
4  * Contains \Drupal\bootstrap\Plugin\Preprocess\FieldMultipleValueForm.
5  */
6
7 namespace Drupal\bootstrap\Plugin\Preprocess;
8
9 use Drupal\bootstrap\Annotation\BootstrapPreprocess;
10 use Drupal\bootstrap\Utility\Element;
11 use Drupal\bootstrap\Utility\Variables;
12
13 /**
14  * Pre-processes variables for the "field_multiple_value_form" theme hook.
15  *
16  * @ingroup plugins_preprocess
17  *
18  * @BootstrapPreprocess("field_multiple_value_form")
19  */
20 class FieldMultipleValueForm extends PreprocessBase implements PreprocessInterface {
21
22   /**
23    * {@inheritdoc}
24    */
25   public function preprocessElement(Element $element, Variables $variables) {
26     // Wrap header columns in label element for Bootstrap.
27     if ($variables['multiple']) {
28       $header = [
29         [
30           'data' => [
31             '#prefix' => '<label class="label">',
32             'title' => ['#markup' => $element->getProperty('title')],
33             '#suffix' => '</label>',
34           ],
35           'colspan' => 2,
36           'class' => [
37             'field-label',
38             !empty($element['#required']) ? 'form-required' : '',
39           ],
40         ],
41         t('Order', [], ['context' => 'Sort order']),
42       ];
43
44       $variables['table']['#header'] = $header;
45     }
46   }
47
48 }