Skip to content
Snippets Groups Projects
Commit c578cd50 authored by Tyler Struyk's avatar Tyler Struyk Committed by Lily Yan
Browse files

Move column options to layout yaml instead of separate class

parent f658ab7e
No related branches found
No related tags found
1 merge request!60Feature/istwcms 4651 tstruyk admin label multi column
<?php
namespace Drupal\uw_cfg_common\Plugin\Layout;
use Drupal\Core\Form\FormStateInterface;
/**
* A UW two column layout.
*/
class Uw2ColumnLayout extends UwColumnLayoutBase {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Get Parents configuration form (which by default adds the Admin Label).
$form = parent::buildConfigurationForm($form, $form_state);
// Get the config for this layout.
$configuration = $this->getConfiguration();
// The options for the column widths.
$options = [
'even-split' => $this->t('Even split (50%, 50%)'),
'larger-left' => $this->t('Larger left (67%, 33%)'),
'larger-right' => $this->t('Larger right (33%, 67%)'),
];
// The form element for the column widths.
$form['column_class'] = [
'#type' => 'select',
'#title' => $this->t('Column widths'),
'#default_value' => !empty($configuration['column_class']) ? $configuration['column_class'] : 'even-split',
'#options' => $options,
];
return $form;
}
}
<?php
namespace Drupal\uw_cfg_common\Plugin\Layout;
use Drupal\Core\Form\FormStateInterface;
/**
* A UW three column layout.
*/
class Uw3ColumnLayout extends UwColumnLayoutBase {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Get Parents configuration form (which by default adds the Admin Label).
$form = parent::buildConfigurationForm($form, $form_state);
// Get the config for this layout.
$configuration = $this->getConfiguration();
// The options for the column widths.
$options = [
'even-split' => $this->t('Even split (33%, 34%, 33%)'),
'larger-left' => $this->t('Larger left (50%, 25%, 25%)'),
'larger-middle' => $this->t('Larger middle (25%, 50%, 25%)'),
'larger-right' => $this->t('Larger right (25%, 25%, 50%)'),
'legacy-38-38-24' => $this->t('Legacy (38%, 38%, 24%)'),
'legacy-24-38-38' => $this->t('Legacy (24%, 38%, 38%)'),
];
// The form element for the column widths.
$form['column_class'] = [
'#type' => 'select',
'#title' => $this->t('Column widths'),
'#default_value' => !empty($configuration['column_class']) ? $configuration['column_class'] : 'even-split',
'#options' => $options,
];
return $form;
}
}
<?php
namespace Drupal\uw_cfg_common\Plugin\Layout;
use Drupal\Core\Form\FormStateInterface;
/**
* A UW four column layout.
*/
class Uw4ColumnLayout extends UwColumnLayoutBase {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Get Parents configuration form (which by default adds the Admin Label).
$form = parent::buildConfigurationForm($form, $form_state);
// Get the config for this layout.
$configuration = $this->getConfiguration();
// The options for the column widths.
$options = [
'even-split' => $this->t('Even split (25%, 25%, 25%, 25%)'),
'larger-left' => $this->t('Larger left (50%, 16.67%, 16.67%, 16.67%)'),
'larger-second' => $this->t('Larger second (16.67%, 50%, 16.67%, 16.67%)'),
'larger-third' => $this->t('Larger third (16.67%, 16.67%, 50%, 16.67%)'),
'larger-right' => $this->t('Larger right (16.67%, 16.67%, 16.67%, 50%)'),
'legacy-23-27-27-23' => $this->t('Legacy (23%, 27%, 27%, 23%)'),
];
// The form element for the column widths.
$form['column_class'] = [
'#type' => 'select',
'#title' => $this->t('Column widths'),
'#default_value' => !empty($configuration['column_class']) ? $configuration['column_class'] : 'even-split',
'#options' => $options,
];
return $form;
}
}
<?php
namespace Drupal\uw_cfg_common\Plugin\Layout;
use Drupal\Core\Form\FormStateInterface;
/**
* A UW four column layout.
*/
class Uw5ColumnLayout extends UwColumnLayoutBase {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Get Parents configuration form (which by default adds the Admin Label).
$form = parent::buildConfigurationForm($form, $form_state);
// Get the config for this layout.
$configuration = $this->getConfiguration();
// The options for the column widths.
$options = [
'even-split' => $this->t('Even split (20%, 20%, 20%, 20%, 20%)'),
'larger-left' => $this->t('Larger left (40%, 15%, 15%, 15%, 15%)'),
'larger-second' => $this->t('Larger second (15%, 40%, 15%, 15%, 15%)'),
'larger-third' => $this->t('Larger third (15%, 15%, 40%, 15%, 15%)'),
'larger-fourth' => $this->t('Larger fourth (15%, 15%, 15%, 40%, 15%)'),
'larger-right' => $this->t('Larger right (15%, 15%, 15%, 15%, 40%)'),
'legacy-23-19-19-19-20' => $this->t('Legacy (23%, 19%, 19%, 19%, 20%)'),
];
// The form element for the column widths.
$form['column_class'] = [
'#type' => 'select',
'#title' => $this->t('Column widths'),
'#default_value' => !empty($configuration['column_class']) ? $configuration['column_class'] : 'even-split',
'#options' => $options,
];
return $form;
}
}
......@@ -11,6 +11,30 @@ use Drupal\Core\Plugin\PluginFormInterface;
*/
class UwColumnLayoutBase extends LayoutDefault implements PluginFormInterface {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Get Parents configuration form (which by default adds the Admin Label).
$form = parent::buildConfigurationForm($form, $form_state);
// Get the config for this layout.
$configuration = $this->getConfiguration();
// The options for the column widths.
$columnOptions = $this->getColumnOptions();
// The form element for the column widths.
$form['column_class'] = [
'#type' => 'select',
'#title' => $this->t('Column widths'),
'#default_value' => !empty($configuration['column_class']) ? $configuration['column_class'] : $columnOptions['default'],
'#options' => $columnOptions['columns'],
];
return $form;
}
/**
* {@inheritdoc}
*/
......@@ -42,4 +66,14 @@ class UwColumnLayoutBase extends LayoutDefault implements PluginFormInterface {
return $build;
}
/**
* Helper function to get column options defined in *.layout.yml file
*
* @return array[]
* an array containing string options and the default column.
*/
public function getColumnOptions() {
return $this->getPluginDefinition()->get('column_options');
}
}
<?php
namespace Drupal\uw_cfg_common\Plugin\Layout;
use Drupal\Core\Form\FormStateInterface;
/**
* A UW Inverted L Left layout.
*/
class UwInvertedLLeftLayout extends UwColumnLayoutBase {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Get Parents configuration form (which by default adds the Admin Label).
$form = parent::buildConfigurationForm($form, $form_state);
// Get the config for this layout.
$configuration = $this->getConfiguration();
// The options for the column widths.
$options = [
'even-split' => $this->t('Even split (50%, 50%)'),
'larger-left' => $this->t('Larger left (33%, 67%)'),
'larger-right' => $this->t('Larger right (67%, 33%)'),
];
// The form element for the column widths.
$form['column_class'] = [
'#type' => 'select',
'#title' => $this->t('Column widths for top row'),
'#default_value' => !empty($configuration['column_class']) ? $configuration['column_class'] : 'even-split',
'#options' => $options,
];
return $form;
}
}
<?php
namespace Drupal\uw_cfg_common\Plugin\Layout;
use Drupal\Core\Form\FormStateInterface;
/**
* A UW Inverted L Right layout.
*/
class UwInvertedLRightLayout extends UwColumnLayoutBase {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
// Get Parents configuration form (which by default adds the Admin Label).
$form = parent::buildConfigurationForm($form, $form_state);
// Get the config for this layout.
$configuration = $this->getConfiguration();
// The options for the column widths.
$options = [
'even-split' => $this->t('Even split (50%, 50%)'),
'larger-left' => $this->t('Larger left (33%, 67%)'),
'larger-right' => $this->t('Larger right (67%, 33%)'),
];
// The form element for the column widths.
$form['column_class'] = [
'#type' => 'select',
'#title' => $this->t('Column widths for top row'),
'#default_value' => !empty($configuration['column_class']) ? $configuration['column_class'] : 'even-split',
'#options' => $options,
];
return $form;
}
}
uw_1_column:
label: 'One column'
category: 'UW layouts'
library: uw_cfg_common/uw_layout_1_col
template: layouts/uw-1-col/layout--uw-1-col
default_region: first
regions:
first:
label: One
icon_map:
- [first]
uw_2_column:
label: 'Two columns'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\Uw2ColumnLayout'
library: uw_cfg_common/uw_layout_2_col
template: layouts/uw-2-col/layout--uw-2-col
default_region: first
regions:
first:
label: First
second:
label: Second
icon_map:
- [first, second]
uw_3_column:
label: 'Three columns'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\Uw3ColumnLayout'
library: uw_cfg_common/uw_layout_3_col
template: layouts/uw-3-col/layout--uw-3-col
default_region: first
regions:
first:
label: First
second:
label: Second
third:
label: Third
icon_map:
- [first, second, third]
uw_4_column:
label: 'Four columns'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\Uw4ColumnLayout'
library: uw_cfg_common/uw_layout_4_col
template: layouts/uw-4-col/layout--uw-4-col
default_region: first
regions:
first:
label: First
second:
label: Second
third:
label: Third
fourth:
label: Fourth
icon_map:
- [first, second, third, fourth]
uw_5_column:
label: 'Five columns'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\Uw5ColumnLayout'
library: uw_cfg_common/uw_layout_5_col
template: layouts/uw-5-col/layout--uw-5-col
default_region: first
regions:
first:
label: First
second:
label: Second
third:
label: Third
fourth:
label: Fourth
fifth:
label: Fifth
icon_map:
- [first, second, third, fourth, fifth]
uw_inverted_l_right:
label: 'Inverted "L" - right'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwInvertedLRightLayout'
library: uw_cfg_common/uw_layout_inverted_l_right
template: layouts/uw-inverted-l-right/layout--uw-inverted-l-right
default_region: first
regions:
first:
label: First
second:
label: Second
third:
label: Third
fourth:
label: Fourth
icon_map:
- [first, second, fourth]
- [third, third, fourth]
uw_inverted_l_left:
label: 'Inverted "L" - left'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwInvertedLLeftLayout'
library: uw_cfg_common/uw_layout_inverted_l_left
template: layouts/uw-inverted-l-left/layout--uw-inverted-l-left
default_region: first
regions:
first:
label: First
second:
label: Second
third:
label: Third
fourth:
label: Fourth
icon_map:
- [first, second, third]
- [first, fourth, fourth]
uw_1_column:
label: 'One column'
category: 'UW layouts'
library: uw_cfg_common/uw_layout_1_col
template: layouts/uw-1-col/layout--uw-1-col
default_region: first
regions:
first:
label: One
icon_map:
- [first]
uw_2_column:
label: 'Two columns'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwColumnLayoutBase'
library: uw_cfg_common/uw_layout_2_col
template: layouts/uw-2-col/layout--uw-2-col
default_region: first
regions:
first:
label: First
second:
label: Second
icon_map:
- [first, second]
column_options:
columns:
even-split: 'Even split (50%, 50%)'
larger-left: 'Larger left (67%, 33%)'
larger-right: 'Larger right (33%, 67%)'
default: 'even-split'
uw_3_column:
label: 'Three columns'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwColumnLayoutBase'
library: uw_cfg_common/uw_layout_3_col
template: layouts/uw-3-col/layout--uw-3-col
default_region: first
regions:
first:
label: First
second:
label: Second
third:
label: Third
icon_map:
- [first, second, third]
column_options:
columns:
even-split: 'Even split (33%, 34%, 33%)'
larger-left: 'Larger left (50%, 25%, 25%)'
larger-middle: 'Larger middle (25%, 50%, 25%)'
larger-right: 'Larger right (25%, 25%, 50%)'
legacy-38-38-24: 'Legacy (38%, 38%, 24%)'
legacy-24-38-38: 'Legacy (24%, 38%, 38%)'
default: 'even-split'
uw_4_column:
label: 'Four columns'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwColumnLayoutBase'
library: uw_cfg_common/uw_layout_4_col
template: layouts/uw-4-col/layout--uw-4-col
default_region: first
regions:
first:
label: First
second:
label: Second
third:
label: Third
fourth:
label: Fourth
icon_map:
- [first, second, third, fourth]
column_options:
columns:
even-split': 'Even split (25%, 25%, 25%, 25%)'
larger-left': 'Larger left (50%, 16.67%, 16.67%, 16.67%)'
larger-second': 'Larger second (16.67%, 50%, 16.67%, 16.67%)'
larger-third': 'Larger third (16.67%, 16.67%, 50%, 16.67%)'
larger-right': 'Larger right (16.67%, 16.67%, 16.67%, 50%)'
legacy-23-27-27-23': 'Legacy (23%, 27%, 27%, 23%)'
default: 'even-split'
uw_5_column:
label: 'Five columns'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwColumnLayoutBase'
library: uw_cfg_common/uw_layout_5_col
template: layouts/uw-5-col/layout--uw-5-col
default_region: first
regions:
first:
label: First
second:
label: Second
third:
label: Third
fourth:
label: Fourth
fifth:
label: Fifth
icon_map:
- [first, second, third, fourth, fifth]
column_options:
columns:
even-split': 'Even split (20%, 20%, 20%, 20%, 20%)'
larger-left': 'Larger left (40%, 15%, 15%, 15%, 15%)'
larger-second': 'Larger second (15%, 40%, 15%, 15%, 15%)'
larger-third': 'Larger third (15%, 15%, 40%, 15%, 15%)'
larger-fourth': 'Larger fourth (15%, 15%, 15%, 40%, 15%)'
larger-right': 'Larger right (15%, 15%, 15%, 15%, 40%)'
legacy-23-19-19-19-20': 'Legacy (23%, 19%, 19%, 19%, 20%)'
default: 'even-split'
uw_inverted_l_right:
label: 'Inverted "L" - right'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwColumnLayoutBase'
library: uw_cfg_common/uw_layout_inverted_l_right
template: layouts/uw-inverted-l-right/layout--uw-inverted-l-right
default_region: first
regions:
first:
label: First
second:
label: Second
third:
label: Third
fourth:
label: Fourth
icon_map:
- [first, second, fourth]
- [third, third, fourth]
column_options:
columns:
even-split: 'Even split (50%, 50%)'
larger-left: 'Larger left (67%, 33%)'
larger-right: 'Larger right (33%, 67%)'
default: 'even-split'
uw_inverted_l_left:
label: 'Inverted "L" - left'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwColumnLayoutBase'
library: uw_cfg_common/uw_layout_inverted_l_left
template: layouts/uw-inverted-l-left/layout--uw-inverted-l-left
default_region: first
regions:
first:
label: First
second:
label: Second
third:
label: Third
fourth:
label: Fourth
icon_map:
- [first, second, third]
- [first, fourth, fourth]
column_options:
columns:
even-split: 'Even split (50%, 50%)'
larger-left: 'Larger left (67%, 33%)'
larger-right: 'Larger right (33%, 67%)'
default: 'even-split'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment