diff --git a/modules/cms/classes/AutoDatasource.php b/modules/cms/classes/AutoDatasource.php index 1ebf8f8a9..b90a43836 100644 --- a/modules/cms/classes/AutoDatasource.php +++ b/modules/cms/classes/AutoDatasource.php @@ -265,7 +265,7 @@ class AutoDatasource extends Datasource implements DatasourceInterface public function update($dirName, $fileName, $extension, $content, $oldFileName = null, $oldExtension = null) { $searchFileName = $oldFileName ?: $fileName; - $searchExt = $oldExtension ?: $oldExtension; + $searchExt = $oldExtension ?: $extension; if (!empty($this->datasources[0]->selectOne($dirName, $searchFileName, $searchExt))) { $result = $this->datasources[0]->update($dirName, $fileName, $extension, $content, $oldFileName, $oldExtension); diff --git a/modules/cms/classes/Meta.php b/modules/cms/classes/Meta.php new file mode 100644 index 000000000..450d5b58f --- /dev/null +++ b/modules/cms/classes/Meta.php @@ -0,0 +1,85 @@ +bindEvent('model.beforeSave', function () { + $this->content = $this->renderContent(); + }); + $this->bindEvent('model.afterFetch', function () { + $this->attributes = array_merge($this->parseContent(), $this->attributes); + }); + } + + /** + * Processes the content attribute to an array of menu data. + * @return array|null + */ + protected function parseContent() + { + if ($this->contentDataCache !== null) { + return $this->contentDataCache; + } + + $parsedData = Yaml::parse($this->content); + + if (!is_array($parsedData)) { + return null; + } + + return $this->contentDataCache = $parsedData; + } + + /** + * Renders the meta data as a content string in YAML format. + * @return string + */ + protected function renderContent() + { + return Yaml::render($this->settings); + } + + /** + * Compile the content for this CMS object, used by the theme logger. + * @return string + */ + public function toCompiled() + { + return $this->renderContent(); + } +} \ No newline at end of file