You are here

protected function GridWidget::getGridSelector in Paragraphs grid 8

Generate select form field for css classes.

Parameters

array $bp_definition: The config definition of the breakpoints.

array $definition: The grid definition.

array $defaults: The current field value.

Return value

array Render array of a select form field for grid classes.

1 call to GridWidget::getGridSelector()
GridWidget::formElement in src/Plugin/Field/FieldWidget/GridWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/GridWidget.php, line 275

Class

GridWidget
Plugin implementation of the 'grid_widget' widget.

Namespace

Drupal\paragraphs_grid\Plugin\Field\FieldWidget

Code

protected function getGridSelector(array $bp_definition, array $definition, array $defaults = []) {
  $options = $this
    ->getGridOptions($bp_definition['fragment'], $bp_definition['cols'], $definition);
  $default_values = array_intersect($defaults, array_keys($options));
  $select = [
    '#type' => 'select',
    '#title' => $definition['label'],
    '#size' => 1,
    '#default_value' => reset($default_values),
    '#options' => $options,
  ];
  if (!$definition['default']) {
    $select['#empty_value'] = '';
    $select['#empty_option'] = '';
  }
  return $select;
}