ADD B4 Actions: Save and View

This commit is contained in:
2023-10-07 23:33:29 +02:00
parent 9db4ad808b
commit 436734cd4c
7 changed files with 144 additions and 9 deletions

View File

@ -0,0 +1,19 @@
<?php
/**
* @package Depot.Administrator
* @subpackage com_depot
* @author Thomas Kuschel <thomas@kuschel.at>
* @copyright (C) 2023 KW4NZ, <https://www.kuschel.at>
* @license GNU General Public License version 2 or later; see LICENSE.md
* @since 0.0.4
*/
namespace KW4NZ\Component\Depot\Administrator\Controller;
use Joomla\CMS\MVC\Controller\FormController;
defined('_JEXEC') or die;
class PartController extends FormController
{
}

View File

@ -10,6 +10,7 @@
namespace KW4NZ\Component\Depot\Administrator\Model;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\AdminModel;
\defined('_JEXEC') or die;
@ -26,4 +27,16 @@ class PartModel extends AdminModel
return $form;
}
protected function loadFormData()
{
$app = Factory::getApplication();
$data = $app->getUserState('com_depot.edit.part.data', []);
if (empty($data)) {
$data = $this->getItem();
}
return $data;
}
}

View File

@ -10,10 +10,13 @@
namespace KW4NZ\Component\Depot\Administrator\View\Part;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
// use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
\defined('_JEXEC') or die;
/**
* View to edit an article.
@ -43,8 +46,8 @@ class HtmlView extends BaseHtmlView
*
* @return mixed A string if successful, otherwise an Error object.
*
* @throws \Exception
* @since 1.6
* @throws \Exception
* @since 1.6
*/
public function display($tpl = null)
{
@ -54,7 +57,19 @@ class HtmlView extends BaseHtmlView
// if (count($errors = $this->get('Errors'))) {
// throw new GenericDataException(implode("\n", $errors), 500);
// }
$this->addToolbar();
return parent::display($tpl);
}
protected function addToolbar()
{
Factory::getApplication()->getInput()->set('hidemainmenu', true);
ToolbarHelper::title('Part: Add');
ToolbarHelper::apply('part.apply');
ToolbarHelper::save('part.save');
ToolbarHelper::cancel('part.cancel', 'JTOOLBAR_CLOSE');
}
}

View File

@ -16,11 +16,12 @@ $wa->useScript('form.validate')
->useScript('keepalive');
?>
<form action="<?php echo Route::_('index.php?option=com_depot&view=part&layout=edit&id=' . (int) $this->item->id); ?>"
<form action="<?= Route::_('index.php?option=com_depot&view=part&layout=edit&id=' . (int) $this->item->id); ?>"
method="post" name="adminForm" id="item-form" class="form-validate">
<?php echo $this->form->renderField('component_name'); ?>
<?= $this->form->renderField('component_name'); ?>
<?= $this->form->renderField('id'); ?>
<input type="hidden" name="task" value="part.edit" />
<?php echo HTMLHelper::_('form.token'); ?>
<?= HTMLHelper::_('form.token'); ?>
</form>

View File

@ -10,4 +10,4 @@
?>
<h2>Welcome to my Depot Component!</h2>
<p>Link: <a href="index.php?option=com_depot&view=part&layout=edit">Part</a></p>
<p>Link: <a href="index.php?option=com_depot&view=part&layout=edit&id=1">Part</a></p>