You are here

public function RegionWells::alterFormElement in Express 8

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

File

themes/contrib/bootstrap/src/Plugin/Setting/Components/Region/RegionWells.php, line 49
Contains \Drupal\bootstrap\Plugin\Setting\Components\Region\RegionWells.

Class

RegionWells
The "region_wells" theme setting.

Namespace

Drupal\bootstrap\Plugin\Setting\Components\Region

Code

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] : '',
    ];
  }
}