/**
  * 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('TreeBuilder', 'TreeButtons', get_class($this->builder));
         if (class_exists($buttons)) {
             $this->builder->setButtons($buttons . '@handle');
         }
     }
     /*
      * Set the default segments handler based
      * on the builder class. Defaulting to
      * no handler.
      */
     if (!$this->builder->getSegments()) {
         $segments = str_replace('TreeBuilder', 'TreeSegments', get_class($this->builder));
         if (class_exists($segments)) {
             $this->builder->setSegments($segments . '@handle');
         }
     }
 }
 /**
  * Normalize button input.
  *
  * @param TreeBuilder $builder
  */
 public function normalize(TreeBuilder $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'));
         }
         /*
          * Move all data-* keys
          * to attributes.
          */
         foreach ($button as $attribute => $value) {
             if (str_is('data-*', $attribute)) {
                 array_set($button, 'attributes.' . $attribute, array_pull($button, $attribute));
             }
         }
         /*
          * 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 trees.
          */
         $button['size'] = array_get($button, 'size', 'xs');
     }
     $builder->setButtons($buttons);
 }
 /**
  * Merge in registered properties.
  *
  * @param TreeBuilder $builder
  */
 public function merge(TreeBuilder $builder)
 {
     $buttons = $builder->getButtons();
     foreach ($buttons as &$parameters) {
         if ($button = $this->buttons->get(array_get($parameters, 'button'))) {
             $parameters = array_replace_recursive($button, $parameters);
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Guess the HREF for a button.
  *
  * @param TreeBuilder $builder
  */
 public function guess(TreeBuilder $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);
 }