You are here

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

Builds the column 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::buildSelectStep()
GridDialog::buildForm in src/Form/GridDialog.php
Form constructor.

File

src/Form/GridDialog.php, line 121

Class

GridDialog
Creates a grid dialog form for use in CKEditor.

Namespace

Drupal\ckeditor_bs_grid\Form

Code

public function buildSelectStep(array $form, FormStateInterface $form_state) {
  $settings = $form_state
    ->get('bs_grid_settings');
  $form['#title'] = $this
    ->t("Select columns");
  $columns = [];
  $available_cols = array_filter($settings['editor_settings']['available_columns']);
  foreach ($available_cols as $column) {
    $title = $this
      ->t('Column @num', [
      '@num' => $column,
    ]);
    $img = drupal_get_path('module', 'ckeditor_bs_grid') . '/images/ui/col_' . $column . '.png';
    $img_src = '<img src="/' . $img . '" title="' . $title . '" />';
    $columns[$column] = $img_src . '<p>' . $this
      ->t('Column @num', [
      '@num' => $column,
    ]) . '</p>';
  }

  // @todo Need to find a better way around this.
  if (!empty($settings['saved'])) {
    $form['bs_grid_settings'] = [
      '#type' => 'hidden',
      '#value' => Json::encode($settings),
    ];
  }

  // @todo Make this configurable from text format.
  $form['num_columns'] = [
    '#title' => $this
      ->t('Select Number of Columns'),
    '#type' => 'radios',
    '#options' => $columns,
    '#default_value' => $settings['num_columns'] ?? 1,
    '#attributes' => [
      'disabled' => $settings['saved'] ?? FALSE,
    ],
    '#prefix' => $this
      ->t('Read-only on existing elements.'),
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['next'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Next'),
    '#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;
}