More tidying.
[yaffs-website] / web / modules / contrib / views_bootstrap / src / Plugin / views / style / ViewsBootstrapMediaObject.php
1 <?php
2
3 namespace Drupal\views_bootstrap\Plugin\views\style;
4
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\style\StylePluginBase;
7
8 /**
9  * Style plugin to render each item as a row in a Bootstrap Media Object.
10  *
11  * @ingroup views_style_plugins
12  *
13  * @ViewsStyle(
14  *   id = "views_bootstrap_media_object",
15  *   title = @Translation("Bootstrap Media Object"),
16  *   help = @Translation("Displays rows in a Bootstrap Media Object."),
17  *   theme = "views_bootstrap_media_object",
18  *   theme_file = "../views_bootstrap.theme.inc",
19  *   display_types = {"normal"}
20  * )
21  */
22 class ViewsBootstrapMediaObject extends StylePluginBase {
23
24   /**
25    * Does the style plugin for itself support to add fields to it's output.
26    *
27    * @var bool
28    */
29   protected $usesFields = TRUE;
30
31   /**
32    * Definition.
33    */
34   protected function defineOptions() {
35     $options = parent::defineOptions();
36
37     $options['image_field'] = ['default' => []];
38     $options['heading_field'] = ['default' => []];
39     $options['body_field'] = ['default' => []];
40     $options['image_class'] = ['default' => 'media-left'];
41
42     return $options;
43   }
44
45   /**
46    * Render the given style.
47    */
48   public function buildOptionsForm(&$form, FormStateInterface $form_state) {
49     parent::buildOptionsForm($form, $form_state);
50
51     $fields = $this->displayHandler->getFieldLabels(TRUE);
52     $optionalFields = ['' => $this->t('<None>')];
53     $optionalFields += $this->displayHandler->getFieldLabels(TRUE);
54
55     $form['heading_field'] = [
56       '#type' => 'select',
57       '#title' => $this->t('Heading field'),
58       '#options' => $fields,
59       '#required' => TRUE,
60       '#default_value' => $this->options['heading_field'],
61       '#description' => $this->t('Select the field that will be used as the media object heading.'),
62     ];
63
64     $form['image_field'] = [
65       '#type' => 'select',
66       '#title' => $this->t('Image field'),
67       '#options' => $this->displayHandler->getFieldLabels(TRUE),
68       '#required' => TRUE,
69       '#default_value' => $this->options['image_field'],
70       '#description' => $this->t('Select the field that will be used as the media object image.'),
71     ];
72
73     $form['image_class'] = [
74       '#type' => 'radios',
75       '#title' => $this->t('Image Alignment'),
76       '#options' => [
77         'media-left' => $this->t('Left'),
78         'media-right' => $this->t('Right'),
79         'media-middle' => $this->t('Middle'),
80       ],
81       '#default_value' => $this->options['image_class'],
82       '#description' => t('Align the media object image left or right.'),
83     ];
84
85     $form['body_field'] = [
86       '#type' => 'select',
87       '#title' => $this->t('Body field'),
88       '#options' => $optionalFields,
89       '#required' => FALSE,
90       '#default_value' => $this->options['body_field'],
91       '#description' => $this->t('Select the field that will be used as the media object body.'),
92     ];
93
94   }
95
96 }