[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\HTML\Helpers; 11 12 use Joomla\CMS\HTML\HTMLHelper; 13 use Joomla\CMS\Language\Text; 14 use Joomla\CMS\Layout\LayoutHelper; 15 16 // phpcs:disable PSR1.Files.SideEffects 17 \defined('JPATH_PLATFORM') or die; 18 // phpcs:enable PSR1.Files.SideEffects 19 20 /** 21 * HTML utility class for building a dropdown menu 22 * 23 * @since 3.2 24 */ 25 abstract class ActionsDropdown 26 { 27 /** 28 * @var string HTML markup for the dropdown list 29 * @since 3.2 30 */ 31 protected static $dropDownList = array(); 32 33 /** 34 * Method to render current dropdown menu 35 * 36 * @param string $item An item to render. 37 * 38 * @return string HTML markup for the dropdown list 39 * 40 * @since 3.2 41 */ 42 public static function render($item = '') 43 { 44 $html = array(); 45 46 $html[] = '<button data-bs-toggle="dropdown" class="dropdown-toggle btn btn-sm btn-secondary">'; 47 $html[] = '<span class="caret"></span>'; 48 49 if ($item) { 50 $html[] = '<span class="visually-hidden">' . Text::sprintf('JACTIONS', $item) . '</span>'; 51 } 52 53 $html[] = '</button>'; 54 $html[] = '<ul class="dropdown-menu">'; 55 $html[] = implode('', static::$dropDownList); 56 $html[] = '</ul>'; 57 58 static::$dropDownList = null; 59 60 return implode('', $html); 61 } 62 63 /** 64 * Append a publish item to the current dropdown menu 65 * 66 * @param string $id ID of corresponding checkbox of the record 67 * @param string $prefix The task prefix 68 * 69 * @return void 70 * 71 * @since 3.2 72 */ 73 public static function publish($id, $prefix = '') 74 { 75 $task = ($prefix ? $prefix . '.' : '') . 'publish'; 76 static::addCustomItem(Text::_('JTOOLBAR_PUBLISH'), 'publish', $id, $task); 77 } 78 79 /** 80 * Append an unpublish item to the current dropdown menu 81 * 82 * @param string $id ID of corresponding checkbox of the record 83 * @param string $prefix The task prefix 84 * 85 * @return void 86 * 87 * @since 3.2 88 */ 89 public static function unpublish($id, $prefix = '') 90 { 91 $task = ($prefix ? $prefix . '.' : '') . 'unpublish'; 92 static::addCustomItem(Text::_('JTOOLBAR_UNPUBLISH'), 'unpublish', $id, $task); 93 } 94 95 /** 96 * Append a feature item to the current dropdown menu 97 * 98 * @param string $id ID of corresponding checkbox of the record 99 * @param string $prefix The task prefix 100 * 101 * @return void 102 * 103 * @since 3.2 104 */ 105 public static function feature($id, $prefix = '') 106 { 107 $task = ($prefix ? $prefix . '.' : '') . 'featured'; 108 static::addCustomItem(Text::_('JFEATURE'), 'featured', $id, $task); 109 } 110 111 /** 112 * Append an unfeature item to the current dropdown menu 113 * 114 * @param string $id ID of corresponding checkbox of the record 115 * @param string $prefix The task prefix 116 * 117 * @return void 118 * 119 * @since 3.2 120 */ 121 public static function unfeature($id, $prefix = '') 122 { 123 $task = ($prefix ? $prefix . '.' : '') . 'unfeatured'; 124 static::addCustomItem(Text::_('JUNFEATURE'), 'unfeatured', $id, $task); 125 } 126 127 /** 128 * Append an archive item to the current dropdown menu 129 * 130 * @param string $id ID of corresponding checkbox of the record 131 * @param string $prefix The task prefix 132 * 133 * @return void 134 * 135 * @since 3.2 136 */ 137 public static function archive($id, $prefix = '') 138 { 139 $task = ($prefix ? $prefix . '.' : '') . 'archive'; 140 static::addCustomItem(Text::_('JTOOLBAR_ARCHIVE'), 'archive', $id, $task); 141 } 142 143 /** 144 * Append an unarchive item to the current dropdown menu 145 * 146 * @param string $id ID of corresponding checkbox of the record 147 * @param string $prefix The task prefix 148 * 149 * @return void 150 * 151 * @since 3.2 152 */ 153 public static function unarchive($id, $prefix = '') 154 { 155 $task = ($prefix ? $prefix . '.' : '') . 'unpublish'; 156 static::addCustomItem(Text::_('JTOOLBAR_UNARCHIVE'), 'unarchive', $id, $task); 157 } 158 159 /** 160 * Append a duplicate item to the current dropdown menu 161 * 162 * @param string $id ID of corresponding checkbox of the record 163 * @param string $prefix The task prefix 164 * 165 * @return void 166 * 167 * @since 3.2 168 */ 169 public static function duplicate($id, $prefix = '') 170 { 171 $task = ($prefix ? $prefix . '.' : '') . 'duplicate'; 172 static::addCustomItem(Text::_('JTOOLBAR_DUPLICATE'), 'copy', $id, $task); 173 } 174 175 /** 176 * Append a trash item to the current dropdown menu 177 * 178 * @param string $id ID of corresponding checkbox of the record 179 * @param string $prefix The task prefix 180 * 181 * @return void 182 * 183 * @since 3.2 184 */ 185 public static function trash($id, $prefix = '') 186 { 187 $task = ($prefix ? $prefix . '.' : '') . 'trash'; 188 static::addCustomItem(Text::_('JTOOLBAR_TRASH'), 'trash', $id, $task); 189 } 190 191 /** 192 * Append an untrash item to the current dropdown menu 193 * 194 * @param string $id ID of corresponding checkbox of the record 195 * @param string $prefix The task prefix 196 * 197 * @return void 198 * 199 * @since 3.2 200 */ 201 public static function untrash($id, $prefix = '') 202 { 203 self::publish($id, $prefix); 204 } 205 206 /** 207 * Writes a divider between dropdown items 208 * 209 * @return void 210 * 211 * @since 3.0 212 */ 213 public static function divider() 214 { 215 static::$dropDownList[] = '<li class="divider"></li>'; 216 } 217 218 /** 219 * Append a custom item to current dropdown menu. 220 * 221 * @param string $label The label of the item. 222 * @param string $icon The icon classname. 223 * @param string $id The item id. 224 * @param string $task The task. 225 * 226 * @return void 227 * 228 * @since 3.2 229 */ 230 public static function addCustomItem($label, $icon = '', $id = '', $task = '') 231 { 232 static::$dropDownList[] = '<li>' 233 . HTMLHelper::link( 234 'javascript://', 235 ($icon ? LayoutHelper::render('joomla.icon.iconclass', ['icon' => $icon]) : '') . $label, 236 [ 237 'onclick' => 'Joomla.listItemTask(\'' . $id . '\', \'' . $task . '\')' 238 ] 239 ) 240 . '</li>'; 241 } 242 }
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 |