Release of v5.1.1-beta3

Fixes issue with loading the Component Builder Wiki. Adds advanced version update notice to the Component Builder Dashboard. Completely refactors the class that builds the Component Dashboard. #1134.
This commit is contained in:
2025-06-23 17:02:17 +00:00
parent 3c1057a830
commit dbebb5663c
28 changed files with 2067 additions and 888 deletions

View File

@ -27,6 +27,24 @@ namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Administrator
*/
class ###Component###Model extends ListModel
{
/**
* Represents the current user object.
*
* @var User The user object representing the current user.
* @since 3.2.0
*/
protected User $user;
/**
* View groups of this component
*
* @var array<string, string>
* @since 5.1.1
*/
protected array $viewGroups = [
'main' => [###DASHBOARDICONS###],
];
###DASHBOARDICONACCESS###
/**
* The styles array.
*
@ -48,199 +66,50 @@ class ###Component###Model extends ListModel
'administrator/components/com_###component###/assets/js/admin.js'
];
public function getIcons()
/**
* Constructor
*
* @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request).
* @param ?MVCFactoryInterface $factory The factory.
*
* @since 1.6
* @throws \Exception
*/
public function __construct($config = [], MVCFactoryInterface $factory = null)
{
// load user for access menus
$user = Joomla___39403062_84fb_46e0_bac4_0023f766e827___Power::getApplication()->getIdentity();
// reset icon array
$icons = [];
// view groups array
$viewGroups = array(
'main' => array(###DASHBOARDICONS###)
);###DASHBOARDICONACCESS###
// loop over the $views
foreach($viewGroups as $group => $views)
parent::__construct($config, $factory);
$this->user ??= $this->getCurrentUser();
}
/**
* Get dashboard icons, grouped by view sections.
*
* @return array<string, array<int, \stdClass|false>>
* @since 5.1.1
*/
public function getIcons(): array
{
$icons = [];
foreach ($this->viewGroups as $group => $views)
{
$i = 0;
if (Super___0a59c65c_9daf_4bc9_baf4_e063ff9e6a8a___Power::check($views))
if (!Super___0a59c65c_9daf_4bc9_baf4_e063ff9e6a8a___Power::check($views))
{
foreach($views as $view)
$icons[$group][] = false;
continue;
}
foreach ($views as $view)
{
$icon = $this->buildIconObject($view);
if ($icon !== null)
{
$add = false;
// external views (links)
if (strpos($view,'||') !== false)
{
$dwd = explode('||', $view);
if (count($dwd) == 3)
{
list($type, $name, $url) = $dwd;
$viewName = $name;
$alt = $name;
$url = $url;
$image = $name . '.' . $type;
$name = 'COM_###COMPONENT###_DASHBOARD_' . Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::safe($name,'U');
}
}
// internal views
elseif (strpos($view,'.') !== false)
{
$dwd = explode('.', $view);
if (count($dwd) == 3)
{
list($type, $name, $action) = $dwd;
}
elseif (count($dwd) == 2)
{
list($type, $name) = $dwd;
$action = false;
}
if ($action)
{
$viewName = $name;
switch($action)
{
case 'add':
$url = 'index.php?option=com_###component###&view=' . $name . '&layout=edit';
$image = $name . '_' . $action. '.' . $type;
$alt = $name . '&nbsp;' . $action;
$name = 'COM_###COMPONENT###_DASHBOARD_'.Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::safe($name,'U').'_ADD';
$add = true;
break;
default:
// check for new convention (more stable)
if (strpos($action, '_qpo0O0oqp_') !== false)
{
list($action, $extension) = (array) explode('_qpo0O0oqp_', $action);
$extension = str_replace('_po0O0oq_', '.', $extension);
}
else
{
$extension = 'com_###component###.' . $name;
}
$url = 'index.php?option=com_categories&view=categories&extension=' . $extension;
$image = $name . '_' . $action . '.' . $type;
$alt = $viewName . '&nbsp;' . $action;
$name = 'COM_###COMPONENT###_DASHBOARD_' . Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::safe($name,'U') . '_' . Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::safe($action,'U');
break;
}
}
else
{
$viewName = $name;
$alt = $name;
$url = 'index.php?option=com_###component###&view=' . $name;
$image = $name . '.' . $type;
$name = 'COM_###COMPONENT###_DASHBOARD_' . Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::safe($name,'U');
$hover = false;
}
}
else
{
$viewName = $view;
$alt = $view;
$url = 'index.php?option=com_###component###&view=' . $view;
$image = $view . '.png';
$name = ucwords($view).'<br /><br />';
$hover = false;
}
// first make sure the view access is set
if (Super___0a59c65c_9daf_4bc9_baf4_e063ff9e6a8a___Power::check($viewAccess))
{
// setup some defaults
$dashboard_add = false;
$dashboard_list = false;
$accessTo = '';
$accessAdd = '';
// access checking start
$accessCreate = (isset($viewAccess[$viewName.'.create'])) ? Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($viewAccess[$viewName.'.create']):false;
$accessAccess = (isset($viewAccess[$viewName.'.access'])) ? Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($viewAccess[$viewName.'.access']):false;
// set main controllers
$accessDashboard_add = (isset($viewAccess[$viewName.'.dashboard_add'])) ? Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($viewAccess[$viewName.'.dashboard_add']):false;
$accessDashboard_list = (isset($viewAccess[$viewName.'.dashboard_list'])) ? Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($viewAccess[$viewName.'.dashboard_list']):false;
// check for adding access
if ($add && $accessCreate)
{
$accessAdd = $viewAccess[$viewName.'.create'];
}
elseif ($add)
{
$accessAdd = 'core.create';
}
// check if access to view is set
if ($accessAccess)
{
$accessTo = $viewAccess[$viewName.'.access'];
}
// set main access controllers
if ($accessDashboard_add)
{
$dashboard_add = $user->authorise($viewAccess[$viewName.'.dashboard_add'], 'com_###component###');
}
if ($accessDashboard_list)
{
$dashboard_list = $user->authorise($viewAccess[$viewName.'.dashboard_list'], 'com_###component###');
}
if (Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($accessAdd) && Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($accessTo))
{
// check access
if($user->authorise($accessAdd, 'com_###component###') && $user->authorise($accessTo, 'com_###component###') && $dashboard_add)
{
$icons[$group][$i] = new \StdClass;
$icons[$group][$i]->url = $url;
$icons[$group][$i]->name = $name;
$icons[$group][$i]->image = $image;
$icons[$group][$i]->alt = $alt;
}
}
elseif (Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($accessTo))
{
// check access
if($user->authorise($accessTo, 'com_###component###') && $dashboard_list)
{
$icons[$group][$i] = new \StdClass;
$icons[$group][$i]->url = $url;
$icons[$group][$i]->name = $name;
$icons[$group][$i]->image = $image;
$icons[$group][$i]->alt = $alt;
}
}
elseif (Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($accessAdd))
{
// check access
if($user->authorise($accessAdd, 'com_###component###') && $dashboard_add)
{
$icons[$group][$i] = new \StdClass;
$icons[$group][$i]->url = $url;
$icons[$group][$i]->name = $name;
$icons[$group][$i]->image = $image;
$icons[$group][$i]->alt = $alt;
}
}
else
{
$icons[$group][$i] = new \StdClass;
$icons[$group][$i]->url = $url;
$icons[$group][$i]->name = $name;
$icons[$group][$i]->image = $image;
$icons[$group][$i]->alt = $alt;
}
}
else
{
$icons[$group][$i] = new \StdClass;
$icons[$group][$i]->url = $url;
$icons[$group][$i]->name = $name;
$icons[$group][$i]->image = $image;
$icons[$group][$i]->alt = $alt;
}
$i++;
$icons[$group][] = $icon;
}
}
else
{
$icons[$group][$i] = false;
}
}
return $icons;
}
@ -286,5 +155,188 @@ class ###Component###Model extends ListModel
public function setScript(string $path): void
{
$this->scripts[] = $path;
}
/**
* Build a single dashboard icon if access is granted.
*
* @param string $view The view string to parse.
*
* @return \stdClass|null The icon object or null if access denied.
* @since 5.1.1
*/
protected function buildIconObject(string $view): ?\stdClass
{
$parsed = $this->parseViewDefinition($view);
if (!$parsed)
{
return null;
}
[
'type' => $type,
'name' => $name,
'url' => $url,
'image' => $image,
'alt' => $alt,
'viewName' => $viewName,
'add' => $add,
] = $parsed;
if (!$this->hasAccessToView($viewName, $add))
{
return null;
}
return $this->createIconObject($url, $name, $image, $alt);
}
/**
* Parse a view string into structured components.
*
* @param string $view The view definition string.
*
* @return array<string, mixed>|null Parsed values or null on failure.
* @since 5.1.1
*/
protected function parseViewDefinition(string $view): ?array
{
$add = false;
if (strpos($view, '||') !== false)
{
$parts = explode('||', $view);
if (count($parts) === 3)
{
[$type, $name, $url] = $parts;
return [
'type' => $type,
'name' => 'COM_###COMPONENT###_DASHBOARD_' . Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::safe($name, 'U'),
'url' => $url,
'image' => "{$name}.{$type}",
'alt' => $name,
'viewName' => $name,
'add' => false,
];
}
}
if (strpos($view, '.') !== false)
{
$parts = explode('.', $view);
$type = $parts[0] ?? '';
$name = $parts[1] ?? '';
$action = $parts[2] ?? null;
$viewName = $name;
if ($action)
{
if ($action === 'add')
{
$url = "index.php?option=com_###component###&view={$name}&layout=edit";
$image = "{$name}_{$action}.{$type}";
$alt = "{$name}&nbsp;{$action}";
$name = 'COM_###COMPONENT###_DASHBOARD_' .
Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::safe($name, 'U') . '_ADD';
$add = true;
}
else
{
if (strpos($action, '_qpo0O0oqp_') !== false)
{
[$action, $ext] = explode('_qpo0O0oqp_', $action);
$extension = str_replace('_po0O0oq_', '.', $ext);
}
else
{
$extension = "com_###component###.{$name}";
}
$url = "index.php?option=com_categories&view=categories&extension={$extension}";
$image = "{$name}_{$action}.{$type}";
$alt = "{$name}&nbsp;{$action}";
$name = 'COM_###COMPONENT###_DASHBOARD_' .
Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::safe($name, 'U') . '_' .
Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::safe($action, 'U');
}
}
else
{
$url = "index.php?option=com_###component###&view={$name}";
$image = "{$name}.{$type}";
$alt = $name;
$name = 'COM_###COMPONENT###_DASHBOARD_' .
Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::safe($name, 'U');
}
return compact('type', 'name', 'url', 'image', 'alt', 'viewName', 'add');
}
return [
'type' => 'png',
'name' => ucwords($view) . '<br /><br />',
'url' => "index.php?option=com_###component###&view={$view}",
'image' => "{$view}.png",
'alt' => $view,
'viewName' => $view,
'add' => false,
];
}
/**
* Determine if the user has access to view or create the item.
*
* @param string $viewName The base name of the view.
* @param bool $add If this is an add-action.
*
* @return bool
* @since 5.1.1
*/
protected function hasAccessToView(string $viewName, bool $add): bool
{
$viewAccess = $this->viewAccess;
$accessAdd = $add && isset($viewAccess["{$viewName}.create"])
? $viewAccess["{$viewName}.create"]
: ($add ? 'core.create' : '');
$accessTo = $viewAccess["{$viewName}.access"] ?? '';
$dashboardAdd = isset($viewAccess["{$viewName}.dashboard_add"]) &&
$this->user->authorise($viewAccess["{$viewName}.dashboard_add"], 'com_###component###');
$dashboardList = isset($viewAccess["{$viewName}.dashboard_list"]) &&
$this->user->authorise($viewAccess["{$viewName}.dashboard_list"], 'com_###component###');
if ($add && Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($accessAdd))
{
return $this->user->authorise($accessAdd, 'com_###component###') && $dashboardAdd;
}
if (Super___1f28cb53_60d9_4db1_b517_3c7dc6b429ef___Power::check($accessTo))
{
return $this->user->authorise($accessTo, 'com_###component###') && $dashboardList;
}
return !$accessTo && !$accessAdd;
}
/**
* Create a \stdClass icon object.
*
* @param string $url Icon URL.
* @param string $name Language string or label.
* @param string $image Image filename.
* @param string $alt Alt text.
*
* @return \stdClass
* @since 5.1.1
*/
protected function createIconObject(string $url, string $name, string $image, string $alt): \stdClass
{
$icon = new \stdClass;
$icon->url = $url;
$icon->name = $name;
$icon->image = $image;
$icon->alt = $alt;
return $icon;
}###DASH_MODEL_METHODS###
}

View File

@ -28,6 +28,60 @@ namespace ###NAMESPACEPREFIX###\Component\###ComponentNamespace###\Administrator
#[\AllowDynamicProperties]
class HtmlView extends BaseHtmlView
{
/**
* @var array<string> List of icon identifiers to render in the dashboard view.
* @since 1.6
*/
public array $icons = [];
/**
* @var array<string> List of CSS file URLs to be added to the page.
* @since 4.3
*/
public array $styles = [];
/**
* @var array<string> List of JavaScript file URLs to be included on the page.
* @since 4.3
*/
public array $scripts = [];
/**
* @var array<int, object> List of contributor objects fetched via the helper.
* @since 1.6
*/
public array $contributors = [];
/**
* @var object|null The manifest metadata of the component as returned by `ComponentbuilderHelper::manifest()`.
* @since 1.6
*/
public $manifest = null;
/**
* @var string|null Markdown content of the component's wiki page.
* @since 1.6
*/
public ?string $wiki = null;
/**
* @var string|null The rendered or raw README markdown of the component.
* @since 1.6
*/
public ?string $readme = null;
/**
* @var string|null The current version of the component.
* @since 1.6
*/
public ?string $version = null;
/**
* @var string|null Help URL for the component dashboard view, if available.
* @since 1.6
*/
public ?string $help_url = null;
/**
* View display method
*
@ -96,8 +150,12 @@ class HtmlView extends BaseHtmlView
{
// set page title
$this->getDocument()->setTitle(Joomla___ba6326ef_cb79_4348_80f4_ab086082e3c5___Power::_('COM_###COMPONENT###_DASHBOARD'));
// add manifest to page JavaScript
$this->getDocument()->addScriptDeclaration("var manifest = JSON.parse(" . json_encode($this->manifest) . ");", "text/javascript");
/** \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->getDocument()->getWebAssetManager();
// Register the inline script with properly encoded JSON
$wa->addInlineScript(
'var manifest = ' . json_encode($this->manifest, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . ';'
);
// add styles
foreach ($this->styles as $style)
{