[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_scheduler/src/Field/ -> TaskTypeField.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_scheduler
   6   *
   7   * @copyright   (C) 2021 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\Scheduler\Administrator\Field;
  12  
  13  use Joomla\CMS\Form\Field\ListField;
  14  use Joomla\CMS\HTML\HTMLHelper;
  15  use Joomla\Component\Scheduler\Administrator\Helper\SchedulerHelper;
  16  use Joomla\Component\Scheduler\Administrator\Task\TaskOption;
  17  use Joomla\Utilities\ArrayHelper;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('_JEXEC') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * A list field with all available task routines.
  25   *
  26   * @since  4.1.0
  27   */
  28  class TaskTypeField extends ListField
  29  {
  30      /**
  31       * The form field type.
  32       *
  33       * @var    string
  34       * @since  4.1.0
  35       */
  36      protected $type = 'taskType';
  37  
  38      /**
  39       * Method to get field options
  40       *
  41       * @return array
  42       *
  43       * @since  4.1.0
  44       * @throws \Exception
  45       */
  46      protected function getOptions(): array
  47      {
  48          $options = parent::getOptions();
  49  
  50          // Get all available task types and sort by title
  51          $types = ArrayHelper::sortObjects(
  52              SchedulerHelper::getTaskOptions()->options,
  53              'title',
  54              1
  55          );
  56  
  57          // Closure to add a TaskOption as a <select> option in $options: array
  58          $addTypeAsOption = function (TaskOption $type) use (&$options) {
  59              try {
  60                  $options[] = HTMLHelper::_('select.option', $type->id, $type->title);
  61              } catch (\InvalidArgumentException $e) {
  62              }
  63          };
  64  
  65          // Call $addTypeAsOption on each type
  66          array_map($addTypeAsOption, $types);
  67  
  68          return $options;
  69      }
  70  }


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