Added new method `addComponent()` to Cms Controller

This commit is contained in:
Sam Georges 2014-05-24 20:30:22 +10:00
parent 0697584108
commit a1d44408b8
2 changed files with 26 additions and 5 deletions

View File

@ -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.

View File

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