Skip to content
Snippets Groups Projects
Commit f58a06b7 authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-4053: adding custom layouts

parent f47b2597
No related branches found
No related tags found
No related merge requests found
<?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;
}
}
<?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;
}
}
<?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;
}
}
uw_two_column:
label: 'UW Two columns'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwTwoColumnLayout'
template: uw_fdsu_theme_resp/templates/layout/layout--uwtwocol
default_region: first
regions:
first:
label: One
second:
label: Two
icon_map:
- [first, second]
uw_three_column:
label: 'UW Three columns'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwThreeColumnLayout'
template: uw_fdsu_theme_resp/templates/layout/layout--uwthreecol
default_region: first
regions:
first:
label: One
second:
label: Two
third:
label: Third
icon_map:
- [first, second, third]
uw_four_column:
label: 'UW Four columns'
category: 'UW layouts'
class: '\Drupal\uw_cfg_common\Plugin\Layout\UwFourColumnLayout'
template: uw_fdsu_theme_resp/templates/layout/layout--uwfourcol
default_region: first
regions:
first:
label: One
second:
label: Two
third:
label: Third
fourth:
label: Fourth
icon_map:
- [first, second, third, fourth]
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