Release of v3.2.3-alpha1

Fix site view form missing classes in J4+. Fix permissions tab in items in J4+. Fix site display controller checkEditId function in J4+. Add class methods to the HtmlView classes in J4+. Fix broken toolbar call in HtmlView in J4+.
This commit is contained in:
2024-07-26 15:33:16 +02:00
parent 36d0eb98ee
commit fd08d48baf
31 changed files with 1445 additions and 68 deletions

View File

@ -27,6 +27,62 @@ namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Administrator
*/
class HtmlView extends BaseHtmlView
{
/**
* The items from the model
*
* @var mixed
* @since 3.10.11
*/
public mixed $items;
/**
* The state object
*
* @var mixed
* @since 3.10.11
*/
public mixed $state;
/**
* The styles url array
*
* @var array
* @since 5.0.0
*/
protected array $styles;
/**
* The scripts url array
*
* @var array
* @since 5.0.0
*/
protected array $scripts;
/**
* The actions object
*
* @var object
* @since 3.10.11
*/
public object $canDo;
/**
* The return here base64 url
*
* @var string
* @since 3.10.11
*/
public string $return_here;
/**
* The user object.
*
* @var Joomla___effdaf6d_2275_425d_9f52_d4952e564d34___Power
* @since 3.10.11
*/
public Joomla___effdaf6d_2275_425d_9f52_d4952e564d34___Power $user;
/**
* ###Views### view display method
*
@ -43,7 +99,7 @@ class HtmlView extends BaseHtmlView
$this->state = $this->get('State');
$this->styles = $this->get('Styles');
$this->scripts = $this->get('Scripts');
$this->user ??= Factory::getApplication()->getIdentity();###ADMIN_DIPLAY_METHOD###
$this->user ??= $this->getCurrentUser();###ADMIN_DIPLAY_METHOD###
$this->saveOrder = $this->listOrder == 'a.ordering';
// set the return here value
$this->return_here = urlencode(base64_encode((string) Uri::getInstance()));

View File

@ -27,6 +27,86 @@ namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Administrator
*/
class HtmlView extends BaseHtmlView
{
/**
* The item from the model
*
* @var mixed
* @since 3.10.11
*/
public mixed $item;
/**
* The state object
*
* @var mixed
* @since 3.10.11
*/
public mixed $state;
/**
* The form from the model
*
* @var mixed
* @since 3.10.11
*/
public mixed $form;
/**
* The toolbar object
*
* @var Toolbar
* @since 3.10.11
*/
public Toolbar $toolbar;
/**
* The styles url array
*
* @var array
* @since 5.0.0
*/
protected array $styles;
/**
* The scripts url array
*
* @var array
* @since 5.0.0
*/
protected array $scripts;
/**
* The actions object
*
* @var object
* @since 3.10.11
*/
public object $canDo;
/**
* The origin referral view name
*
* @var string
* @since 3.10.11
*/
public string $ref;
/**
* The origin referral item id
*
* @var int
* @since 3.10.11
*/
public int $refid;
/**
* The referral url suffix values
*
* @var string
* @since 3.10.11
*/
public string $referral;
/**
* ###View### view display method
*
@ -41,7 +121,7 @@ class HtmlView extends BaseHtmlView
$this->params = ComponentHelper::getParams('com_###component###');
$this->useCoreUI = true;
// Assign the variables
$this->form = $this->get('Form');
$this->form ??= $this->get('Form');
$this->item = $this->get('Item');
$this->styles = $this->get('Styles');
$this->scripts = $this->get('Scripts');

View File

@ -27,6 +27,38 @@ namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Administrator
*/
class HtmlView extends BaseHtmlView
{
/**
* The styles url array
*
* @var array
* @since 5.0.0
*/
protected array $styles;
/**
* The scripts url array
*
* @var array
* @since 5.0.0
*/
protected array $scripts;
/**
* The actions object
*
* @var object
* @since 3.10.11
*/
public object $canDo;
/**
* The user object.
*
* @var Joomla___effdaf6d_2275_425d_9f52_d4952e564d34___Power
* @since 3.10.11
*/
public Joomla___effdaf6d_2275_425d_9f52_d4952e564d34___Power $user;
/**
* Display the view
*
@ -42,11 +74,11 @@ class HtmlView extends BaseHtmlView
// get the application
$this->app ??= Factory::getApplication();
// get the user object
$this->user ??= $this->app->getIdentity();
$this->user ??= $this->getCurrentUser();
// get global action permissions
$this->canDo = ###Component###Helper::getActions('###sview###');
$this->styles = $this->get('Styles');
$this->scripts = $this->get('Scripts');###CUSTOM_ADMIN_DIPLAY_METHOD###
$this->styles = $this->get('Styles') ?? [];
$this->scripts = $this->get('Scripts') ?? [];###CUSTOM_ADMIN_DIPLAY_METHOD###
// Set the html view document stuff
$this->_prepareDocument();

View File

@ -27,6 +27,86 @@ namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Site\View\###
*/
class HtmlView extends BaseHtmlView
{
/**
* The item from the model
*
* @var mixed
* @since 3.10.11
*/
public mixed $item;
/**
* The state object
*
* @var mixed
* @since 3.10.11
*/
public mixed $state;
/**
* The form from the model
*
* @var mixed
* @since 3.10.11
*/
public mixed $form;
/**
* The toolbar object
*
* @var Toolbar
* @since 3.10.11
*/
public Toolbar $toolbar;
/**
* The styles url array
*
* @var array
* @since 5.0.0
*/
protected array $styles;
/**
* The scripts url array
*
* @var array
* @since 5.0.0
*/
protected array $scripts;
/**
* The actions object
*
* @var object
* @since 3.10.11
*/
public object $canDo;
/**
* The origin referral view name
*
* @var string
* @since 3.10.11
*/
public string $ref;
/**
* The origin referral view item id
*
* @var int
* @since 3.10.11
*/
public int $refid;
/**
* The referral url suffix values
*
* @var string
* @since 3.10.11
*/
public string $referral;
/**
* ###View### view display method
*
@ -41,11 +121,11 @@ class HtmlView extends BaseHtmlView
$this->params = ComponentHelper::getParams('com_###component###');
$this->useCoreUI = true;
// Assign the variables
$this->form = $this->get('Form');
$this->form ??= $this->get('Form');
$this->item = $this->get('Item');
$this->state = $this->get('State');
$this->styles = $this->get('Styles');
$this->scripts = $this->get('Scripts');
$this->styles = $this->get('Styles') ?? [];
$this->scripts = $this->get('Scripts') ?? [];
// get action permissions
$this->canDo = ###Component###Helper::getActions('###view###', $this->item);
// get input
@ -97,6 +177,9 @@ class HtmlView extends BaseHtmlView
protected function addToolbar(): void
{
###ADDTOOLBAR###
// now initiate the toolbar
$this->toolbar ??= Toolbar::getInstance();
}
/**

View File

@ -15,9 +15,13 @@ defined('_JCB_TEMPLATE') or die;
###BOM###
namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Site\Controller;
use Joomla\Input\Input;
use Joomla\CMS\Factory;
use Joomla\CMS\Application\CMSApplication;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\Router\Route;
use Joomla\CMS\User\User;
use Joomla\Utilities\ArrayHelper;
use Joomla\CMS\Language\Text;
@ -31,13 +35,50 @@ use Joomla\CMS\Language\Text;
*/
class DisplayController extends BaseController
{
/**
* The allowed edit views.
*
* @var array
* @since 4.0.0
*/
protected array $allowed_edit_views = [###SITE_ALLOW_EDIT_VIEWS_ARRAY###
];
/**
* The application identity object.
*
* @var User
* @since 4.0.0
*/
protected $identity;
/**
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'default_task', 'model_path', and
* 'view_path' (this list is not meant to be comprehensive).
* @param MVCFactoryInterface|null $factory The factory.
* @param CMSApplication|null $app The Application for the dispatcher
* @param Input|null $input The Input object for the request
*
* @throws \Exception
* @since 3.0.1
*/
public function __construct($config = [], MVCFactoryInterface $factory = null, $app = null, $input = null)
{
$app ??= Factory::getApplication();
$this->identity ??= $app->getIdentity();
parent::__construct($config, $factory, $app, $input);
}
/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached.
* @param boolean $urlparams An array of safe URL parameters and their variable types, for valid values see {@link InputFilter::clean()}.
* @param boolean $cachable If true, the view output will be cached.
* @param boolean|array $urlparams An array of safe URL parameters and their variable types, for valid values see {@link InputFilter::clean()}.
*
* @return DisplayController This object to support chaining.
* @throws \Exception
* @since 1.5
*/
function display($cachable = false, $urlparams = false)
@ -51,14 +92,13 @@ class DisplayController extends BaseController
$cachable = true;
// ensure that the view is not cashable if edit view or if user is logged in
$user = $this->app->getIdentity();
if ($user->get('id') || $this->input->getMethod() === 'POST' || $isEdit)
if ($this->identity->get('id') || $this->input->getMethod() === 'POST' || $isEdit)
{
$cachable = false;
}
// Check for edit form.
if ($isEdit && !$this->checkEditId('com_###component###.edit.'.$view, $id))
if ($isEdit && !$this->checkEditId($view, $id))
{
// check if item was opened from other than its own list view
$ref = $this->input->getCmd('ref', 0);
@ -68,12 +108,12 @@ class DisplayController extends BaseController
if ($refid > 0 && Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($ref))
{
// redirect to item of ref
$this->setRedirect(Route::_('index.php?option=com_###component###&view='.(string)$ref.'&layout=edit&id='.(int)$refid, false));
$this->setRedirect(Route::_('index.php?option=com_###component###&view=' . (string) $ref . '&layout=edit&id=' . (int) $refid, false));
}
elseif (Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($ref))
{
// redirect to ref
$this->setRedirect(Route::_('index.php?option=com_###component###&view='.(string)$ref, false));
$this->setRedirect(Route::_('index.php?option=com_###component###&view=' . (string) $ref, false));
}
else
{
@ -115,18 +155,133 @@ class DisplayController extends BaseController
return $this;
}
protected function checkEditView($view)
/**
* Method to check whether an ID is in the edit list.
*
* @param string $context The view name.
* @param integer $id The ID of the record to add to the edit list.
*
* @return boolean True if the ID is in the edit list.
*
* @throws \Exception
* @since 3.0
*/
protected function checkEditId($context, $id)
{
if (parent::checkEditId("com_###component###.edit.{$context}", $id))
{
return true;
}
// check user edit access
if ($this->canEditId($context, $id))
{
$this->holdEditId("com_###component###.edit.{$context}", $id);
return true;
}
return false;
}
/**
* Method to check whether an ID is allowed to be edited by the active user.
*
* @param string $view The view name.
* @param integer $id The ID of the record to add to the edit list.
*
* @return boolean True if the ID is in the edit list.
*
* @since 5.0.2
*/
protected function canEditId($view, $id): bool
{
// check that this view is even allowed
$allowed = $this->getAllowedEditView($view);
if ($allowed === null)
{
return false;
}
// check if this item has custom function set for canEditId
if (isset($allowed['function'])
&& method_exists($this, $allowed['function'])
&& $this->{$allowed['function']}(['id' => $id], 'id'))
{
return true;
}
// check if this item can be accessed (and has access)
$access = true;
if (isset($allowed['access']))
{
$access = ($this->identity->authorise($allowed['access'], "com_###component###.{$view}." . (int) $id)
&& $this->identity->authorise($allowed['access'], 'com_###component###'));
}
// check if this item can be edited
$edit = false;
if ($access && isset($allowed['edit']))
{
$edit = ($this->identity->authorise($allowed['edit'], "com_###component###.{$view}." . (int) $id)
&& $this->identity->authorise($allowed['edit'], 'com_###component###'));
}
// check if this item can be edited by owner
if ($access && !$edit && isset($allowed['edit.own']))
{
$edit = ($this->identity->authorise($allowed['edit.own'], "com_###component###.{$view}." . (int) $id)
&& $this->identity->authorise($allowed['edit.own'], 'com_###component###'));
}
return $edit;
}
/**
* Checks if the provided view is an edit view.
*
* This method verifies whether the given view name is recognized as an edit view.
* It uses the StringHelper::check() method to validate the input and then checks
* against a predefined list of edit views.
*
* @param string|null $view The name of the view to check.
*
* @return bool True if the view is an edit view, false otherwise.
* @since 4.0.0
*/
protected function checkEditView(?string $view): bool
{
if (Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($view))
{
$views = [###SITE_EDIT_VIEW_ARRAY###
];
// check if this is a edit view
if (in_array($view,$views))
// check if this is an edit view
if (isset($this->allowed_edit_views[$view]))
{
return true;
}
}
return false;
}
/**
* Get the allowed edit view permission map
*
* @param string|null $view The name of the view to check.
*
* @return array|null The permissions map
* @since 5.0.2
*/
protected function getAllowedEditView(?string $view): ?array
{
if (Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($view))
{
// check if this is an edit view
if (isset($this->allowed_edit_views[$view]))
{
return $this->allowed_edit_views[$view];
}
}
return null;
}###SITE_ALLOW_EDIT_VIEWS_FUNCTIONS###
}

View File

@ -27,6 +27,54 @@ namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Site\View\###
*/
class HtmlView extends BaseHtmlView
{
/**
* The items from the model
*
* @var mixed
* @since 3.10.11
*/
public mixed $items;
/**
* The toolbar object
*
* @var Toolbar
* @since 3.10.11
*/
public Toolbar $toolbar;
/**
* The styles url array
*
* @var array
* @since 5.0.0
*/
protected array $styles;
/**
* The scripts url array
*
* @var array
* @since 5.0.0
*/
protected array $scripts;
/**
* The actions object
*
* @var object
* @since 3.10.11
*/
public object $canDo;
/**
* The user object.
*
* @var Joomla___effdaf6d_2275_425d_9f52_d4952e564d34___Power
* @since 3.10.11
*/
public Joomla___effdaf6d_2275_425d_9f52_d4952e564d34___Power $user;
/**
* Display the view
*
@ -82,6 +130,7 @@ class HtmlView extends BaseHtmlView
{
ToolbarHelper::help('COM_###COMPONENT###_HELP_MANAGER', false, $this->help_url);
}
// now initiate the toolbar
$this->toolbar = Toolbar::getInstance();
}###SITE_GET_MODULE###

View File

@ -25,7 +25,7 @@ namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Site\Controll
*
* @since 1.6
*/
class ###SView###Controller extends FormController
class ###SView###Controller extends Joomla___907ccae5_57a9_44b9_a8aa_5b905d1cd70f___Power
{
/**
* The prefix to use with controller messages.
@ -107,14 +107,14 @@ class ###SView###Controller extends FormController
* Function that allows child controller access to model data
* after the data has been saved.
*
* @param BaseDatabaseModel $model The data model object.
* @param Joomla___6dce7a1b_cfc3_4c2a_837d_be9cbc902446___Power $model The data model object.
* @param array $validData The validated data.
*
* @return void
*
* @since 12.2
*/
protected function postSaveHook(BaseDatabaseModel $model, $validData = [])
protected function postSaveHook(Joomla___6dce7a1b_cfc3_4c2a_837d_be9cbc902446___Power $model, $validData = [])
{
}
}

View File

@ -27,6 +27,38 @@ namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Site\View\###
*/
class HtmlView extends BaseHtmlView
{
/**
* The toolbar object
*
* @var Toolbar
* @since 3.10.11
*/
public Toolbar $toolbar;
/**
* The styles url array
*
* @var array
* @since 3.10.11
*/
protected array $styles;
/**
* The scripts url array
*
* @var array
* @since 3.10.11
*/
protected array $scripts;
/**
* The user object.
*
* @var Joomla___effdaf6d_2275_425d_9f52_d4952e564d34___Power
* @since 3.10.11
*/
public Joomla___effdaf6d_2275_425d_9f52_d4952e564d34___Power $user;
/**
* Display the view
*
@ -41,10 +73,10 @@ class HtmlView extends BaseHtmlView
$this->app ??= Factory::getApplication();
$this->params = $this->app->getParams();
$this->menu = $this->app->getMenu()->getActive();
$this->styles = $this->get('Styles');
$this->scripts = $this->get('Scripts');
$this->styles = $this->get('Styles') ?? [];
$this->scripts = $this->get('Scripts') ?? [];
// get the user object
$this->user ??= $this->app->getIdentity();###SITE_DIPLAY_METHOD###
$this->user ??= $this->getCurrentUser();###SITE_DIPLAY_METHOD###
}###SITE_EXTRA_DIPLAY_METHODS###
/**
@ -82,8 +114,9 @@ class HtmlView extends BaseHtmlView
{
ToolbarHelper::help('COM_###COMPONENT###_HELP_MANAGER', false, $this->help_url);
}
// now initiate the toolbar
$this->toolbar = Toolbar::getInstance();
$this->toolbar ??= Toolbar::getInstance();
}###SITE_GET_MODULE###
/**