You are here

public function GridDialog::buildLayoutStep in CKEditor Bootstrap Grid 2.0.x

Builds the layout selection step.

Parameters

array $form: The form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

Return value

array The form part.

1 call to GridDialog::buildLayoutStep()
GridDialog::buildForm in src/Form/GridDialog.php
Form constructor.

File

src/Form/GridDialog.php, line 189

Class

GridDialog
Creates a grid dialog form for use in CKEditor.

Namespace

Drupal\ckeditor_bs_grid\Form

Code

public function buildLayoutStep(array $form, FormStateInterface $form_state) {
  $config = $this
    ->config('ckeditor_bs_grid.settings');
  $settings = $form_state
    ->get('bs_grid_settings');
  $form['#title'] = $this
    ->t("Choose a layout");
  $form['add_container'] = [
    '#title' => $this
      ->t('Add Container'),
    '#type' => 'checkbox',
    '#default_value' => $settings['add_container'] ?? FALSE,
    '#attributes' => [
      'class' => [
        'bs_grid-add-container',
      ],
    ],
  ];
  $form['container_type'] = [
    '#title' => $this
      ->t('Container Type'),
    '#type' => 'radios',
    '#options' => [
      'default' => $this
        ->t('Default'),
      'fluid' => $this
        ->t('Fluid'),
      'wrapper' => $this
        ->t('Wrapper'),
    ],
    '#default_value' => $settings['container_type'] ?? 'default',
    '#states' => [
      'visible' => [
        '.bs_grid-add-container' => [
          'checked' => TRUE,
        ],
      ],
    ],
  ];

  // @todo detect row class override.
  $form['no_gutter'] = [
    '#title' => $this
      ->t('No Gutters'),
    '#type' => 'checkbox',
    '#default_value' => $settings['no_gutter'] ?? FALSE,
  ];

  // Default.
  $num_cols = (int) $settings['num_columns'];
  $options = [
    'none' => $this
      ->t('None (advanced)'),
  ];
  $available_breakpoints = array_filter($settings['editor_settings']['available_breakpoints']);
  foreach ($config
    ->get('breakpoints') as $class => $breakpoint) {
    if (!isset($available_breakpoints[$class])) {
      continue;
    }
    $prefix = $breakpoint['prefix'];
    $form['breakpoints'][$prefix] = [
      '#title' => $breakpoint['label'],
      '#type' => 'details',
      '#open' => FALSE,
    ];
    foreach ($breakpoint['columns'][$num_cols]['layouts'] as $layout) {
      $options[implode('_', $layout['settings'])] = $layout['label'];
    }
    $form['breakpoints'][$prefix]['layout'] = [
      '#type' => 'radios',
      '#options' => $options,
      '#default_value' => $settings['breakpoints'][$prefix]['layout'] ?? 'none',
      '#attributes' => [
        'data-bs-grid-option' => TRUE,
      ],
    ];
  }

  // @todo Refactor for repetition here.
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['back'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Back'),
    '#button_type' => 'primary',
    // No regular submit-handler. This form only works via JavaScript.
    '#submit' => [],
    '#ajax' => [
      'callback' => '::submitBackStep',
      'event' => 'click',
    ],
    '#attributes' => [
      'class' => [
        'js-button-back',
      ],
    ],
  ];
  $form['actions']['save_modal'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Save'),
    '#button_type' => 'primary',
    // No regular submit-handler. This form only works via JavaScript.
    '#submit' => [],
    '#ajax' => [
      'callback' => '::submitDialog',
      'event' => 'click',
    ],
    '#attributes' => [
      'class' => [
        'js-button-next',
      ],
    ],
  ];
  $form['actions']['advanced'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Advanced Settings'),
    '#button_type' => 'primary',
    // No regular submit-handler. This form only works via JavaScript.
    '#submit' => [],
    '#ajax' => [
      'callback' => '::submitStep',
      'event' => 'click',
    ],
    '#attributes' => [
      'class' => [
        'js-button-next',
      ],
    ],
  ];
  return $form;
}