You are here

public function LayoutOptionForm::form in Bootstrap Layout Builder 1.x

Same name and namespace in other branches
  1. 2.x src/Form/LayoutOptionForm.php \Drupal\bootstrap_layout_builder\Form\LayoutOptionForm::form()

Gets the actual form array to be built.

Overrides EntityForm::form

See also

\Drupal\Core\Entity\EntityForm::processForm()

\Drupal\Core\Entity\EntityForm::afterBuild()

File

src/Form/LayoutOptionForm.php, line 78

Class

LayoutOptionForm
Form handler for the layout option entity forms.

Namespace

Drupal\bootstrap_layout_builder\Form

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);

  /** @var \Drupal\bootstrap_layout_builder\LayoutInterface $layout */
  $option = $this->entity;
  $form['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Label'),
    '#maxlength' => 255,
    '#default_value' => $option
      ->label(),
    '#required' => TRUE,
  ];
  $form['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $option
      ->id(),
    '#machine_name' => [
      'exists' => '\\Drupal\\bootstrap_layout_builder\\Entity\\LayoutOption::load',
    ],
    '#disabled' => !$option
      ->isNew(),
  ];
  $form['structure'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Structure'),
    '#maxlength' => 255,
    '#default_value' => $option
      ->getStructure() ?: '',
    '#description' => $this
      ->t('Add numbers seperated by space; if the number of columns at this layout is two and you are using bootstrap 12 Grid system<br/> this field must be two numbers at the sum of them sould equal 12. eg: <b>6 6</b> or <b>8 4</b> ...etc.'),
    '#required' => TRUE,
  ];
  $breakpoints = [];
  $blb_breakpoint = $this->entityTypeManager
    ->getStorage('blb_breakpoint')
    ->getQuery()
    ->sort('weight', 'ASC')
    ->execute();
  foreach ($blb_breakpoint as $breakpoint_id) {
    $breakpoint_entity = $this->entityTypeManager
      ->getStorage('blb_breakpoint')
      ->load($breakpoint_id);
    $breakpoints[$breakpoint_id] = $breakpoint_entity
      ->label();
  }
  $form['breakpoints'] = [
    '#title' => $this
      ->t('Breakpoints'),
    '#type' => 'checkboxes',
    '#description' => $this
      ->t('Select which breakpoints uses this layout option'),
    '#options' => $breakpoints,
    '#default_value' => $option
      ->getBreakpointsIds() ?: [],
  ];
  return $form;
}