/**
  * Guess the HREF for a button.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $entry = $builder->getFormEntry();
     // Nothing to do if empty.
     if (!($section = $this->sections->active())) {
         return;
     }
     foreach ($buttons as &$button) {
         if (isset($button['attributes']['href'])) {
             continue;
         }
         switch (array_get($button, 'button')) {
             case 'cancel':
                 $button['attributes']['href'] = $section->getHref();
                 break;
             case 'delete':
                 $button['attributes']['href'] = $section->getHref('delete/' . $entry->getId());
                 break;
             default:
                 // Determine the HREF based on the button type.
                 $type = array_get($button, 'button');
                 if ($type && !str_contains($type, '\\') && !class_exists($type)) {
                     $button['attributes']['href'] = $section->getHref($type . '/{entry.id}');
                 }
                 break;
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Normalize button input.
  *
  * @param FormBuilder $builder
  */
 public function normalize(FormBuilder $builder)
 {
     $buttons = $builder->getButtons();
     foreach ($buttons as $key => &$button) {
         $button = $this->process($key, $button);
     }
     $builder->setButtons($buttons);
 }
 /**
  * Merge in registered properties.
  *
  * @param FormBuilder $builder
  */
 public function merge(FormBuilder $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 FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $mode = $builder->getFormMode();
     foreach ($buttons as &$button) {
         if (!isset($button['enabled'])) {
             continue;
         }
         if (is_bool($button['enabled'])) {
             continue;
         }
         $button['enabled'] = $mode === $button['enabled'];
     }
     $builder->setButtons($buttons);
 }
 /**
  * Guess the HREF for a button.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $buttons = $builder->getButtons();
     $mode = $builder->getFormMode();
     foreach ($buttons as &$button) {
         if (isset($button['enabled']) && is_bool($button['enabled'])) {
             return;
         }
         switch (array_get($button, 'button')) {
             case 'delete':
                 $button['enabled'] = $mode === 'edit';
                 break;
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Build dropdown items.
  *
  * @param FormBuilder $builder
  */
 public function build(FormBuilder $builder)
 {
     $buttons = $builder->getButtons();
     foreach ($buttons as $key => &$button) {
         if ($dropdown = array_get($button, 'parent')) {
             foreach ($buttons as &$parent) {
                 if (array_get($parent, 'button') == $dropdown) {
                     if (!isset($parent['dropdown'])) {
                         $parent['dropdown'] = [];
                     }
                     $parent['dropdown'][] = $button;
                 }
             }
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Default the form buttons when none are defined.
  *
  * @param FormBuilder $builder
  */
 public function defaults(FormBuilder $builder)
 {
     if ($builder->getButtons() === []) {
         $builder->setButtons(['cancel']);
     }
 }
Esempio n. 8
0
 /**
  * Guess the button from the hint.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $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['text'])) {
             continue;
         }
         if (!isset($button['button'])) {
             continue;
         }
         $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'] = ucwords($this->string->humanize($button['button']));
         }
         if (!isset($button['text'])) {
             $button['text'] = $text;
         }
     }
     $builder->setButtons($buttons);
 }
 /**
  * Evaluate the form buttons.
  *
  * @param FormBuilder $builder
  */
 public function evaluate(FormBuilder $builder)
 {
     $entry = $builder->getFormEntry();
     $builder->setButtons($this->evaluator->evaluate($builder->getButtons(), compact('builder', 'entry')));
 }
Esempio n. 10
0
 /**
  * Parse the form buttons.
  *
  * @param FormBuilder $builder
  */
 public function parse(FormBuilder $builder)
 {
     $entry = $builder->getFormEntry();
     $builder->setButtons($this->parser->parse($builder->getButtons(), compact('entry')));
 }