You are here

public function Flexbox::buildOptionsForm in Views Flexbox 8

Provide a form to edit options for this plugin.

Overrides StylePluginBase::buildOptionsForm

File

src/Plugin/views/style/Flexbox.php, line 50

Class

Flexbox
Style plugin to render each item in a flexbox layout.

Namespace

Drupal\views_flexbox\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  $form['style'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Display Style'),
    '#default_value' => $this->options['style'],
    '#required' => TRUE,
    '#options' => [
      '_none_' => $this
        ->t('None'),
      'cards' => $this
        ->t('Card Layout'),
    ],
  ];
  $form['link_to_content'] = [
    '#title' => $this
      ->t('Link to content'),
    '#description' => $this
      ->t('Link card to content.'),
    '#type' => 'checkbox',
    '#default_value' => $this->options['link_to_content'],
    '#states' => [
      // Show this textfield only if the radio 'other' is selected above.
      'visible' => [
        ':input[name="style_options[style]"]' => [
          'value' => 'cards',
        ],
      ],
    ],
  ];
  if ($this
    ->usesFields()) {
    $form['link_source'] = [
      '#title' => $this
        ->t('Link Source'),
      '#description' => $this
        ->t('Link URL. You may use field tokens from as per the "Replacement patterns" used in "Rewrite the output of this field" for all fields.'),
      '#type' => 'textfield',
      '#default_value' => $this->options['link_source'],
      '#states' => [
        // Show this textfield only if the radio 'other' is selected above.
        'visible' => [
          ':input[name="style_options[link_to_content]"]' => [
            'checked' => TRUE,
          ],
        ],
      ],
    ];
  }
  $form['direction'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Flex Direction'),
    '#default_value' => $this->options['direction'],
    '#required' => TRUE,
    '#options' => [
      'row' => $this
        ->t('Row'),
      'row-reverse' => $this
        ->t('Row Reverse'),
      'column' => $this
        ->t('Column'),
      'column-reverse' => $this
        ->t('Column Reverse'),
    ],
  ];
  $form['justify'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Justify Content'),
    '#default_value' => $this->options['justify'],
    '#required' => TRUE,
    '#options' => [
      'start' => $this
        ->t('Start'),
      'end' => $this
        ->t('End'),
      'center' => $this
        ->t('Center'),
      'space-between' => $this
        ->t('Space Between'),
      'space-around' => $this
        ->t('Space Around'),
      'space-evenly' => $this
        ->t('Space Evenly'),
    ],
  ];
  $form['align_items'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Align Items'),
    '#default_value' => $this->options['align_items'],
    '#required' => TRUE,
    '#options' => [
      'start' => $this
        ->t('Start'),
      'end' => $this
        ->t('End'),
      'center' => $this
        ->t('Center'),
      'strech' => $this
        ->t('Stretch'),
      'baseline' => $this
        ->t('Baseline'),
    ],
  ];
  $form['align_content'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Align Content'),
    '#default_value' => $this->options['align_content'],
    '#required' => TRUE,
    '#options' => [
      'start' => $this
        ->t('Start'),
      'end' => $this
        ->t('End'),
      'center' => $this
        ->t('Center'),
      'strech' => $this
        ->t('Stretch'),
      'space-between' => $this
        ->t('Space Between'),
      'space-around' => $this
        ->t('Space Around'),
    ],
  ];
  $form['item_class_default'] = [
    '#title' => $this
      ->t('Default item classes'),
    '#description' => $this
      ->t('Adds the default views style classes like item-1 to the output. You can use this to quickly reduce the amount of markup the view provides by default, at the cost of making it more difficult to apply CSS.'),
    '#type' => 'checkbox',
    '#default_value' => $this->options['item_class_default'],
  ];
  $form['item_class_custom'] = [
    '#title' => $this
      ->t('Custom item classes'),
    '#description' => $this
      ->t('Additional classes to provide on each item. Separated by a space.'),
    '#type' => 'textfield',
    '#default_value' => $this->options['item_class_custom'],
  ];
  if ($this
    ->usesFields()) {
    $form['item_class_custom']['#description'] .= ' ' . $this
      ->t('You may use field tokens from as per the "Replacement patterns" used in "Rewrite the output of this field" for all fields.');
  }
}