/** * Save layout. * * @param bool $cascade * @return $this */ public function save($cascade = true) { if (!$this->name) { throw new \LogicException('Cannot save unnamed layout'); } $name = strtolower(preg_replace('|[^a-z\\d_-]|ui', '_', $this->name)); $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; // If there are atoms in the layout, copy them into outline configuration. $atoms = $this->atoms(); if (is_array($atoms)) { if ($cascade) { // Save layout into custom directory for the current theme. $filename = $locator->findResource("gantry-config://{$name}/page/head.yaml", true, true); $file = YamlFile::instance($filename); $config = new Config($file->content()); $file->save($config->set('atoms', json_decode(json_encode($atoms), true))->toArray()); $file->free(); } } // Remove atoms from the layout. foreach ($this->items as $key => $section) { if ($section->type === 'atoms') { unset($this->items[$key]); } } $filename = $locator->findResource("gantry-config://{$name}/layout.yaml", true, true); $file = CompiledYamlFile::instance($filename); $file->settings(['inline' => 20]); $file->save(LayoutReader::store($this->preset, $this->items)); $file->free(); $this->exists = true; return $this; }