Skip to content

Commit

Permalink
Layouts: Add support for setting a default layout
Browse files Browse the repository at this point in the history
This is a better approach than setting a ThemeSetting Default, since Genesis then sets the UI to highlight the default layout correctly.
  • Loading branch information
GaryJones committed Aug 7, 2017
1 parent c5584ba commit d7e1a91
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Layouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* Layouts::SIDEBAR_CONTENT_SIDEBAR,
* Layouts::SIDEBAR_SIDEBAR_CONTENT,
* ],
* Layouts::DEFAULTLAYOUT => __genesis_return_full_width_content()
* ];
* ```
*
Expand All @@ -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';
Expand All @@ -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));
}
}

/**
Expand All @@ -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);
}
}

0 comments on commit d7e1a91

Please sign in to comment.