[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_menus 6 * 7 * @copyright (C) 2009 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Menus\Administrator\Field; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\Form\Field\ListField; 15 use Joomla\CMS\Language\Text; 16 use Joomla\Database\ParameterType; 17 18 // phpcs:disable PSR1.Files.SideEffects 19 \defined('_JEXEC') or die; 20 // phpcs:enable PSR1.Files.SideEffects 21 22 /** 23 * Menu Parent field. 24 * 25 * @since 1.6 26 */ 27 class MenuParentField extends ListField 28 { 29 /** 30 * The form field type. 31 * 32 * @var string 33 * @since 1.6 34 */ 35 protected $type = 'MenuParent'; 36 37 /** 38 * Method to get the field options. 39 * 40 * @return array The field option objects. 41 * 42 * @since 1.6 43 */ 44 protected function getOptions() 45 { 46 $options = array(); 47 48 $db = $this->getDatabase(); 49 $query = $db->getQuery(true) 50 ->select( 51 [ 52 'DISTINCT ' . $db->quoteName('a.id', 'value'), 53 $db->quoteName('a.title', 'text'), 54 $db->quoteName('a.level'), 55 $db->quoteName('a.lft'), 56 ] 57 ) 58 ->from($db->quoteName('#__menu', 'a')); 59 60 // Filter by menu type. 61 if ($menuType = $this->form->getValue('menutype')) { 62 $query->where($db->quoteName('a.menutype') . ' = :menuType') 63 ->bind(':menuType', $menuType); 64 } else { 65 // Skip special menu types 66 $query->where($db->quoteName('a.menutype') . ' != ' . $db->quote('')); 67 $query->where($db->quoteName('a.menutype') . ' != ' . $db->quote('main')); 68 } 69 70 // Filter by client id. 71 $clientId = $this->getAttribute('clientid'); 72 73 if (!is_null($clientId)) { 74 $clientId = (int) $clientId; 75 $query->where($db->quoteName('a.client_id') . ' = :clientId') 76 ->bind(':clientId', $clientId, ParameterType::INTEGER); 77 } 78 79 // Prevent parenting to children of this item. 80 if ($id = (int) $this->form->getValue('id')) { 81 $query->join('LEFT', $db->quoteName('#__menu', 'p'), $db->quoteName('p.id') . ' = :id') 82 ->bind(':id', $id, ParameterType::INTEGER) 83 ->where( 84 'NOT(' . $db->quoteName('a.lft') . ' >= ' . $db->quoteName('p.lft') 85 . ' AND ' . $db->quoteName('a.rgt') . ' <= ' . $db->quoteName('p.rgt') . ')' 86 ); 87 } 88 89 $query->where($db->quoteName('a.published') . ' != -2') 90 ->order($db->quoteName('a.lft') . ' ASC'); 91 92 // Get the options. 93 $db->setQuery($query); 94 95 try { 96 $options = $db->loadObjectList(); 97 } catch (\RuntimeException $e) { 98 Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); 99 } 100 101 // Pad the option text with spaces using depth level as a multiplier. 102 for ($i = 0, $n = count($options); $i < $n; $i++) { 103 if ($clientId != 0) { 104 // Allow translation of custom admin menus 105 $options[$i]->text = str_repeat('- ', $options[$i]->level) . Text::_($options[$i]->text); 106 } else { 107 $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text; 108 } 109 } 110 111 // Merge any additional options in the XML definition. 112 $options = array_merge(parent::getOptions(), $options); 113 114 return $options; 115 } 116 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |