/** * Create form for the given page. * * @param Page $page * @param null $name * @param null $form */ public function __construct(Page $page, $name = null, $form = null) { parent::__construct(); $this->page = $page->route(); $header = $page->header(); $this->rules = isset($header->rules) ? $header->rules : []; $this->header_data = isset($header->data) ? $header->data : []; if ($form) { $this->items = $form; } else { if (isset($header->form)) { $this->items = $header->form; // for backwards compatibility } } // Add form specific rules. if (!empty($this->items['rules']) && is_array($this->items['rules'])) { $this->rules += $this->items['rules']; } // Set form name if not set. if ($name && !is_int($name)) { $this->items['name'] = $name; } elseif (empty($this->items['name'])) { $this->items['name'] = $page->slug(); } // Set form id if not set. if (empty($this->items['id'])) { $inflector = new Inflector(); $this->items['id'] = $inflector->hyphenize($this->items['name']); } // Reset and initialize the form $this->reset(); }
/** * Themes constructor. * * @param Grav $grav */ public function __construct(Grav $grav) { parent::__construct(); $this->grav = $grav; $this->config = $grav['config']; // Register instance as autoloader for theme inheritance spl_autoload_register([$this, 'autoloadTheme']); }
public function __construct() { parent::__construct(); /** @var UniformResourceLocator $locator */ $locator = Grav::instance()['locator']; $iterator = $locator->getIterator('plugins://'); foreach ($iterator as $directory) { if (!$directory->isDir()) { continue; } $plugin = $directory->getBasename(); $this->add($this->loadPlugin($plugin)); } }
/** * Remove item from the list. * * @param Page|string|null $key * @throws \InvalidArgumentException */ public function remove($key = null) { if ($key instanceof Page) { $key = $key->path(); } elseif (is_null($key)) { $key = key($this->items); } if (!is_string($key)) { throw new \InvalidArgumentException('Invalid argument $key.'); } parent::remove($key); }