You are here

protected function DynamicLayoutForm::addSettingsFormFields in Dynamic Layouts 8

1 call to DynamicLayoutForm::addSettingsFormFields()
DynamicLayoutForm::form in src/Form/DynamicLayoutForm.php
Gets the actual form array to be built.

File

src/Form/DynamicLayoutForm.php, line 143

Class

DynamicLayoutForm
Form controller for the DynamicLayout entity edit forms.

Namespace

Drupal\dynamic_layouts\Form

Code

protected function addSettingsFormFields(array &$form, DynamicLayoutInterface $entity) {

  // Check if the entity is new, set some vars.
  $layout_tab_weight = 1;
  $entity_is_new = FALSE;
  if ($entity
    ->isNew()) {
    $entity_is_new = TRUE;
    $layout_tab_weight = 0;
  }
  $form[Constants::GENERAL_SETTING] = array(
    '#type' => 'details',
    '#title' => t('General settings'),
    '#group' => Constants::DYNAMIC_LAYOUT,
    '#weight' => $layout_tab_weight,
  );
  $form[Constants::GENERAL_SETTING]['label'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Layout name'),
    '#default_value' => $entity
      ->label(),
    '#size' => 30,
    '#required' => TRUE,
    '#maxlength' => 64,
    '#description' => $this
      ->t('The name for this layout.'),
  ];
  $form[Constants::GENERAL_SETTING]['id'] = [
    '#type' => 'machine_name',
    '#default_value' => $entity
      ->id(),
    '#required' => TRUE,
    '#disabled' => !$entity
      ->isNew(),
    '#size' => 30,
    '#maxlength' => 64,
    '#machine_name' => [
      'exists' => [
        '\\Drupal\\dynamic_layouts\\Entity\\DynamicLayout',
        'load',
      ],
      'source' => [
        Constants::GENERAL_SETTING,
        'label',
      ],
    ],
  ];
  $form[Constants::GENERAL_SETTING][Constants::CATEGORY] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Layout category'),
    '#default_value' => $entity
      ->getCategory(),
    '#size' => 30,
    '#required' => TRUE,
    '#maxlength' => 64,
    '#description' => $this
      ->t('The category of this layout.'),
  ];
  $form[Constants::GENERAL_SETTING][Constants::DEFAULT_ROW_CLASS] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Default row class'),
    '#default_value' => $entity
      ->getDefaultRowClass(),
    '#size' => 30,
    '#maxlength' => 64,
    '#required' => TRUE,
    '#description' => $this
      ->t('This class will be used on every row.'),
  ];
  $form[Constants::GENERAL_SETTING][Constants::DEFAULT_COLUMN_CLASS] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Default column class'),
    '#default_value' => $entity
      ->getDefaultColumnClass(),
    '#size' => 30,
    '#maxlength' => 64,
    '#description' => $this
      ->t('This class will be used on every column.'),
  ];
  if ($entity_is_new) {
    $form[Constants::GENERAL_SETTING][Constants::START_ROWS_COUNT] = [
      '#type' => 'number',
      '#title' => $this
        ->t('Layout rows'),
      '#description' => $this
        ->t('After saving you can add, remove configure the rows'),
      '#min' => 1,
      '#max' => 50,
      '#default_value' => 1,
      '#size' => 30,
      '#required' => TRUE,
      '#maxlength' => 64,
    ];
  }
}