You are here

protected function GridWidget::getGridOptions in Paragraphs grid 8

Returns options for a select form field.

Parameters

string $breakpoint: Current breakpoint.

int $col_num: Number of columns to generate classes.

array $definition: Definition of the cell property.

Return value

array Form select options.

1 call to GridWidget::getGridOptions()
GridWidget::getGridSelector in src/Plugin/Field/FieldWidget/GridWidget.php
Generate select form field for css classes.

File

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

Class

GridWidget
Plugin implementation of the 'grid_widget' widget.

Namespace

Drupal\paragraphs_grid\Plugin\Field\FieldWidget

Code

protected function getGridOptions($breakpoint, $col_num, array $definition) {
  $options = [];
  if ($definition['asc']) {
    for ($count = 0; $count <= $col_num; $count++) {
      $css_class = str_replace([
        '%cols',
        '%bp',
      ], [
        $count,
        $breakpoint,
      ], $definition['formatter']);
      $options[$css_class] = "{$count}";
    }
  }
  else {
    $count = $col_num;
    while ($count >= 1) {
      $css_class = str_replace([
        '%cols',
        '%bp',
      ], [
        $count,
        $breakpoint,
      ], $definition['formatter']);
      $options[$css_class] = "{$count}";
      $count--;
    }
  }
  if (isset($definition['additional'])) {
    foreach ($definition['additional'] as $add_opts) {
      $css_class = str_replace('%bp', $breakpoint, $add_opts['class']);
      $options[$css_class] = $add_opts['name'];
    }
  }
  return $options;
}