1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 use Joomla\Utilities\ArrayHelper;
13
14 JFormHelper::loadFieldClass('list');
15
16 17 18 19 20
21 class JFormFieldComponents extends JFormFieldList
22 {
23 24 25 26 27 28
29 protected $type = 'Components';
30
31 32 33 34 35 36 37
38 protected function getOptions()
39 {
40 $db = JFactory::getDbo();
41 $query = $db->getQuery(true)
42 ->select('name AS text, element AS value')
43 ->from('#__extensions')
44 ->where('enabled >= 1')
45 ->where('type =' . $db->quote('component'));
46
47 $items = $db->setQuery($query)->loadObjectList();
48
49 if ($items)
50 {
51 $lang = JFactory::getLanguage();
52
53 foreach ($items as &$item)
54 {
55
56 $extension = $item->value;
57
58 $lang->load("$extension.sys", JPATH_ADMINISTRATOR, null, false, true)
59 || $lang->load("$extension.sys", JPATH_ADMINISTRATOR . '/components/' . $extension, null, false, true);
60
61
62 $item->text = JText::_($item->text);
63 }
64
65
66 $items = ArrayHelper::sortObjects($items, 'text', 1, true, true);
67 }
68
69
70 $options = array_merge(parent::getOptions(), $items);
71
72 return $options;
73 }
74 }
75