/**
  * Guess the button from the hint.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $module = $this->modules->active();
     /**
      * This will break if we can't figure
      * out what the active module is.
      */
     if (!$module instanceof Module) {
         return;
     }
     foreach ($buttons as &$button) {
         if (!isset($button['button'])) {
             continue;
         }
         $text = $module->getNamespace('button.' . $button['button']);
         if (!isset($button['text']) && $this->translator->has($text)) {
             $button['text'] = $text;
         }
         $text = $module->getNamespace('button.' . $button['button']);
         if (!isset($button['text']) && $this->translator->has($text)) {
             $button['text'] = $text;
         }
         if ((!isset($button['text']) || !$this->translator->has($button['text'])) && $this->config->get('streams::system.lazy_translations')) {
             $button['text'] = $this->string->humanize(array_get($button, 'slug', $button['button']));
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Guess the HREF for a button.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $sections = $builder->getControlPanelSections();
     $active = $sections->active();
     $module = $this->modules->active();
     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.
         switch (array_get($button, 'button')) {
             case 'add':
             case 'new':
             case 'create':
                 $button['attributes']['href'] = $active->getHref('create');
                 break;
             case 'export':
                 if ($module) {
                     $button['attributes']['href'] = $this->url->to('entry/handle/export/' . $module->getNamespace() . '/' . array_get($button, 'namespace') . '/' . array_get($button, 'stream'));
                 }
                 break;
         }
         $type = array_get($button, 'segment', array_get($button, 'button'));
         if (!isset($button['attributes']['href']) && $type) {
             $button['attributes']['href'] = $active->getHref($type);
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Guess the enabled property.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     foreach ($buttons as &$button) {
         if (!isset($button['enabled']) || is_bool($button['enabled'])) {
             continue;
         }
         if (is_string($button['enabled'])) {
             $button['enabled'] = str_is($button['enabled'], $this->request->path());
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Merge in registered properties.
  *
  * @param ControlPanelBuilder $builder
  */
 public function merge(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     foreach ($buttons as &$parameters) {
         if (!($button = array_get($parameters, 'button'))) {
             continue;
         }
         if ($button && ($button = $this->buttons->get($button))) {
             $parameters = array_replace_recursive($button, $parameters);
         }
         $button = array_get($parameters, 'button', $button);
         if ($button && ($button = $this->buttons->get($button))) {
             $parameters = array_replace_recursive($button, $parameters);
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Guess the button from the hint.
  *
  * @param ControlPanelBuilder $builder
  */
 public function guess(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $module = $this->modules->active();
     /*
      * This will break if we can't figure
      * out what the active module is.
      */
     if (!$module instanceof Module) {
         return;
     }
     foreach ($buttons as &$button) {
         /*
          * If the button starts with "new_" just use
          * "new" and move the rest to the text.
          */
         if (isset($button['button']) && starts_with($button['button'], 'new_')) {
             if (!isset($button['text'])) {
                 $text = $module->getNamespace('button.' . $button['button']);
                 if ($this->translator->has($text)) {
                     $button['text'] = $text;
                 }
             }
             // Change this to slug for later.
             $button['slug'] = $button['button'];
             array_set($button, 'button', substr($button['button'], 0, 3));
         }
         /*
          * If the button starts with "add_" just use
          * "add" and move the rest to the text.
          */
         if (isset($button['button']) && starts_with($button['button'], 'add_')) {
             if (!isset($button['text'])) {
                 $button['text'] = $module->getNamespace('button.' . $button['button']);
             }
             // Change this to slug for later.
             $button['slug'] = $button['button'];
             array_set($button, 'button', substr($button['button'], 0, 3));
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Resolve table views.
  *
  * @param ControlPanelBuilder $builder
  */
 public function resolve(ControlPanelBuilder $builder)
 {
     $this->resolver->resolve($builder->getButtons(), compact('builder'));
 }
 /**
  * Normalize button input.
  *
  * @param ControlPanelBuilder $builder
  */
 public function normalize(ControlPanelBuilder $builder)
 {
     $buttons = $builder->getButtons();
     foreach ($buttons as $key => &$button) {
         /*
          * If the button is a string but the key
          * is numeric then use the button as the
          * button type.
          */
         if (is_numeric($key) && is_string($button)) {
             $button = ['button' => $button];
         }
         /*
          * If the button AND key are strings then
          * use the key as the button and the
          * button as the text parameters.
          */
         if (!is_numeric($key) && is_string($button)) {
             $button = ['text' => $button, 'button' => $key];
         }
         /*
          * If the key is not numeric and the button
          * is an array without the button key then
          * use the key as the button's type.
          */
         if (!is_numeric($key) && is_array($button) && !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']);
         }
         /*
          * If we have a dropdown then
          * process those real quick.
          */
         if (isset($button['dropdown'])) {
             foreach ($button['dropdown'] as $index => &$dropdown) {
                 if (is_string($dropdown)) {
                     $dropdown = ['text' => $index, 'href' => $dropdown];
                 }
                 // Make sure we have attributes.
                 $dropdown['attributes'] = array_get($dropdown, 'attributes', []);
                 // Move the HREF if any to the attributes.
                 if (isset($dropdown['href'])) {
                     array_set($dropdown['attributes'], 'href', array_pull($dropdown, 'href'));
                 }
                 // Make sure the HREF is absolute.
                 if (isset($dropdown['attributes']['href']) && is_string($dropdown['attributes']['href']) && !starts_with($dropdown['attributes']['href'], 'http')) {
                     $dropdown['attributes']['href'] = url($dropdown['attributes']['href']);
                 }
             }
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Parse the control panel buttons.
  *
  * @param ControlPanelBuilder $builder
  */
 public function parse(ControlPanelBuilder $builder)
 {
     $parameters = $this->request->route()->parameters();
     $builder->setButtons($this->parser->parse($builder->getButtons(), compact('parameters')));
 }