/** * Guess the HREF for a button. * * @param TableBuilder $builder */ public function guess(TableBuilder $builder) { $buttons = $builder->getButtons(); if (!($section = $this->sections->active())) { return; } if (!($module = $this->modules->active())) { return; } $stream = $builder->getTableStream(); foreach ($buttons as &$button) { // If we already have an HREF then skip it. if (isset($button['attributes']['href'])) { continue; } switch (array_get($button, 'button')) { case 'restore': $button['attributes']['href'] = $this->url->to('entry/handle/restore/' . $module->getNamespace() . '/' . $stream->getNamespace() . '/' . $stream->getSlug() . '/{entry.id}'); break; default: // Determine the HREF based on the button type. $type = array_get($button, 'segment', array_get($button, 'button')); if ($type && !str_contains($type, '\\') && !class_exists($type)) { $button['attributes']['href'] = $section->getHref($type . '/{entry.id}'); } break; } } $builder->setButtons($buttons); }
/** * 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); }
/** * Save the order of the entries. * * @param SectionCollection $sections * @param TableBuilder $builder * @param array $selected */ public function handle(SectionCollection $sections, Redirector $redirector, TableBuilder $builder, array $selected) { $prefix = $builder->getTableOption('prefix'); $edit = array_shift($selected); $ids = implode(',', $selected); if ($section = $sections->active()) { $builder->setTableResponse($redirector->to($section->getHref('edit/' . $edit . '?' . $prefix . 'edit_next=' . $ids))); } }
/** * Guess some some form action parameters. * * @param FormBuilder $builder */ public function guess(FormBuilder $builder) { $actions = $builder->getActions(); $section = $this->sections->active(); reset($actions); $first = key($actions); foreach ($actions as $key => &$action) { // If we already have an HREF then skip it. if (isset($action['redirect'])) { continue; } if ($key == $first && ($redirect = $builder->getOption('redirect'))) { $action['redirect'] = $redirect; continue; } // Determine the HREF based on the action type. switch (array_get($action, 'action')) { case 'save': case 'submit': case 'save_exit': $action['redirect'] = $section ? $section->getHref() : $this->request->fullUrl(); break; case 'update': case 'save_edit': case 'save_continue': $action['redirect'] = function () use($section, $builder) { if ($section && $builder->getFormMode() == 'create') { return $section->getHref('edit/' . $builder->getContextualId()); } return $this->request->fullUrl(); }; break; case 'save_edit_next': $ids = array_filter(explode(',', $builder->getRequestValue('edit_next'))); if (!$ids) { $action['redirect'] = $section ? $section->getHref() : $this->request->fullUrl(); } elseif (count($ids) == 1) { $action['redirect'] = $section ? $section->getHref('edit/' . array_shift($ids)) : $this->request->fullUrl(); } else { $action['redirect'] = $section ? $section->getHref('edit/' . array_shift($ids) . '?' . $builder->getOption('prefix') . 'edit_next=' . implode(',', $ids)) : $this->request->fullUrl(); } break; } } $builder->setActions($actions); }
/** * 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); }
/** * Guess some some form action parameters. * * @param FormBuilder $builder */ public function guess(FormBuilder $builder) { $actions = $builder->getActions(); $section = $this->sections->active(); reset($actions); $first = key($actions); foreach ($actions as $key => &$action) { /* * If we already have an * HREF then skip it. */ if (isset($action['redirect'])) { continue; } /* * If this is the first action and the * form builder has a redirect option * then use it for the action redirect. */ if ($key == $first && ($redirect = $builder->getOption('redirect'))) { $action['redirect'] = $redirect; continue; } /* * If we're not in admin then just assume we * need to head back to the form. No redirect * will redirect back in this case. */ if ($this->request->segment(1) !== 'admin') { continue; } // Determine the HREF based on the action type. switch (array_get($action, 'action')) { case 'save': case 'submit': case 'save_exit': $action['redirect'] = $section ? $section->getHref() : $this->request->fullUrl(); break; case 'save_create': $action['redirect'] = $this->request->fullUrl(); break; case 'update': case 'save_edit': case 'save_continue': $action['redirect'] = function () use($section, $builder) { if ($section && $builder->getFormMode() == 'create') { return $section->getHref('edit/' . $builder->getContextualId()); } return $this->request->fullUrl(); }; break; case 'save_edit_next': $ids = array_filter(explode(',', $builder->getRequestValue('edit_next'))); if (!$ids) { $action['redirect'] = $section ? $section->getHref() : $this->request->fullUrl(); } elseif (count($ids) == 1) { $action['redirect'] = $section ? $section->getHref('edit/' . array_shift($ids)) : $this->request->fullUrl(); } else { $action['redirect'] = $section ? $section->getHref('edit/' . array_shift($ids) . '?' . $builder->getOption('prefix') . 'edit_next=' . implode(',', $ids)) : $this->request->fullUrl(); } break; } } $builder->setActions($actions); }
/** * Get the active section. * * @return SectionInterface|null */ public function getActiveSection() { return $this->sections->active(); }