1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 JFormHelper::loadFieldClass('list');
13
14 15 16 17 18
19 class JFormFieldContenttype extends JFormFieldList
20 {
21 22 23 24 25 26
27 public $type = 'Contenttype';
28
29 30 31 32 33 34 35
36 protected function getInput()
37 {
38 if (!is_array($this->value))
39 {
40 if (is_object($this->value))
41 {
42 $this->value = $this->value->tags;
43 }
44
45 if (is_string($this->value))
46 {
47 $this->value = explode(',', $this->value);
48 }
49 }
50
51 return parent::getInput();
52 }
53
54 55 56 57 58 59 60
61 protected function getOptions()
62 {
63 $lang = JFactory::getLanguage();
64 $db = JFactory::getDbo();
65 $query = $db->getQuery(true)
66 ->select('a.type_id AS value, a.type_title AS text, a.type_alias AS alias')
67 ->from('#__content_types AS a')
68
69 ->order('a.type_title ASC');
70
71
72 $db->setQuery($query);
73
74 try
75 {
76 $options = $db->loadObjectList();
77 }
78 catch (RuntimeException $e)
79 {
80 return array();
81 }
82
83
84 $options = array_merge(parent::getOptions(), $options);
85
86 foreach ($options as $option)
87 {
88
89 $parts = explode('.', $option->alias);
90 $comp = array_shift($parts);
91
92
93 $lang->load($comp . '.sys', JPATH_ADMINISTRATOR, null, false, true)
94 || $lang->load($comp . '.sys', JPATH_ADMINISTRATOR . '/components/' . $comp, null, false, true);
95
96 $option->string = implode('_', $parts);
97 $option->string = $comp . '_CONTENT_TYPE_' . $option->string;
98
99 if ($lang->hasKey($option->string))
100 {
101 $option->text = JText::_($option->string);
102 }
103
104 }
105
106 return $options;
107 }
108 }
109