From 226c686a9f2ca551ca05e70478ba9cd45f6dfb2d Mon Sep 17 00:00:00 2001 From: ebremner <ebremner@uwaterloo.ca> Date: Mon, 31 Aug 2020 09:14:39 -0400 Subject: [PATCH] ISTWCMS-4053: completing code review changes for custom layouts --- src/Plugin/Layout/Uw2ColumnLayout.php | 37 +++++++++ src/Plugin/Layout/Uw3ColumnLayout.php | 40 ++++++++++ src/Plugin/Layout/Uw4ColumnLayout.php | 40 ++++++++++ src/Plugin/Layout/Uw5ColumnLayout.php | 42 ++++++++++ src/Plugin/Layout/UwColumnLayoutBase.php | 40 ++++++++++ src/Plugin/Layout/UwFiveColumnLayout.php | 94 ----------------------- src/Plugin/Layout/UwFourColumnLayout.php | 90 ---------------------- src/Plugin/Layout/UwOneColumnLayout.php | 37 --------- src/Plugin/Layout/UwThreeColumnLayout.php | 87 --------------------- src/Plugin/Layout/UwTwoColumnLayout.php | 81 ------------------- uw_cfg_common.layouts.yml | 35 ++++----- 11 files changed, 216 insertions(+), 407 deletions(-) create mode 100644 src/Plugin/Layout/Uw2ColumnLayout.php create mode 100644 src/Plugin/Layout/Uw3ColumnLayout.php create mode 100644 src/Plugin/Layout/Uw4ColumnLayout.php create mode 100644 src/Plugin/Layout/Uw5ColumnLayout.php create mode 100644 src/Plugin/Layout/UwColumnLayoutBase.php delete mode 100644 src/Plugin/Layout/UwFiveColumnLayout.php delete mode 100644 src/Plugin/Layout/UwFourColumnLayout.php delete mode 100644 src/Plugin/Layout/UwOneColumnLayout.php delete mode 100644 src/Plugin/Layout/UwThreeColumnLayout.php delete mode 100644 src/Plugin/Layout/UwTwoColumnLayout.php diff --git a/src/Plugin/Layout/Uw2ColumnLayout.php b/src/Plugin/Layout/Uw2ColumnLayout.php new file mode 100644 index 00000000..e1516e8a --- /dev/null +++ b/src/Plugin/Layout/Uw2ColumnLayout.php @@ -0,0 +1,37 @@ +<?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; + } +} diff --git a/src/Plugin/Layout/Uw3ColumnLayout.php b/src/Plugin/Layout/Uw3ColumnLayout.php new file mode 100644 index 00000000..84171c80 --- /dev/null +++ b/src/Plugin/Layout/Uw3ColumnLayout.php @@ -0,0 +1,40 @@ +<?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; + } +} diff --git a/src/Plugin/Layout/Uw4ColumnLayout.php b/src/Plugin/Layout/Uw4ColumnLayout.php new file mode 100644 index 00000000..de8260e5 --- /dev/null +++ b/src/Plugin/Layout/Uw4ColumnLayout.php @@ -0,0 +1,40 @@ +<?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; + } +} diff --git a/src/Plugin/Layout/Uw5ColumnLayout.php b/src/Plugin/Layout/Uw5ColumnLayout.php new file mode 100644 index 00000000..9a64acc1 --- /dev/null +++ b/src/Plugin/Layout/Uw5ColumnLayout.php @@ -0,0 +1,42 @@ +<?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; + } + +} diff --git a/src/Plugin/Layout/UwColumnLayoutBase.php b/src/Plugin/Layout/UwColumnLayoutBase.php new file mode 100644 index 00000000..299833fe --- /dev/null +++ b/src/Plugin/Layout/UwColumnLayoutBase.php @@ -0,0 +1,40 @@ +<?php + +namespace Drupal\uw_cfg_common\Plugin\Layout; + +use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Layout\LayoutDefault; +use Drupal\Core\Plugin\PluginFormInterface; + +/** + * A column layout base. + */ +class UwColumnLayoutBase extends LayoutDefault implements PluginFormInterface { + + /** + * {@inheritdoc} + */ + public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { + + // Set the column class in the config. + $this->configuration['column_class'] = $form_state->getValue(['layout_settings', 'column_class'], NULL); + } + + /** + * {@inheritdoc} + */ + public function build(array $regions) { + + // Build the render array as usual. + $build = parent::build($regions); + + // Retrieve the config for the layout. + $configuration = $this->getConfiguration(); + + // Set the column class to be used in the layout template. + $build['#settings']['column_class'] = $configuration['column_class']; + + return $build; + } + +} diff --git a/src/Plugin/Layout/UwFiveColumnLayout.php b/src/Plugin/Layout/UwFiveColumnLayout.php deleted file mode 100644 index a0fbc7eb..00000000 --- a/src/Plugin/Layout/UwFiveColumnLayout.php +++ /dev/null @@ -1,94 +0,0 @@ -<?php - -namespace Drupal\uw_cfg_common\Plugin\Layout; - -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Layout\LayoutDefault; -use Drupal\Core\Plugin\PluginFormInterface; - -/** - * A UW four column layout. - * - * @Layout( - * id = "uw_five_column", - * label = @Translation("Five columns"), - * category = @Translation("UW layouts"), - * template = "templates/layout/layout--uwfivecol", - * regions = { - * "first" = { - * "label" = @Translation("Column 1"), - * }, - * "second" = { - * "label" = @Translation("Column 2"), - * }, - * "third" = { - * "label" = @Translation("Column 3"), - * }, - * "fourth" = { - * "label" = @Translation("Column 4"), - * }, - * "fifth" = { - * "label" = @Translation("Column 5"), - * }, - * } - * ) - */ -class UwFiveColumnLayout extends LayoutDefault implements PluginFormInterface { - - /** - * {@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; - } - - /** - * {@inheritdoc} - */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - - // Set the column class in the config. - $this->configuration['column_class'] = $form_state->getValue(['layout_settings', 'column_class'], NULL); - } - - /** - * {@inheritdoc} - */ - public function build(array $regions) { - - // Build the render array as usual. - $build = parent::build($regions); - - // Retrieve the config for the layout. - $configuration = $this->getConfiguration(); - - // Set the column class to be used in the layout template. - $build['#settings']['column_class'] = $configuration['column_class']; - - return $build; - } - -} diff --git a/src/Plugin/Layout/UwFourColumnLayout.php b/src/Plugin/Layout/UwFourColumnLayout.php deleted file mode 100644 index e3a5c00b..00000000 --- a/src/Plugin/Layout/UwFourColumnLayout.php +++ /dev/null @@ -1,90 +0,0 @@ -<?php - -namespace Drupal\uw_cfg_common\Plugin\Layout; - -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Layout\LayoutDefault; -use Drupal\Core\Plugin\PluginFormInterface; - -/** - * A UW four column layout. - * - * @Layout( - * id = "uw_four_column", - * label = @Translation("Four columns"), - * category = @Translation("UW layouts"), - * template = "templates/layout/layout--uwfourcol", - * regions = { - * "first" = { - * "label" = @Translation("Column 1"), - * }, - * "second" = { - * "label" = @Translation("Column 2"), - * }, - * "third" = { - * "label" = @Translation("Column 3"), - * }, - * "four" = { - * "label" = @Translation("Column 4"), - * }, - * } - * ) - */ -class UwFourColumnLayout extends LayoutDefault implements PluginFormInterface { - - /** - * {@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; - } - - /** - * {@inheritdoc} - */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - - // Set the column class in the config. - $this->configuration['column_class'] = $form_state->getValue(['layout_settings', 'column_class'], NULL); - } - - /** - * {@inheritdoc} - */ - public function build(array $regions) { - - // Build the render array as usual. - $build = parent::build($regions); - - // Retrieve the config for the layout. - $configuration = $this->getConfiguration(); - - // Set the column class to be used in the layout template. - $build['#settings']['column_class'] = $configuration['column_class']; - - return $build; - } - -} diff --git a/src/Plugin/Layout/UwOneColumnLayout.php b/src/Plugin/Layout/UwOneColumnLayout.php deleted file mode 100644 index a78b1f7c..00000000 --- a/src/Plugin/Layout/UwOneColumnLayout.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -namespace Drupal\uw_cfg_common\Plugin\Layout; - -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Layout\LayoutDefault; -use Drupal\Core\Plugin\PluginFormInterface; - -/** - * A UW one column layout. - * - * @Layout( - * id = "uw_one_column", - * label = @Translation("One column"), - * category = @Translation("UW layouts"), - * template = "templates/layout/layout--uwonecol", - * regions = { - * "first" = { - * "label" = @Translation("Column 1"), - * }, - * } - * ) - */ -class UwOneColumnLayout extends LayoutDefault implements PluginFormInterface { - - /** - * {@inheritdoc} - */ - public function build(array $regions) { - - // Build the render array as usual. - $build = parent::build($regions); - - return $build; - } - -} diff --git a/src/Plugin/Layout/UwThreeColumnLayout.php b/src/Plugin/Layout/UwThreeColumnLayout.php deleted file mode 100644 index 2590744a..00000000 --- a/src/Plugin/Layout/UwThreeColumnLayout.php +++ /dev/null @@ -1,87 +0,0 @@ -<?php - -namespace Drupal\uw_cfg_common\Plugin\Layout; - -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Layout\LayoutDefault; -use Drupal\Core\Plugin\PluginFormInterface; - -/** - * A UW three column layout. - * - * @Layout( - * id = "uw_three_column", - * label = @Translation("Three columns"), - * category = @Translation("UW layouts"), - * template = "templates/layout/layout--uwthreecol", - * regions = { - * "first" = { - * "label" = @Translation("Column 1"), - * }, - * "second" = { - * "label" = @Translation("Column 2"), - * }, - * "third" = { - * "label" = @Translation("Column 3"), - * }, - * } - * ) - */ -class UwThreeColumnLayout extends LayoutDefault implements PluginFormInterface { - - /** - * {@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; - } - - /** - * {@inheritdoc} - */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - - // Set the column class in the config. - $this->configuration['column_class'] = $form_state->getValue(['layout_settings', 'column_class'], NULL); - } - - /** - * {@inheritdoc} - */ - public function build(array $regions) { - - // Build the render array as usual. - $build = parent::build($regions); - - // Retrieve the config for the layout. - $configuration = $this->getConfiguration(); - - // Set the column class to be used in the layout template. - $build['#settings']['column_class'] = $configuration['column_class']; - - return $build; - } - -} diff --git a/src/Plugin/Layout/UwTwoColumnLayout.php b/src/Plugin/Layout/UwTwoColumnLayout.php deleted file mode 100644 index e5897bda..00000000 --- a/src/Plugin/Layout/UwTwoColumnLayout.php +++ /dev/null @@ -1,81 +0,0 @@ -<?php - -namespace Drupal\uw_cfg_common\Plugin\Layout; - -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Layout\LayoutDefault; -use Drupal\Core\Plugin\PluginFormInterface; - -/** - * A UW two column layout. - * - * @Layout( - * id = "uw_two_column", - * label = @Translation("Two columns"), - * category = @Translation("UW layouts"), - * template = "templates/layout/layout--uwtwocol", - * regions = { - * "first" = { - * "label" = @Translation("Column 1"), - * }, - * "second" = { - * "label" = @Translation("Column 2"), - * }, - * } - * ) - */ -class UwTwoColumnLayout extends LayoutDefault implements PluginFormInterface { - - /** - * {@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; - } - - /** - * {@inheritdoc} - */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - - // Set the column class in the config. - $this->configuration['column_class'] = $form_state->getValue(['layout_settings', 'column_class'], NULL); - } - - /** - * {@inheritdoc} - */ - public function build(array $regions) { - - // Build the render array as usual. - $build = parent::build($regions); - - // Retrieve the config for the layout. - $configuration = $this->getConfiguration(); - - // Set the column class to be used in the layout template. - $build['#settings']['column_class'] = $configuration['column_class']; - - return $build; - } - -} diff --git a/uw_cfg_common.layouts.yml b/uw_cfg_common.layouts.yml index 28ecb904..2b84869c 100644 --- a/uw_cfg_common.layouts.yml +++ b/uw_cfg_common.layouts.yml @@ -1,8 +1,7 @@ uw_one_column: label: 'One column' category: 'UW layouts' - class: '\Drupal\uw_cfg_common\Plugin\Layout\UwOneColumnLayout' - template: uw_fdsu_theme_resp/templates/layout/layout--uwonecol + template: uw_fdsu_theme_resp/templates/layout/layout--uw1col default_region: first regions: first: @@ -12,27 +11,27 @@ uw_one_column: uw_two_column: label: 'Two columns' category: 'UW layouts' - class: '\Drupal\uw_cfg_common\Plugin\Layout\UwTwoColumnLayout' - template: uw_fdsu_theme_resp/templates/layout/layout--uwtwocol + class: '\Drupal\uw_cfg_common\Plugin\Layout\Uw2ColumnLayout' + template: uw_fdsu_theme_resp/templates/layout/layout--uw2col default_region: first regions: first: - label: One + label: First second: - label: Two + label: Second icon_map: - [first, second] uw_three_column: label: 'Three columns' category: 'UW layouts' - class: '\Drupal\uw_cfg_common\Plugin\Layout\UwThreeColumnLayout' - template: uw_fdsu_theme_resp/templates/layout/layout--uwthreecol + class: '\Drupal\uw_cfg_common\Plugin\Layout\Uw3ColumnLayout' + template: uw_fdsu_theme_resp/templates/layout/layout--uw3col default_region: first regions: first: - label: One + label: First second: - label: Two + label: Second third: label: Third icon_map: @@ -40,14 +39,14 @@ uw_three_column: uw_four_column: label: 'Four columns' category: 'UW layouts' - class: '\Drupal\uw_cfg_common\Plugin\Layout\UwFourColumnLayout' - template: uw_fdsu_theme_resp/templates/layout/layout--uwfourcol + class: '\Drupal\uw_cfg_common\Plugin\Layout\Uw4ColumnLayout' + template: uw_fdsu_theme_resp/templates/layout/layout--uw4col default_region: first regions: first: - label: One + label: First second: - label: Two + label: Second third: label: Third fourth: @@ -57,14 +56,14 @@ uw_four_column: uw_five_column: label: 'Five columns' category: 'UW layouts' - class: '\Drupal\uw_cfg_common\Plugin\Layout\UwFiveColumnLayout' - template: uw_fdsu_theme_resp/templates/layout/layout--uwfivecol + class: '\Drupal\uw_cfg_common\Plugin\Layout\Uw5ColumnLayout' + template: uw_fdsu_theme_resp/templates/layout/layout--uw5col default_region: first regions: first: - label: One + label: First second: - label: Two + label: Second third: label: Third fourth: -- GitLab