From 833932387018c32b7a5d0c1a50de73f2a543da1a Mon Sep 17 00:00:00 2001 From: alekseybobkov Date: Fri, 10 Oct 2014 21:20:24 -0700 Subject: [PATCH] Fixes the bug where finding a component by class name is not possible if the component has an alias --- modules/cms/classes/CmsCompoundObject.php | 25 +++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/cms/classes/CmsCompoundObject.php b/modules/cms/classes/CmsCompoundObject.php index 634595ed3..e26ef3465 100644 --- a/modules/cms/classes/CmsCompoundObject.php +++ b/modules/cms/classes/CmsCompoundObject.php @@ -248,23 +248,36 @@ class CmsCompoundObject extends CmsObject */ public function getComponent($componentName) { - if (!$this->hasComponent($componentName)) + if (!($componentSection = $this->hasComponent($componentName))) return null; return ComponentManager::instance()->makeComponent( $componentName, null, - $this->settings['components'][$componentName]); + $this->settings['components'][$componentSection]); } /** * Checks if the object has a component with the specified name. * @param string $componentName Specifies the component name. - * @return boolean Returns true if the component exists. + * @return mixed Return false or the full component name used on the page (it could include the alias). */ public function hasComponent($componentName) { - return isset($this->settings['components'][$componentName]); + foreach ($this->settings['components'] as $sectionName=>$values) { + if ($sectionName == $componentName) + return $componentName; + + $parts = explode(' ', $sectionName); + + if (count($parts) < 2) + continue; + + if (trim($parts[0]) == $componentName) + return $sectionName; + } + + return false; } /** @@ -300,6 +313,10 @@ class CmsCompoundObject extends CmsObject $objectComponentMap[$objectCode] = []; else { foreach ($this->settings['components'] as $componentName=>$componentSettings) { + $nameParts = explode(' ', $componentName); + if (count($nameParts > 1)) + $componentName = trim($nameParts[0]); + $component = $this->getComponent($componentName); if (!$component) continue;