You are here

public function EditRowModalForm::buildForm in Dynamic Layouts 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/EditRowModalForm.php, line 55

Class

EditRowModalForm
EditRowModalForm class.

Namespace

Drupal\dynamic_layouts\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, $options = NULL) {
  $dynamic_layout_id = \Drupal::request()
    ->get(Constants::DYNAMIC_LAYOUT_ID);
  $row_id = \Drupal::request()
    ->get(Constants::ROW_ID);
  $row_classes = '';

  /* @var \Drupal\dynamic_layouts\DynamicLayoutInterface $config_entity */
  if ($dynamic_layout_id !== NULL && ($config_entity = $this->entityTypeManager
    ->getStorage('dynamic_layout')
    ->load($dynamic_layout_id))) {
    $row_classes = $config_entity
      ->getRowClasses($row_id);
  }
  $form['#prefix'] = '<div id="modal_form">';
  $form['#suffix'] = '</div>';

  // The status messages that will contain any form errors.
  $form['status_messages'] = [
    '#type' => 'status_messages',
    '#weight' => -10,
  ];

  // Row classes textarea.
  $form[Constants::ENTITY_ID] = [
    '#type' => 'hidden',
    '#title' => $this
      ->t('Entity ID'),
    '#default_value' => $dynamic_layout_id,
    '#disabled' => TRUE,
  ];

  // Row classes textarea.
  $form[Constants::ROW_ID] = [
    '#type' => 'hidden',
    '#title' => $this
      ->t('Row id'),
    '#default_value' => $row_id,
  ];

  // Custom row classes textarea.
  $form['custom_row_classes'] = [
    '#type' => 'textarea',
    '#title' => $this
      ->t('Custom row classes'),
    '#description' => $this
      ->t('Fill in your row classes, separated by a comma. E.g: "class1, class2, class3"'),
    '#default_value' => $row_classes,
  ];
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['send'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
    '#attributes' => [
      'class' => [
        'use-ajax',
      ],
    ],
    '#ajax' => [
      'callback' => [
        $this,
        'submitModalFormAjax',
      ],
      'event' => 'click',
    ],
  ];
  $form['#attached']['library'][] = 'core/drupal.dialog.ajax';
  return $form;
}