diff --git a/src/Plugin/Layout/UwFiveColumnLayout.php b/src/Plugin/Layout/UwFiveColumnLayout.php new file mode 100644 index 0000000000000000000000000000000000000000..a0fbc7eb70fd346c9b3d3719277a876698d53440 --- /dev/null +++ b/src/Plugin/Layout/UwFiveColumnLayout.php @@ -0,0 +1,94 @@ +<?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/uw_cfg_common.layouts.yml b/uw_cfg_common.layouts.yml index 6c12d9ff3d9e60b35efaf3b6cbb6aa948288cd22..28ecb9042c3ee67ac1c2bff496b22d0553f41557 100644 --- a/uw_cfg_common.layouts.yml +++ b/uw_cfg_common.layouts.yml @@ -1,5 +1,5 @@ uw_one_column: - label: '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 @@ -10,7 +10,7 @@ uw_one_column: icon_map: - [first] uw_two_column: - label: 'UW Two columns' + label: 'Two columns' category: 'UW layouts' class: '\Drupal\uw_cfg_common\Plugin\Layout\UwTwoColumnLayout' template: uw_fdsu_theme_resp/templates/layout/layout--uwtwocol @@ -23,7 +23,7 @@ uw_two_column: icon_map: - [first, second] uw_three_column: - label: 'UW Three columns' + label: 'Three columns' category: 'UW layouts' class: '\Drupal\uw_cfg_common\Plugin\Layout\UwThreeColumnLayout' template: uw_fdsu_theme_resp/templates/layout/layout--uwthreecol @@ -38,7 +38,7 @@ uw_three_column: icon_map: - [first, second, third] uw_four_column: - label: 'UW Four columns' + label: 'Four columns' category: 'UW layouts' class: '\Drupal\uw_cfg_common\Plugin\Layout\UwFourColumnLayout' template: uw_fdsu_theme_resp/templates/layout/layout--uwfourcol @@ -54,3 +54,22 @@ uw_four_column: label: Fourth icon_map: - [first, second, third, fourth] +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 + default_region: first + regions: + first: + label: One + second: + label: Two + third: + label: Third + fourth: + label: Fourth + fifth: + label: Fifth + icon_map: + - [first, second, third, fourth, fifth] \ No newline at end of file