- md5
- 1fd30a3e655c90608883cd39d98453dc
- sha1
- 7ef005c1468cc77a796875a5a15f07f32f0da054
- sha256
- b36561d24d436786af757b5178927713e57e0fe5aafebae5808a609298ac7865
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
<?php
/**
* @package Joomla.Administrator
* @subpackage com_menus
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Menus\Administrator\Field;
defined('JPATH_BASE') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Form\FormHelper;
use Joomla\CMS\Language\Text;
FormHelper::loadFieldClass('list');
/**
* Menu Parent field.
*
* @since 1.6
*/
class MenuParentField extends \JFormFieldList
{
/**
* The form field type.
*
* @var string
* @since 1.6
*/
protected $type = 'MenuParent';
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 1.6
*/
protected function getOptions()
{
$options = array();
$db = Factory::getDbo();
$query = $db->getQuery(true)
->select('DISTINCT(a.id) AS value, a.title AS text, a.level, a.lft')
->from('#__menu AS a');
// Filter by menu type.
if ($menuType = $this->form->getValue('menutype'))
{
$query->where('a.menutype = ' . $db->quote($menuType));
}
else
{
// Skip special menu types
$query->where('a.menutype != ' . $db->quote(''));
$query->where('a.menutype != ' . $db->quote('main'));
}
// Filter by client id.
$clientId = $this->getAttribute('clientid');
if (!is_null($clientId))
{
$query->where($db->quoteName('a.client_id') . ' = ' . (int) $clientId);
}
// Prevent parenting to children of this item.
if ($id = $this->form->getValue('id'))
{
$query->join('LEFT', $db->quoteName('#__menu') . ' AS p ON p.id = ' . (int) $id)
->where('NOT(a.lft >= p.lft AND a.rgt <= p.rgt)');
}
$query->where('a.published != -2')
->order('a.lft ASC');
// Get the options.
$db->setQuery($query);
try
{
$options = $db->loadObjectList();
}
catch (\RuntimeException $e)
{
Factory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}
// Pad the option text with spaces using depth level as a multiplier.
for ($i = 0, $n = count($options); $i < $n; $i++)
{
if ($clientId != 0)
{
// Allow translation of custom admin menus
$options[$i]->text = str_repeat('- ', $options[$i]->level) . Text::_($options[$i]->text);
}
else
{
$options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text;
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
}
The same content is in 2 releases, Joomla 4.0.0-alpha5 to 4.0.0-alpha6. See them all, or every version of this file.