4 * Contains \Drupal\bootstrap\Plugin\Setting\Components\Region\RegionWells.
7 namespace Drupal\bootstrap\Plugin\Setting\Components\Region;
9 use Drupal\bootstrap\Annotation\BootstrapSetting;
10 use Drupal\bootstrap\Plugin\Setting\SettingBase;
11 use Drupal\bootstrap\Utility\Element;
12 use Drupal\Core\Annotation\Translation;
13 use Drupal\Core\Form\FormStateInterface;
16 * The "region_wells" theme setting.
18 * @ingroup plugins_setting
21 * id = "region_wells",
23 * description = @Translation("Enable the <code>.well</code>, <code>.well-sm</code> or <code>.well-lg</code> classes for specified regions."),
26 * "navigation_collapsible" = "",
31 * "sidebar_first" = "",
32 * "sidebar_second" = "well",
36 * "components" = @Translation("Components"),
37 * "region_wells" = @Translation("Region Wells"),
40 * "http://getbootstrap.com/components/#wells" = @Translation("Bootstrap Wells"),
44 class RegionWells extends SettingBase {
49 public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
50 parent::alterFormElement($form, $form_state, $form_id);
52 $group = $this->getGroupElement($form, $form_state);
53 $setting = $this->getSettingElement($form, $form_state);
56 $group->setProperty('description', $setting->getProperty('description'));
58 // Retrieve the current default values.
59 $default_values = $setting->getProperty('default_value', $this->getDefaultValue());
63 'well' => t('.well (normal)'),
64 'well well-sm' => t('.well-sm (small)'),
65 'well well-lg' => t('.well-lg (large)'),
67 // Create dynamic well settings for each region.
68 $regions = system_region_list($this->theme->getName());
69 foreach ($regions as $name => $title) {
70 if (in_array($name, ['page_top', 'page_bottom'])) {
73 $setting->{'region_well-' . $name} = [
77 'class' => ['input-sm'],
80 '#default_value' => isset($default_values[$name]) ? $default_values[$name] : '',
88 public static function submitFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
89 $values = $form_state->getValues();
91 // Extract the regions from individual dynamic settings.
92 $regex = '/^region_well-/';
94 foreach ($values as $key => $value) {
95 if (!preg_match($regex, $key)) {
98 $region_wells[preg_replace($regex, '', $key)] = $value;
102 // Store the new values.
103 $values['region_wells'] = $region_wells;
104 $form_state->setValues($values);