You are here

public function ViewsBootstrapGrid::buildOptionsForm in Views Bootstrap 8.4

Same name and namespace in other branches
  1. 8.3 src/Plugin/views/style/ViewsBootstrapGrid.php \Drupal\views_bootstrap\Plugin\views\style\ViewsBootstrapGrid::buildOptionsForm()

Provide a form to edit options for this plugin.

Overrides StylePluginBase::buildOptionsForm

File

src/Plugin/views/style/ViewsBootstrapGrid.php, line 66

Class

ViewsBootstrapGrid
Style plugin to render each item in an ordered or unordered list.

Namespace

Drupal\views_bootstrap\Plugin\views\style

Code

public function buildOptionsForm(&$form, FormStateInterface $form_state) {
  parent::buildOptionsForm($form, $form_state);
  foreach (ViewsBootstrap::getBreakpoints() as $breakpoint) {
    $breakpoint_option = "col_{$breakpoint}";
    $prefix = 'col' . ($breakpoint != 'xs' ? '-' . $breakpoint : '');
    $form[$breakpoint_option] = [
      '#type' => 'select',
      '#title' => $this
        ->t("Column width of items at @breakpoint breakpoint", [
        '@breakpoint' => $breakpoint,
      ]),
      '#default_value' => isset($this->options[$breakpoint_option]) ? $this->options[$breakpoint_option] : NULL,
      '#description' => $this
        ->t("Set the number of columns each item should take up at the @breakpoint breakpoint and higher.", [
        '@breakpoint' => $breakpoint,
      ]),
      '#options' => [
        'none' => $this
          ->t('None (or inherit from previous)'),
        $prefix => $this
          ->t('Equal'),
        $prefix . '-auto' => $this
          ->t('Fit to content'),
      ],
    ];
    foreach ([
      1,
      2,
      3,
      4,
      6,
      12,
    ] as $width) {
      $form[$breakpoint_option]['#options'][$prefix . "-{$width}"] = $this
        ->formatPlural(12 / $width, '@width (@count column per row)', '@width (@count columns per row)', [
        '@width' => $width,
      ]);
    }
  }
}