Skip to content

Commit

Permalink
Plugin dialog edit: layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Fedik committed Dec 2, 2023
1 parent 7c85099 commit c6b3a64
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace Joomla\Component\Plugins\Administrator\Controller;

use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Router\Route;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand All @@ -23,4 +25,53 @@
*/
class PluginController extends FormController
{
/**
* 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 __DEPLOY_VERSION__
*/
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('extension_id');
$return = 'index.php?option=' . $this->option . '&view=' . $this->view_item . $this->getRedirectToItemAppend($id, 'extension_id')
. '&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 __DEPLOY_VERSION__
*/
protected function postSaveHook(BaseDatabaseModel $model, $validData = [])
{
parent::postSaveHook($model, $validData);

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

$this->setRedirect(Route::_($return, false));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,23 @@ public function display($tpl = null)
$this->item = $this->get('Item');
$this->form = $this->get('Form');

if ($this->getLayout() === 'modalreturn') {
parent::display($tpl);

return;
}

// Check for errors.
if (\count($errors = $this->get('Errors'))) {
throw new GenericDataException(implode("\n", $errors), 500);
}

$this->addToolbar();
if ($this->getLayout() !== 'modal') {
$this->addToolbar();
} else {
$this->addModalToolbar();
}

parent::display($tpl);
}

Expand Down Expand Up @@ -115,4 +126,30 @@ protected function addToolbar()
$toolbar->inlinehelp();
$toolbar->help($help->key, false, $url);
}

/**
* Add the modal toolbar.
*
* @return void
*
* @since __DEPLOY_VERSION__
*
* @throws \Exception
*/
protected function addModalToolbar()
{
$canDo = ContentHelper::getActions('com_plugins');
$toolbar = Toolbar::getInstance();

ToolbarHelper::title(Text::sprintf('COM_PLUGINS_MANAGER_PLUGIN', Text::_($this->item->name)), 'plug plugin');

// If not checked out, can save the item.
if ($canDo->get('core.edit')) {
$toolbar->apply('plugin.apply');

$toolbar->save('plugin.save');
}

$toolbar->cancel('plugin.cancel');
}
}
7 changes: 3 additions & 4 deletions administrator/components/com_plugins/tmpl/plugin/modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
defined('_JEXEC') or die;

?>
<button id="applyBtn" type="button" class="hidden" onclick="Joomla.submitbutton('plugin.apply');"></button>
<button id="saveBtn" type="button" class="hidden" onclick="Joomla.submitbutton('plugin.save');"></button>
<button id="closeBtn" type="button" class="hidden" onclick="Joomla.submitbutton('plugin.cancel');"></button>

<div class="subhead noshadow mb-3">
<?php echo $this->document->getToolbar('toolbar')->render(); ?>
</div>
<div class="container-popup">
<?php $this->setLayout('edit'); ?>
<?php echo $this->loadTemplate(); ?>
Expand Down
45 changes: 45 additions & 0 deletions administrator/components/com_plugins/tmpl/plugin/modalreturn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_content
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Language\Text;

$icon = 'icon-check';
$title = $this->item ? Text::_($this->item->name) : '';
$content = $this->item ? $this->item->folder . '/' . $this->item->element : '';
$data = ['contentType' => 'com_plugins.plugin'];

if ($this->item && $this->item->extension_id) {
$data['id'] = $this->item->extension_id;
$data['title'] = $title;
$data['type'] = $this->item->folder;
$data['name'] = $this->item->element;
}

// Add Content select script
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa->useScript('modal-content-select');

// The data for Content select script
$this->document->addScriptOptions('content-select-on-load', $data, false);

?>

<div class="px-4 py-5 my-5 text-center">
<span class="fa-8x mb-4 <?php echo $icon; ?>" aria-hidden="true"></span>
<h1 class="display-5 fw-bold"><?php echo $title; ?></h1>
<div class="col-lg-6 mx-auto">
<p class="lead mb-4">
<?php echo $content; ?>
</p>
</div>
</div>

0 comments on commit c6b3a64

Please sign in to comment.