function public function RegionWells::alterFormElement

8.x-3.x RegionWells.php public RegionWells::alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL)

The alter method to store the code.

Parameters

\Drupal\bootstrap\Utility\Element $form: The Element object that comprises the form.

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

string $form_id: String representing the name of the form itself. Typically this is the name of the function that generated the form.

Overrides SettingBase::alterFormElement

Class

RegionWells
The "region_wells" theme setting.

Namespace

Drupal\bootstrap\Plugin\Setting\Components\Region

Source src/Plugin/Setting/Components/Region/RegionWells.php (line 43)

public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
  parent::alterFormElement($form, $form_state, $form_id);

  $group = $this->getGroupElement($form, $form_state);
  $setting = $this->getSettingElement($form, $form_state);

  // Move description.
  $group->setProperty('description', $setting->getProperty('description'));

  // Retrieve the current default values.
  $default_values = $setting->getProperty('default_value', $this->getDefaultValue());

  $wells = [
    '' => t('None'),
    'well' => t('.well (normal)'),
    'well well-sm' => t('.well-sm (small)'),
    'well well-lg' => t('.well-lg (large)'),
  ];
  // Create dynamic well settings for each region.
  $regions = system_region_list($this->theme->getName());
  foreach ($regions as $name => $title) {
    if (in_array($name, ['page_top', 'page_bottom'])) {
      continue;
    }
    $setting->{'region_well-' . $name} = [
      '#title' => $title,
      '#type' => 'select',
      '#attributes' => [
        'class' => ['input-sm'],
      ],
      '#options' => $wells,
      '#default_value' => isset($default_values[$name]) ? $default_values[$name] : '',
    ];
  }
}