[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/src/HTML/Helpers/ -> DraggableList.php (source)

   1  <?php
   2  
   3  /**
   4   * Joomla! Content Management System
   5   *
   6   * @copyright  (C) 2016 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\Factory;
  13  use Joomla\CMS\Session\Session;
  14  
  15  // phpcs:disable PSR1.Files.SideEffects
  16  \defined('JPATH_PLATFORM') or die;
  17  // phpcs:enable PSR1.Files.SideEffects
  18  
  19  /**
  20   * HTML utility class for creating a sortable table list
  21   *
  22   * @since  4.0.0
  23   */
  24  abstract class DraggableList
  25  {
  26      /**
  27       * Array containing information for loaded files
  28       *
  29       * @var    array
  30       * @since  4.0.0
  31       */
  32      protected static $loaded = array();
  33  
  34      /**
  35       * Method to load the Dragula script and make table sortable
  36       *
  37       * @param   string   $tableId          DOM id of the table
  38       * @param   string   $formId           DOM id of the form
  39       * @param   string   $sortDir          Sort direction
  40       * @param   string   $saveOrderingUrl  Save ordering url, ajax-load after an item dropped
  41       * @param   string   $redundant        Not used
  42       * @param   boolean  $nestedList       Set whether the list is a nested list
  43       *
  44       * @return  void
  45       *
  46       * @since   4.0.0
  47       */
  48      public static function draggable(
  49          string $tableId = '',
  50          string $formId = '',
  51          string $sortDir = 'asc',
  52          string $saveOrderingUrl = '',
  53          $redundant = null,
  54          bool $nestedList = false
  55      ) {
  56          // Only load once
  57          if (isset(static::$loaded[__METHOD__])) {
  58              return;
  59          }
  60  
  61          $doc = Factory::getDocument();
  62  
  63          // Please consider using data attributes instead of passing arguments here!
  64          if (!empty($tableId) && !empty($saveOrderingUrl) && !empty($formId) && !empty($sortDir)) {
  65              $doc->addScriptOptions(
  66                  'draggable-list',
  67                  [
  68                      'id'        => '#' . $tableId . ' tbody',
  69                      'formId'    => $formId,
  70                      'direction' => $sortDir,
  71                      'url'       => $saveOrderingUrl . '&' . Session::getFormToken() . '=1',
  72                      'nested'    => $nestedList,
  73                  ]
  74              );
  75          }
  76  
  77          $doc->getWebAssetManager()
  78              ->usePreset('dragula')
  79              ->useScript('joomla.draggable');
  80  
  81          // Set static array
  82          static::$loaded[__METHOD__] = true;
  83      }
  84  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer