/** * Saves the object to the disk. */ public function save() { if ($this->itemData !== false) { $this->items = MenuItem::initFromArray($this->itemData); } $contentData = ['name' => $this->name, 'items' => $this->itemData ? $this->itemData : []]; $dumper = new YamlDumper(); $this->content = $dumper->dump($contentData, 20, 0, false, true); return parent::save(); }
/** * Returns a default value for items attribute. * Items are objects of the \RainLab\Pages\Classes\MenuItem class. * @return array */ public function getItemsAttribute() { if (array_key_exists('items', $this->attributes)) { return $this->attributes['items']; } if ($items = array_get($this->parseContent(), 'items')) { $itemObjects = MenuItem::initFromArray($items); } else { $itemObjects = []; } return $this->attributes['items'] = $itemObjects; }