Commit ab62793c authored by catch's avatar catch
Browse files

Issue #3101891 by tim.plunkett, zrpnr: Allow layout plugins to define default...

Issue #3101891 by tim.plunkett, zrpnr: Allow layout plugins to define default values for column widths

(cherry picked from commit 5777f8f5)
parent 1489271d
......@@ -19,9 +19,8 @@ abstract class MultiWidthLayoutBase extends LayoutDefault implements PluginFormI
*/
public function defaultConfiguration() {
$configuration = parent::defaultConfiguration();
$width_classes = array_keys($this->getWidthOptions());
return $configuration + [
'column_widths' => array_shift($width_classes),
'column_widths' => $this->getDefaultWidth(),
];
}
......@@ -72,4 +71,16 @@ public function build(array $regions) {
*/
abstract protected function getWidthOptions();
/**
* Provides a default value for the width options.
*
* @return string
* A key from the array returned by ::getWidthOptions().
*/
protected function getDefaultWidth() {
// Return the first available key from the list of options.
$width_classes = array_keys($this->getWidthOptions());
return array_shift($width_classes);
}
}
......@@ -22,4 +22,11 @@ protected function getWidthOptions() {
];
}
/**
* {@inheritdoc}
*/
protected function getDefaultWidth() {
return '33-34-33';
}
}
......@@ -23,4 +23,11 @@ protected function getWidthOptions() {
];
}
/**
* {@inheritdoc}
*/
protected function getDefaultWidth() {
return '50-50';
}
}
......@@ -64,8 +64,8 @@ public function testWidthChange() {
$width_options = [
[
'label' => 'Two column',
'widths' => [
'50-50',
'default_width' => '50-50',
'additional_widths' => [
'33-67',
'67-33',
'25-75',
......@@ -75,9 +75,9 @@ public function testWidthChange() {
],
[
'label' => 'Three column',
'widths' => [
'default_width' => '33-34-33',
'additional_widths' => [
'25-50-25',
'33-34-33',
'25-25-50',
'50-25-25',
],
......@@ -85,7 +85,7 @@ public function testWidthChange() {
],
];
foreach ($width_options as $width_option) {
$width = array_shift($width_option['widths']);
$width = $width_option['default_width'];
$assert_session->linkExists('Add section');
$page->clickLink('Add section');
$this->assertNotEmpty($assert_session->waitForElementVisible('css', "#drupal-off-canvas a:contains(\"{$width_option['label']}\")"));
......@@ -93,7 +93,7 @@ public function testWidthChange() {
$this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas input[type="submit"][value="Add section"]'));
$page->pressButton("Add section");
$this->assertWidthClassApplied($width_option['class'] . $width);
foreach ($width_option['widths'] as $width) {
foreach ($width_option['additional_widths'] as $width) {
$width_class = $width_option['class'] . $width;
$assert_session->linkExists('Configure Section 1');
$page->clickLink('Configure Section 1');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment