Feature No Code Attached Yet Maintainers Checked
avatar HLeithner
HLeithner
28 Nov 2023

Is your feature request related to a problem? Please describe.

In core we use the layout modal in the cancel task in the controller for modalselect closing.
This is implemented in several controllers. it would make sense to move this functionality to the FromController cancel method. This function already has similar functionality for redirection logic.
Additionally in the postSaveHook in the same Controller is used for save operation redirection and should be added to the core at the same time.

Describe the solution you'd like

Move selectmodal functionality to FromController

Additional context

Something like that but a bit simplified:

    /**
     * Method to cancel an edit.
     *
     * @param   string  $key  The name of the primary key of the URL variable.
     *
     * @return  boolean  True if access level checks pass, false otherwise.
     *
     * @since _0_VERSION_0_
     */
    public function cancel($key = null)
    {
        $result = parent::cancel($key);

        // When editing in modal then redirect to modalreturn layout
        if ($result && $this->input->get('layout') === 'modal') {
            $id     = $this->input->get('_0_MVC_TABLE_SCHEMA_ID_0_', '');
            $return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id, '_0_MVC_TABLE_SCHEMA_ID_0_')
                . '&layout=modalreturn&from-task=cancel';

            $this->setRedirect(Route::_($return, false));
        }

        return $result;
    }

    /**
     * Function that allows child controller access to model data
     * after the data has been saved.
     *
     * @param   BaseDatabaseModel  $model      The data model object.
     * @param   array              $validData  The validated data.
     *
     * @return  void
     *
     * @since _0_VERSION_0_
     */
    protected function postSaveHook(BaseDatabaseModel $model, $validData = [])
    {
        // When editing in modal then redirect to modalreturn layout
        if ($this->input->get('layout') === 'modal' && $this->task === 'save') {
            $id     = $model->getState('_0_MVC_EDIT_0_.id');
            $return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id, '_0_MVC_TABLE_SCHEMA_ID_0_')
                . '&layout=modalreturn&from-task=save';

            $this->setRedirect(Route::_($return, false));
        }
    }
avatar HLeithner HLeithner - open - 28 Nov 2023
avatar joomla-cms-bot joomla-cms-bot - change - 28 Nov 2023
Labels Added: No Code Attached Yet
avatar joomla-cms-bot joomla-cms-bot - labeled - 28 Nov 2023
avatar HLeithner
HLeithner - comment - 28 Nov 2023

Additonal the addModalToolbar() method in the HtmlView could be added to FormView as well.
Example code:

    /**
     * Add the page title and toolbar.
     *
     * @return  void
     */
    protected function addToolbar()
    {
        // We don't need toolbar in the modal window.
        if ($this->getLayout() === 'modal') {
            $this->addModalToolbar();
            return;
        }

        parent::addToolbar();

        ToolbarHelper::inlinehelp();
    }

    /**
     * Add the page title and toolbar.
     *
     * @return  void
     */
    protected function addModalToolbar()
    {
        $user       = $this->getCurrentUser();
        $isNew      = empty($this->item->{$this->keyName});
        $canDo      = $this->canDo;
        $toolbar    = $this->document->getToolbar();

        $canCreate = $isNew && (\count($user->getAuthorisedCategories($this->option, 'core.create')) > 0);
        $canEdit   = $canDo->get('core.edit');

        if ($canCreate || $canEdit) {
            $toolbar->apply('_0LC_MVC_EDIT_0_.apply');
            $toolbar->save('_0LC_MVC_EDIT_0_.save');
        }

        $toolbar->cancel('_0LC_MVC_EDIT_0_.cancel');
    }
avatar Fedik Fedik - change - 28 Nov 2023
Labels Added: Feature
avatar Fedik Fedik - labeled - 28 Nov 2023
avatar rdeutz
rdeutz - comment - 27 Apr 2024

Sounds like a good idea

avatar rdeutz rdeutz - change - 27 Apr 2024
Labels Added: Maintainers Checked
avatar rdeutz rdeutz - labeled - 27 Apr 2024

Add a Comment

Login with GitHub to post a comment