- md5
- 717c573f89b7b42ce2b9238aa4e17c38
- sha1
- 22c4218604bf48a80876be0c921cc7d12a421d5d
- sha256
- ef25f5ad99cf48af4758b2bceeed9fda2058b0e83ce8c0a5c8080ee17455e39c
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Form\Field;
use Joomla\CMS\Language\Text;
use Joomla\Database\ParameterType;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Supports an HTML select list of menus
*
* @since 1.6
*/
class MenuField extends GroupedlistField
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
public $type = 'Menu';
/**
* Method to get the field option groups.
*
* @return array[] The field option objects as a nested array in groups.
*
* @since 1.7.0
* @throws \UnexpectedValueException
*/
protected function getGroups()
{
$clientId = (string) $this->element['clientid'];
$accessType = (string) $this->element['accesstype'];
$showAll = (string) $this->element['showAll'] === 'true';
$db = $this->getDatabase();
$query = $db->createQuery()
->select(
[
$db->quoteName('id'),
$db->quoteName('menutype', 'value'),
$db->quoteName('title', 'text'),
$db->quoteName('client_id'),
]
)
->from($db->quoteName('#__menu_types'))
->order(
[
$db->quoteName('client_id'),
$db->quoteName('ordering'),
]
);
if (\strlen($clientId)) {
$client = (int) $clientId;
$query->where($db->quoteName('client_id') . ' = :client')
->bind(':client', $client, ParameterType::INTEGER);
}
$menus = $db->setQuery($query)->loadObjectList();
if ($accessType) {
$user = $this->getCurrentUser();
foreach ($menus as $key => $menu) {
switch ($accessType) {
case 'create':
case 'manage':
if (!$user->authorise('core.' . $accessType, 'com_menus.menu.' . (int) $menu->id)) {
unset($menus[$key]);
}
break;
case 'edit':
// Editing a menu item is a bit tricky, we have to check the current menutype for core.edit and all others for core.create
$check = $this->value == $menu->value ? 'edit' : 'create';
if (!$user->authorise('core.' . $check, 'com_menus.menu.' . (int) $menu->id)) {
unset($menus[$key]);
}
break;
}
}
}
$opts = [];
// Protected menutypes can be shown if requested
if ($clientId == 1 && $showAll) {
$opts[] = (object) [
'value' => 'main',
'text' => Text::_('COM_MENUS_MENU_TYPE_PROTECTED_MAIN_LABEL'),
'client_id' => 1,
];
}
$options = array_merge($opts, $menus);
$groups = [];
if (\strlen($clientId)) {
$groups[0] = $options;
} else {
foreach ($options as $option) {
// If client id is not specified we group the items.
$label = ($option->client_id == 1 ? Text::_('JADMINISTRATOR') : Text::_('JSITE'));
$groups[$label][] = $option;
}
}
// Merge any additional options in the XML definition.
return array_merge(parent::getGroups(), $groups);
}
}
The same content is in 43 releases, Joomla 6.0.0-rc1 to 6.2.0. See them all, or every version of this file.