3 namespace Drupal\views_bootstrap\Plugin\views\style;
5 use Drupal\Core\Form\FormStateInterface;
6 use Drupal\views\Plugin\views\style\StylePluginBase;
9 * Style plugin to render each item as a row in a Bootstrap Media Object.
11 * @ingroup views_style_plugins
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"}
22 class ViewsBootstrapMediaObject extends StylePluginBase {
25 * Does the style plugin for itself support to add fields to it's output.
29 protected $usesFields = TRUE;
34 protected function defineOptions() {
35 $options = parent::defineOptions();
37 $options['image_field'] = ['default' => []];
38 $options['heading_field'] = ['default' => []];
39 $options['body_field'] = ['default' => []];
40 $options['image_class'] = ['default' => 'media-left'];
46 * Render the given style.
48 public function buildOptionsForm(&$form, FormStateInterface $form_state) {
49 parent::buildOptionsForm($form, $form_state);
51 $fields = $this->displayHandler->getFieldLabels(TRUE);
52 $optionalFields = ['' => $this->t('<None>')];
53 $optionalFields += $this->displayHandler->getFieldLabels(TRUE);
55 $form['heading_field'] = [
57 '#title' => $this->t('Heading field'),
58 '#options' => $fields,
60 '#default_value' => $this->options['heading_field'],
61 '#description' => $this->t('Select the field that will be used as the media object heading.'),
64 $form['image_field'] = [
66 '#title' => $this->t('Image field'),
67 '#options' => $this->displayHandler->getFieldLabels(TRUE),
69 '#default_value' => $this->options['image_field'],
70 '#description' => $this->t('Select the field that will be used as the media object image.'),
73 $form['image_class'] = [
75 '#title' => $this->t('Image Alignment'),
77 'media-left' => $this->t('Left'),
78 'media-right' => $this->t('Right'),
79 'media-middle' => $this->t('Middle'),
81 '#default_value' => $this->options['image_class'],
82 '#description' => t('Align the media object image left or right.'),
85 $form['body_field'] = [
87 '#title' => $this->t('Body field'),
88 '#options' => $optionalFields,
90 '#default_value' => $this->options['body_field'],
91 '#description' => $this->t('Select the field that will be used as the media object body.'),