bindEvent('model.beforeSave', function () { $this->content = $this->renderContent(); }); $this->bindEvent('model.afterFetch', function () { $this->attributes = array_merge($this->attributes, $this->parseContent()); }); } /** * 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(); } }