class RegionWells

The "region_wells" theme setting.

Plugin annotation

@BootstrapSetting(
  id = "region_wells",
  type = "container",
  description = @Translation("Enable the <code>.well</code>, <code>.well-sm</code> or <code>.well-lg</code> classes for specified regions."),
  defaultValue = {
    "navigation" = "",
    "navigation_collapsible" = "",
    "header" = "",
    "highlighted" = "",
    "help" = "",
    "content" = "",
    "sidebar_first" = "",
    "sidebar_second" = "well",
    "footer" = "",
  },
  groups = {
    "components" = @Translation("Components"),
    "region_wells" = @Translation("Region Wells"),
  },
  see = {
    "http://getbootstrap.com/components/#wells" = @Translation("Bootstrap Wells"),
  },
)

Hierarchy

Expanded class hierarchy of RegionWells

Related topics

Namespace

Drupal\bootstrap\Plugin\Setting\Components\Region
Source
class RegionWells extends SettingBase {

  /**
   * {@inheritdoc}
   */
  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] : '',
      ];
    }
  }

  /**
   * {@inheritdoc}
   */
  public static function submitFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
    $values = $form_state->getValues();

    // Extract the regions from individual dynamic settings.
    $regex = '/^region_well-/';
    $region_wells = [];
    foreach ($values as $key => $value) {
      if (!preg_match($regex, $key)) {
        continue;
      }
      $region_wells[preg_replace($regex, '', $key)] = $value;
      unset($values[$key]);
    }

    // Store the new values.
    $values['region_wells'] = $region_wells;
    $form_state->setValues($values);
  }

}

Members

Contains filters are case sensitive
Namesort descending Modifiers Type Description
PluginBase::$theme protected property The currently set theme object.
PluginBase::__construct public function
RegionWells::alterFormElement public function The alter method to store the code. Overrides SettingBase::alterFormElement
RegionWells::submitFormElement public static function Form submission handler. Overrides SettingBase::submitFormElement
SettingBase::alterForm public function The alter method to store the code. Overrides FormInterface::alterForm
SettingBase::drupalSettings public function Determines whether a theme setting should added to drupalSettings. Overrides SettingInterface::drupalSettings
SettingBase::getCacheTags public function The cache tags associated with this object. Overrides SettingInterface::getCacheTags
SettingBase::getDefaultValue public function Retrieves the setting's default value. Overrides SettingInterface::getDefaultValue
SettingBase::getElement Deprecated public function Overrides SettingInterface::getElement
SettingBase::getElementProperties public function Retrieves all the form properties from the setting definition.
SettingBase::getGroup Deprecated public function Overrides SettingInterface::getGroup
SettingBase::getGroupElement public function Retrieves the group form element the setting belongs to. Overrides SettingInterface::getGroupElement
SettingBase::getGroups public function Retrieves the setting's groups. Overrides SettingInterface::getGroups
SettingBase::getOptions public function Retrieves the settings options, if set. Overrides SettingInterface::getOptions
SettingBase::getSettingElement public function Retrieves the form element for the setting. Overrides SettingInterface::getSettingElement
SettingBase::getTitle public function Retrieves the setting's human-readable title. Overrides SettingInterface::getTitle
SettingBase::submitForm public static function Form submission handler. Overrides FormInterface::submitForm
SettingBase::validateForm public static function Form validation handler. Overrides FormInterface::validateForm
SettingBase::validateFormElement public static function Form validation handler. Overrides FormInterface::validateFormElement