Skip to content

Commit af73758

Browse files
authored
[5.1] Fix Form::renderField() can cause duplicate database queries (#42709)
* FormField collect layout data
1 parent d36ef9a commit af73758

29 files changed

+57
-69
lines changed

libraries/src/Form/Field/CalendarField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ protected function getInput()
327327
$this->value = '';
328328
}
329329

330-
return $this->getRenderer($this->layout)->render($this->getLayoutData());
330+
return $this->getRenderer($this->layout)->render($this->collectLayoutData());
331331
}
332332

333333
/**

libraries/src/Form/Field/CheckboxesField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected function getInput()
110110
throw new \UnexpectedValueException(sprintf('%s has no layout assigned.', $this->name));
111111
}
112112

113-
return $this->getRenderer($this->layout)->render($this->getLayoutData());
113+
return $this->getRenderer($this->layout)->render($this->collectLayoutData());
114114
}
115115

116116
/**

libraries/src/Form/Field/ColorField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ protected function getInput()
232232
}
233233

234234
// Trim the trailing line in the layout file
235-
return rtrim($this->getRenderer($this->layout)->render($this->getLayoutData()), PHP_EOL);
235+
return rtrim($this->getRenderer($this->layout)->render($this->collectLayoutData()), PHP_EOL);
236236
}
237237

238238
/**

libraries/src/Form/Field/ComboField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ protected function getInput()
5050
throw new \UnexpectedValueException(sprintf('%s has no layout assigned.', $this->name));
5151
}
5252

53-
return $this->getRenderer($this->layout)->render($this->getLayoutData());
53+
return $this->getRenderer($this->layout)->render($this->collectLayoutData());
5454
}
5555

5656
/**

libraries/src/Form/Field/ContenthistoryField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ protected function getInput()
7777
throw new \UnexpectedValueException(sprintf('%s has no layout assigned.', $this->name));
7878
}
7979

80-
return $this->getRenderer($this->layout)->render($this->getLayoutData());
80+
return $this->getRenderer($this->layout)->render($this->collectLayoutData());
8181
}
8282
}

libraries/src/Form/Field/EmailField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class EmailField extends TextField
4949
protected function getInput()
5050
{
5151
// Trim the trailing line in the layout file
52-
return rtrim($this->getRenderer($this->layout)->render($this->getLayoutData()), PHP_EOL);
52+
return rtrim($this->getRenderer($this->layout)->render($this->collectLayoutData()), PHP_EOL);
5353
}
5454
/**
5555
* Method to get the data to be passed to the layout for rendering.

libraries/src/Form/Field/FileField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function setup(\SimpleXMLElement $element, $value, $group = null)
126126
*/
127127
protected function getInput()
128128
{
129-
return $this->getRenderer($this->layout)->render($this->getLayoutData());
129+
return $this->getRenderer($this->layout)->render($this->collectLayoutData());
130130
}
131131

132132
/**

libraries/src/Form/Field/GroupedlistField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected function getGroups()
154154
*/
155155
protected function getInput()
156156
{
157-
$data = $this->getLayoutData();
157+
$data = $this->collectLayoutData();
158158

159159
// Get the field groups.
160160
$data['groups'] = (array) $this->getGroups();

libraries/src/Form/Field/HiddenField.php

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -39,29 +39,4 @@ class HiddenField extends FormField
3939
* @since 3.7
4040
*/
4141
protected $layout = 'joomla.form.field.hidden';
42-
43-
/**
44-
* Method to get the field input markup.
45-
*
46-
* @return string The field input markup.
47-
*
48-
* @since 1.7.0
49-
*/
50-
protected function getInput()
51-
{
52-
// Trim the trailing line in the layout file
53-
return rtrim($this->getRenderer($this->layout)->render($this->getLayoutData()), PHP_EOL);
54-
}
55-
56-
/**
57-
* Method to get the data to be passed to the layout for rendering.
58-
*
59-
* @return array
60-
*
61-
* @since 3.7
62-
*/
63-
protected function getLayoutData()
64-
{
65-
return parent::getLayoutData();
66-
}
6742
}

libraries/src/Form/Field/ListField.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ListField extends FormField
5858
*/
5959
protected function getInput()
6060
{
61-
$data = $this->getLayoutData();
61+
$data = $this->collectLayoutData();
6262

6363
$data['options'] = (array) $this->getOptions();
6464

0 commit comments

Comments
 (0)