From d7e1a91c94f1ad8a711cd50af37b87c76817fe49 Mon Sep 17 00:00:00 2001 From: Gary Jones Date: Mon, 7 Aug 2017 15:33:30 +0100 Subject: [PATCH] Layouts: Add support for setting a default layout This is a better approach than setting a ThemeSetting Default, since Genesis then sets the UI to highlight the default layout correctly. --- src/Layouts.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Layouts.php b/src/Layouts.php index 4904293..e64e0b3 100644 --- a/src/Layouts.php +++ b/src/Layouts.php @@ -26,6 +26,7 @@ * Layouts::SIDEBAR_CONTENT_SIDEBAR, * Layouts::SIDEBAR_SIDEBAR_CONTENT, * ], + * Layouts::DEFAULTLAYOUT => __genesis_return_full_width_content() * ]; * ``` * @@ -47,6 +48,7 @@ class Layouts extends Brick { const REGISTER = 'register'; const UNREGISTER = 'unregister'; + const DEFAULTLAYOUT = 'default-layout'; const FULL_WIDTH_CONTENT = 'full-width-content'; const CONTENT_SIDEBAR = 'content-sidebar'; @@ -69,6 +71,10 @@ public function apply() $unregisterConfig = $this->config->getSubConfig(self::UNREGISTER); $this->unregister($unregisterConfig->getArrayCopy()); } + + if ($this->config->hasKey(self::DEFAULTLAYOUT)) { + $this->setDefault($this->config->getKey(self::DEFAULTLAYOUT)); + } } /** @@ -94,4 +100,16 @@ protected function unregister(array $args) \genesis_unregister_layout($value); }); } + + /** + * Set a default Genesis layout. + * + * Allow a user to identify a layout as being the default layout on a new install, as well as serve as the fallback layout. + * + * @param string $layout Layout handle. + */ + protected function setDefault(string $layout) + { + \genesis_set_default_layout($layout); + } }