diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b8baa66b..12428ce09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ * **Build 92** (2014-05-24) - Components can now be dragged from the side navigation directly on to the page. - Asset maker methods (addJs, addCss, addRss) now use an optional build code, either *core* or a plugin code. This is converted to a version number to ensure updates are not affected by cached assets. + - Added new method `addComponent()` to Cms Controller. Components can now act as a proxy for other components. * **Build 90** (2014-05-23) - Class `CmsPropertyHelper` has been deprecated, will be removed year > 2014. diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index d732b73db..2435f8323 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -237,23 +237,43 @@ class Controller extends BaseController */ protected function initComponents() { - $manager = ComponentManager::instance(); - if (!$this->layout->isFallBack()) { foreach ($this->layout->settings['components'] as $component => $properties) { list($name, $alias) = strpos($component, ' ') ? explode(' ', $component) : array($component, $component); - $componentObj = $manager->makeComponent($name, $this->layoutObj, $properties); - $componentObj->alias = $alias; - $this->vars[$alias] = $this->layout->components[$alias] = $componentObj; + $this->addComponent($name, $alias, $properties, true); } } foreach ($this->page->settings['components'] as $component => $properties) { list($name, $alias) = strpos($component, ' ') ? explode(' ', $component) : array($component, $component); + $this->addComponent($name, $alias, $properties); + } + } + + /** + * Adds a component to the page object + * @param mixed $name Component class name or short name + * @param string $alias Alias to give the component + * @param array $properties Component properties + * @param bool $addToLayout Add to layout, instead of page + * @return ComponentBase Component object + */ + public function addComponent($name, $alias, $properties, $addToLayout = false) + { + $manager = ComponentManager::instance(); + + if ($addToLayout) { + $componentObj = $manager->makeComponent($name, $this->layoutObj, $properties); + $componentObj->alias = $alias; + $this->vars[$alias] = $this->layout->components[$alias] = $componentObj; + } + else { $componentObj = $manager->makeComponent($name, $this->pageObj, $properties); $componentObj->alias = $alias; $this->vars[$alias] = $this->page->components[$alias] = $componentObj; } + + return $componentObj; } /**