Version 1
[yaffs-website] / web / themes / contrib / bootstrap / src / Plugin / Form / NodePreviewFormSelect.php
1 <?php
2 /**
3  * @file
4  * Contains \Drupal\bootstrap\Plugin\Form\NodePreviewFormSelect.
5  */
6
7 namespace Drupal\bootstrap\Plugin\Form;
8
9 use Drupal\bootstrap\Annotation\BootstrapForm;
10 use Drupal\bootstrap\Bootstrap;
11 use Drupal\bootstrap\Utility\Element;
12 use Drupal\Core\Form\FormStateInterface;
13
14 /**
15  * Implements hook_form_FORM_ID_alter().
16  *
17  * @ingroup plugins_form
18  *
19  * @BootstrapForm("node_preview_form_select")
20  */
21 class NodePreviewFormSelect extends FormBase {
22
23   /**
24    * {@inheritdoc}
25    */
26   public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
27     $form->addClass(['form-inline', 'bg-info', 'text-center', 'clearfix']);
28
29     // Backlink.
30     $options = $form->backlink->getProperty('options', []);
31
32     $form->backlink->addClass(isset($options['attributes']['class']) ? $options['attributes']['class'] : []);
33     $form->backlink->addClass(['btn', 'btn-info', 'pull-left']);
34     $form->backlink->setButtonSize();
35     $form->backlink->setIcon(Bootstrap::glyphicon('chevron-left'));
36
37     // Ensure the UUID is set.
38     if ($uuid = $form->uuid->getProperty('value')) {
39       $options['query'] = ['uuid' => $uuid];
40     }
41
42     // Override the options attributes.
43     $options['attributes'] = $form->backlink->getAttributes()->getArrayCopy();
44
45     $form->backlink->setProperty('options', $options);
46
47
48     // View mode.
49     $form->view_mode->addClass('pull-right', $form::WRAPPER);
50   }
51
52 }