diff --git a/modules/cms/classes/CmsObject.php b/modules/cms/classes/CmsObject.php index 138be4216..91b4d48d5 100644 --- a/modules/cms/classes/CmsObject.php +++ b/modules/cms/classes/CmsObject.php @@ -152,6 +152,9 @@ class CmsObject implements ArrayAccess if (!FileHelper::validatePath($fileName, static::getMaxAllowedPathNesting())) throw new SystemException(Lang::get('cms::lang.cms_object.invalid_file', ['name'=>$fileName])); + if (!strlen(File::extension($fileName))) + $fileName .= '.htm'; + $fullPath = static::getFilePath($theme, $fileName); if (!File::isFile($fullPath)) diff --git a/modules/cms/classes/ComponentBase.php b/modules/cms/classes/ComponentBase.php index e9c91a632..807b76cc3 100644 --- a/modules/cms/classes/ComponentBase.php +++ b/modules/cms/classes/ComponentBase.php @@ -54,6 +54,11 @@ abstract class ComponentBase extends Extendable */ protected $page; + /** + * @var array Cache of linked Component objects, used for page links. + */ + protected $pageLinkCache = []; + /** * Component constructor. Takes in the page or layout code section object * and properties set by the page or layout. @@ -146,4 +151,37 @@ abstract class ComponentBase extends Extendable return $value; } + + /** + * Creates a page link to another page. Allows mapping to the other page's + * component properties for the purpose of extracting URL routing parameters. + * @param string $page Page name or page file name + * @param string $class Component class name + * @param array $mappings ['componentProperty' => 'routed value'] + * @return string + */ + protected function makePageLink($page, $class, $mappings = []) + { + if (!isset($this->pageLinkCache[$page.$class])) { + $this->pageLinkCache[$page.$class] = $this->getOtherPageComponent($page, $class); + } + + if (!$component = $this->pageLinkCache[$page.$class]) + return null; + + $params = []; + foreach ($mappings as $property => $value) { + + if (!$param = $component->property($property)) + continue; + + if (substr($param, 0, 1) == ':') + $param = substr($param, 1); + + $params[$param] = $value; + } + + return $this->pageUrl($page, $params); + } + } \ No newline at end of file diff --git a/modules/cms/classes/ComponentManager.php b/modules/cms/classes/ComponentManager.php index 992140f23..76168cfd8 100644 --- a/modules/cms/classes/ComponentManager.php +++ b/modules/cms/classes/ComponentManager.php @@ -162,7 +162,7 @@ class ComponentManager public function hasComponent($name) { $className = $this->resolve($name); - if (!$className) + if (!$className) return false; return isset($this->classMap[$className]);