/** * Handle the command. */ public function handle() { /* * Set the default buttons handler based * on the builder class. Defaulting to * no handler. */ if (!$this->builder->getButtons()) { $buttons = str_replace('GridBuilder', 'GridButtons', get_class($this->builder)); if (class_exists($buttons)) { $this->builder->setButtons($buttons . '@handle'); } } }
/** * Normalize button input. * * @param GridBuilder $builder */ public function normalize(GridBuilder $builder) { $buttons = $builder->getButtons(); foreach ($buttons as $key => &$button) { /** * If the button is a string then use * it as the button parameter. */ if (is_string($button)) { $button = ['button' => $button]; } /** * If the key is a string and the button * is an array without a button param then * move the key into the button as that param. */ if (!is_integer($key) && !isset($button['button'])) { $button['button'] = $key; } /** * Make sure some default parameters exist. */ $button['attributes'] = array_get($button, 'attributes', []); /** * Move the HREF if any to the attributes. */ if (isset($button['href'])) { array_set($button['attributes'], 'href', array_pull($button, 'href')); } /** * Move the target if any to the attributes. */ if (isset($button['target'])) { array_set($button['attributes'], 'target', array_pull($button, 'target')); } /** * Make sure the HREF is absolute. */ if (isset($button['attributes']['href']) && is_string($button['attributes']['href']) && !starts_with($button['attributes']['href'], 'http')) { $button['attributes']['href'] = url($button['attributes']['href']); } /** * Use small buttons for grids. */ $button['size'] = array_get($button, 'size', 'xs'); } $builder->setButtons($buttons); }
/** * Guess the HREF for a button. * * @param GridBuilder $builder */ public function guess(GridBuilder $builder) { $buttons = $builder->getButtons(); // Nothing to do if empty. if (!($section = $this->sections->active())) { return; } foreach ($buttons as &$button) { // If we already have an HREF then skip it. if (isset($button['attributes']['href'])) { continue; } // Determine the HREF based on the button type. if ($type = array_get($button, 'button')) { $button['attributes']['href'] = $section->getHref($type . '/{entry.id}'); } } $builder->setButtons($buttons); }
/** * Resolve grid views. * * @param GridBuilder $builder */ public function resolve(GridBuilder $builder) { $this->resolver->resolve($builder->getButtons(), compact('builder')); }