[ 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) 2011 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 Ordering field. 24 * 25 * @since 1.6 26 */ 27 class MenuOrderingField extends ListField 28 { 29 /** 30 * The form field type. 31 * 32 * @var string 33 * @since 1.7 34 */ 35 protected $type = 'MenuOrdering'; 36 37 /** 38 * Method to get the list of siblings in a menu. 39 * The method requires that parent be set. 40 * 41 * @return array|boolean The field option objects or false if the parent field has not been set 42 * 43 * @since 1.7 44 */ 45 protected function getOptions() 46 { 47 $options = array(); 48 49 // Get the parent 50 $parent_id = (int) $this->form->getValue('parent_id', 0); 51 52 if (!$parent_id) { 53 return false; 54 } 55 56 $db = $this->getDatabase(); 57 $query = $db->getQuery(true) 58 ->select( 59 [ 60 $db->quoteName('a.id', 'value'), 61 $db->quoteName('a.title', 'text'), 62 $db->quoteName('a.client_id', 'clientId'), 63 ] 64 ) 65 ->from($db->quoteName('#__menu', 'a')) 66 67 ->where($db->quoteName('a.published') . ' >= 0') 68 ->where($db->quoteName('a.parent_id') . ' = :parentId') 69 ->bind(':parentId', $parent_id, ParameterType::INTEGER); 70 71 if ($menuType = $this->form->getValue('menutype')) { 72 $query->where($db->quoteName('a.menutype') . ' = :menuType') 73 ->bind(':menuType', $menuType); 74 } else { 75 $query->where($db->quoteName('a.menutype') . ' != ' . $db->quote('')); 76 } 77 78 $query->order($db->quoteName('a.lft') . ' ASC'); 79 80 // Get the options. 81 $db->setQuery($query); 82 83 try { 84 $options = $db->loadObjectList(); 85 } catch (\RuntimeException $e) { 86 Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); 87 } 88 89 // Allow translation of custom admin menus 90 foreach ($options as &$option) { 91 if ($option->clientId != 0) { 92 $option->text = Text::_($option->text); 93 } 94 } 95 96 $options = array_merge( 97 array(array('value' => '-1', 'text' => Text::_('COM_MENUS_ITEM_FIELD_ORDERING_VALUE_FIRST'))), 98 $options, 99 array(array('value' => '-2', 'text' => Text::_('COM_MENUS_ITEM_FIELD_ORDERING_VALUE_LAST'))) 100 ); 101 102 // Merge any additional options in the XML definition. 103 $options = array_merge(parent::getOptions(), $options); 104 105 return $options; 106 } 107 108 /** 109 * Method to get the field input markup. 110 * 111 * @return string The field input markup. 112 * 113 * @since 1.7 114 */ 115 protected function getInput() 116 { 117 if ($this->form->getValue('id', 0) == 0) { 118 return '<span class="readonly">' . Text::_('COM_MENUS_ITEM_FIELD_ORDERING_TEXT') . '</span>'; 119 } else { 120 return parent::getInput(); 121 } 122 } 123 }
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 |