3 namespace Drupal\bootstrap\Plugin\Setting\Components\Region;
5 use Drupal\bootstrap\Plugin\Setting\SettingBase;
6 use Drupal\bootstrap\Utility\Element;
7 use Drupal\Core\Form\FormStateInterface;
10 * The "region_wells" theme setting.
12 * @ingroup plugins_setting
15 * id = "region_wells",
17 * description = @Translation("Enable the <code>.well</code>, <code>.well-sm</code> or <code>.well-lg</code> classes for specified regions."),
20 * "navigation_collapsible" = "",
25 * "sidebar_first" = "",
26 * "sidebar_second" = "well",
30 * "components" = @Translation("Components"),
31 * "region_wells" = @Translation("Region Wells"),
34 * "https://getbootstrap.com/docs/3.3/components/#wells" = @Translation("Bootstrap Wells"),
38 class RegionWells extends SettingBase {
43 public function alterFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
44 parent::alterFormElement($form, $form_state, $form_id);
46 $group = $this->getGroupElement($form, $form_state);
47 $setting = $this->getSettingElement($form, $form_state);
50 $group->setProperty('description', $setting->getProperty('description'));
52 // Retrieve the current default values.
53 $default_values = $setting->getProperty('default_value', $this->getDefaultValue());
57 'well' => t('.well (normal)'),
58 'well well-sm' => t('.well-sm (small)'),
59 'well well-lg' => t('.well-lg (large)'),
61 // Create dynamic well settings for each region.
62 $regions = system_region_list($this->theme->getName());
63 foreach ($regions as $name => $title) {
64 if (in_array($name, ['page_top', 'page_bottom'])) {
67 $setting->{'region_well-' . $name} = [
71 'class' => ['input-sm'],
74 '#default_value' => isset($default_values[$name]) ? $default_values[$name] : '',
82 public static function submitFormElement(Element $form, FormStateInterface $form_state, $form_id = NULL) {
83 $values = $form_state->getValues();
85 // Extract the regions from individual dynamic settings.
86 $regex = '/^region_well-/';
88 foreach ($values as $key => $value) {
89 if (!preg_match($regex, $key)) {
92 $region_wells[preg_replace($regex, '', $key)] = $value;
96 // Store the new values.
97 $values['region_wells'] = $region_wells;
98 $form_state->setValues($values);