1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage Form
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Module Order field.
14 *
15 * @since 1.6
16 */
17 class JFormFieldModuleOrder extends JFormField
18 {
19 /**
20 * The form field type.
21 *
22 * @var string
23 * @since 1.6
24 */
25 protected $type = 'ModuleOrder';
26
27 /**
28 * Name of the layout being used to render the field
29 *
30 * @var string
31 * @since 3.6.3
32 */
33 protected $layout = 'joomla.form.field.moduleorder';
34
35 /**
36 * Method to get certain otherwise inaccessible properties from the form field object.
37 *
38 * @param string $name The property name for which to the the value.
39 *
40 * @return mixed The property value or null.
41 *
42 * @since 3.6.3
43 */
44 public function __get($name)
45 {
46 switch ($name)
47 {
48 case 'linked':
49 return $this->$name;
50 }
51
52 return parent::__get($name);
53 }
54
55 /**
56 * Method to set certain otherwise inaccessible properties of the form field object.
57 *
58 * @param string $name The property name for which to the the value.
59 * @param mixed $value The value of the property.
60 *
61 * @return void
62 *
63 * @since 3.6.3
64 */
65 public function __set($name, $value)
66 {
67 switch ($name)
68 {
69 case 'linked':
70 $this->$name = (string) $value;
71 break;
72
73 default:
74 parent::__set($name, $value);
75 }
76 }
77
78 /**
79 * Method to attach a JForm object to the field.
80 *
81 * @param SimpleXMLElement $element The SimpleXMLElement object representing the `<field>` tag for the form field object.
82 * @param mixed $value The form field value to validate.
83 * @param string $group The field name group control value. This acts as an array container for the field.
84 * For example if the field has name="foo" and the group value is set to "bar" then the
85 * full field name would end up being "bar[foo]".
86 *
87 * @return boolean True on success.
88 *
89 * @see JFormField::setup()
90 * @since 3.6.3
91 */
92 public function setup(SimpleXMLElement $element, $value, $group = null)
93 {
94 $return = parent::setup($element, $value, $group);
95
96 if ($return)
97 {
98 $this->linked = isset($this->element['linked']) ? (int) $this->element['linked'] : 'position';
99 }
100
101 return $return;
102 }
103
104 /**
105 * Method to get the field input markup for the moduleorder field.
106 *
107 * @return string The field input markup.
108 *
109 * @since 1.6
110 */
111 protected function getInput()
112 {
113 return $this->getRenderer($this->layout)->render($this->getLayoutData());
114 }
115
116 /**
117 * Method to get the data to be passed to the layout for rendering.
118 *
119 * @return array
120 *
121 * @since 3.6.3
122 */
123 protected function getLayoutData()
124 {
125 $data = parent::getLayoutData();
126
127 $extraData = array(
128 'ordering' => $this->form->getValue('ordering'),
129 'clientId' => $this->form->getValue('client_id'),
130 'name' => $this->name,
131 'token' => JSession::getFormToken() . '=1',
132 'element' => $this->form->getName() . '_' . $this->linked
133 );
134
135 return array_merge($data, $extraData);
136 }
137 }
138