Skip to content
Snippets Groups Projects
Commit a7b6c730 authored by Lily Yan's avatar Lily Yan
Browse files

Merge branch 'feature/ISTWCMS-4651-tstruyk-admin-label-multi-column' into '8.x-1.x'

Feature/istwcms 4651 tstruyk admin label multi column

See merge request !60
parents 71a0b85a 03656668
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 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['layout_settings']['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 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['layout_settings']['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 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['layout_settings']['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 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['layout_settings']['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,14 +11,42 @@ use Drupal\Core\Plugin\PluginFormInterface; ...@@ -11,14 +11,42 @@ use Drupal\Core\Plugin\PluginFormInterface;
*/ */
class UwColumnLayoutBase extends LayoutDefault implements 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} * {@inheritdoc}
*/ */
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
// Call parent and let it do its thing (like set the label).
parent::submitConfigurationForm($form, $form_state);
// Set the column class in the config. // Set the column class in the config.
$this->configuration['column_class'] = $form_state->getValue( $this->configuration['column_class'] = $form_state->getValue(
['layout_settings', 'column_class'], ['column_class'],
NULL NULL
); );
} }
...@@ -40,4 +68,14 @@ class UwColumnLayoutBase extends LayoutDefault implements PluginFormInterface { ...@@ -40,4 +68,14 @@ class UwColumnLayoutBase extends LayoutDefault implements PluginFormInterface {
return $build; 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 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['layout_settings']['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 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['layout_settings']['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: uw_1_column:
label: 'One column' label: 'One column'
category: 'UW layouts' category: 'UW layouts'
library: uw_cfg_common/uw_layout_1_col library: uw_cfg_common/uw_layout_1_col
template: layouts/uw-1-col/layout--uw-1-col template: layouts/uw-1-col/layout--uw-1-col
default_region: first default_region: first
regions: regions:
first: first:
label: One label: One
icon_map: icon_map:
- [first] - [first]
uw_2_column: uw_2_column:
label: 'Two columns' label: 'Two columns'
category: 'UW layouts' category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\Uw2ColumnLayout' class: '\Drupal\uw_cfg_common\Plugin\Layout\UwColumnLayoutBase'
library: uw_cfg_common/uw_layout_2_col library: uw_cfg_common/uw_layout_2_col
template: layouts/uw-2-col/layout--uw-2-col template: layouts/uw-2-col/layout--uw-2-col
default_region: first default_region: first
regions: regions:
first: first:
label: First label: First
second: second:
label: Second label: Second
icon_map: icon_map:
- [first, second] - [first, second]
uw_3_column: column_options:
label: 'Three columns' columns:
category: 'UW layouts' even-split: 'Even split (50%, 50%)'
class: '\Drupal\uw_cfg_common\Plugin\Layout\Uw3ColumnLayout' larger-left: 'Larger left (67%, 33%)'
library: uw_cfg_common/uw_layout_3_col larger-right: 'Larger right (33%, 67%)'
template: layouts/uw-3-col/layout--uw-3-col default: 'even-split'
default_region: first uw_3_column:
regions: label: 'Three columns'
first: category: 'UW layouts'
label: First class: '\Drupal\uw_cfg_common\Plugin\Layout\UwColumnLayoutBase'
second: library: uw_cfg_common/uw_layout_3_col
label: Second template: layouts/uw-3-col/layout--uw-3-col
third: default_region: first
label: Third regions:
icon_map: first:
- [first, second, third] label: First
uw_4_column: second:
label: 'Four columns' label: Second
category: 'UW layouts' third:
class: '\Drupal\uw_cfg_common\Plugin\Layout\Uw4ColumnLayout' label: Third
library: uw_cfg_common/uw_layout_4_col icon_map:
template: layouts/uw-4-col/layout--uw-4-col - [first, second, third]
default_region: first column_options:
regions: columns:
first: even-split: 'Even split (33%, 34%, 33%)'
label: First larger-left: 'Larger left (50%, 25%, 25%)'
second: larger-middle: 'Larger middle (25%, 50%, 25%)'
label: Second larger-right: 'Larger right (25%, 25%, 50%)'
third: legacy-38-38-24: 'Legacy (38%, 38%, 24%)'
label: Third legacy-24-38-38: 'Legacy (24%, 38%, 38%)'
fourth: default: 'even-split'
label: Fourth uw_4_column:
icon_map: label: 'Four columns'
- [first, second, third, fourth] category: 'UW layouts'
uw_5_column: class: '\Drupal\uw_cfg_common\Plugin\Layout\UwColumnLayoutBase'
label: 'Five columns' library: uw_cfg_common/uw_layout_4_col
category: 'UW layouts' template: layouts/uw-4-col/layout--uw-4-col
class: '\Drupal\uw_cfg_common\Plugin\Layout\Uw5ColumnLayout' default_region: first
library: uw_cfg_common/uw_layout_5_col regions:
template: layouts/uw-5-col/layout--uw-5-col first:
default_region: first label: First
regions: second:
first: label: Second
label: First third:
second: label: Third
label: Second fourth:
third: label: Fourth
label: Third icon_map:
fourth: - [first, second, third, fourth]
label: Fourth column_options:
fifth: columns:
label: Fifth even-split': 'Even split (25%, 25%, 25%, 25%)'
icon_map: larger-left': 'Larger left (50%, 16.67%, 16.67%, 16.67%)'
- [first, second, third, fourth, fifth] larger-second': 'Larger second (16.67%, 50%, 16.67%, 16.67%)'
uw_inverted_l_right: larger-third': 'Larger third (16.67%, 16.67%, 50%, 16.67%)'
label: 'Inverted "L" - right' larger-right': 'Larger right (16.67%, 16.67%, 16.67%, 50%)'
category: 'UW layouts' legacy-23-27-27-23': 'Legacy (23%, 27%, 27%, 23%)'
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwInvertedLRightLayout' default: 'even-split'
library: uw_cfg_common/uw_layout_inverted_l_right uw_5_column:
template: layouts/uw-inverted-l-right/layout--uw-inverted-l-right label: 'Five columns'
default_region: first category: 'UW layouts'
regions: class: '\Drupal\uw_cfg_common\Plugin\Layout\UwColumnLayoutBase'
first: library: uw_cfg_common/uw_layout_5_col
label: First template: layouts/uw-5-col/layout--uw-5-col
second: default_region: first
label: Second regions:
third: first:
label: Third label: First
fourth: second:
label: Fourth label: Second
icon_map: third:
- [first, second, fourth] label: Third
- [third, third, fourth] fourth:
uw_inverted_l_left: label: Fourth
label: 'Inverted "L" - left' fifth:
category: 'UW layouts' label: Fifth
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwInvertedLLeftLayout' icon_map:
library: uw_cfg_common/uw_layout_inverted_l_left - [first, second, third, fourth, fifth]
template: layouts/uw-inverted-l-left/layout--uw-inverted-l-left column_options:
default_region: first columns:
regions: even-split': 'Even split (20%, 20%, 20%, 20%, 20%)'
first: larger-left': 'Larger left (40%, 15%, 15%, 15%, 15%)'
label: First larger-second': 'Larger second (15%, 40%, 15%, 15%, 15%)'
second: larger-third': 'Larger third (15%, 15%, 40%, 15%, 15%)'
label: Second larger-fourth': 'Larger fourth (15%, 15%, 15%, 40%, 15%)'
third: larger-right': 'Larger right (15%, 15%, 15%, 15%, 40%)'
label: Third legacy-23-19-19-19-20': 'Legacy (23%, 19%, 19%, 19%, 20%)'
fourth: default: 'even-split'
label: Fourth uw_inverted_l_right:
icon_map: label: 'Inverted "L" - right'
- [first, second, third] category: 'UW layouts'
- [first, fourth, fourth] 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