Skip to content

Commit bcb2601

Browse files
author
Rene Pasing
committed
Comply with Joomla phpcs.
1 parent e835e5f commit bcb2601

File tree

3 files changed

+60
-39
lines changed

3 files changed

+60
-39
lines changed

administrator/components/com_fields/models/fields/subformtype.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
/**
1414
* Fields Subformtype
1515
*
16-
* @see \JFormFieldType
17-
* @since __DEPLOY_VERSION__
16+
* @see \JFormFieldType
17+
* @since __DEPLOY_VERSION__
1818
*/
1919
class JFormFieldSubformtype extends JFormFieldList
2020
{

plugins/fields/subform/subform.php

Lines changed: 57 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/**
1515
* Fields subform Plugin
1616
*
17-
* @since __DEPLOY_VERSION__
17+
* @since __DEPLOY_VERSION__
1818
*/
1919
class PlgFieldsSubform extends FieldsPlugin
2020
{
@@ -28,6 +28,16 @@ class PlgFieldsSubform extends FieldsPlugin
2828
*/
2929
protected $renderCache = array();
3030

31+
/**
32+
* Handles the onContentPrepareForm event. Adds form definitions to relevant forms.
33+
*
34+
* @param JForm $form The form to manipulate
35+
* @param array|object $data The data of the form
36+
*
37+
* @return void
38+
*
39+
* @since __DEPLOY_VERSION__
40+
*/
3141
public function onContentPrepareForm(JForm $form, $data)
3242
{
3343
$path = $this->getFormPath($form, $data);
@@ -37,11 +47,11 @@ public function onContentPrepareForm(JForm $form, $data)
3747
}
3848

3949
// Load our own form definition
40-
$xml = new DOMDocument();
50+
$xml = new DOMDocument;
4151
$xml->load($path);
4252

4353
// Get the options subform
44-
$xmlxpath = new DOMXPath($xml);
54+
$xmlxpath = new DOMXPath($xml);
4555
$hiddenform = $xmlxpath->evaluate(
4656
'/form/fields[@name="fieldparams"]/fieldset[@name="fieldparams"]/field[@name="options"]/form'
4757
);
@@ -72,7 +82,7 @@ public function onContentPrepareForm(JForm $form, $data)
7282
try
7383
{
7484
// Try to load the XML definition file into a DOMDocument
75-
$subxml = new DOMDocument();
85+
$subxml = new DOMDocument;
7686
$subxml->load($path);
7787
$subxmlxpath = new DOMXPath($subxml);
7888

@@ -115,11 +125,11 @@ public function onContentPrepareForm(JForm $form, $data)
115125
* Manipulates the $field->value before the field is being passed to
116126
* onCustomFieldsPrepareField.
117127
*
118-
* @param string $context
119-
* @param object $item
120-
* @param \stdClass $field
128+
* @param string $context The context
129+
* @param object $item The item
130+
* @param \stdClass $field The field
121131
*
122-
* @return void
132+
* @return void
123133
*
124134
* @since __DEPLOY_VERSION__
125135
*/
@@ -145,11 +155,11 @@ public function onCustomFieldsBeforePrepareField($context, $item, $field)
145155
* and joining all those rendered subfields. Additionally stores the value
146156
* and raw value of all rendered subfields into $field->subfield_rows.
147157
*
148-
* @param string $context
149-
* @param object $item
150-
* @param \stdClass $field
158+
* @param string $context The context
159+
* @param object $item The item
160+
* @param \stdClass $field The field
151161
*
152-
* @return string
162+
* @return string
153163
*
154164
* @since __DEPLOY_VERSION__
155165
*/
@@ -191,20 +201,25 @@ public function onCustomFieldsPrepareField($context, $item, $field)
191201
{
192202
$rows = array($field->value);
193203
}
204+
194205
// Iterate over each row of the data
195206
foreach ($rows as $row)
196207
{
197208
// The rendered values for this row, indexed by the name of the subfield
198209
$row_values = new \stdClass;
210+
199211
// Holds for all subfields (indexed by their name) for this row their rendered and raw value.
200-
$row_subfields = new \stdClass();
212+
$row_subfields = new \stdClass;
213+
201214
// For each row, iterate over all the subfields
202215
foreach ($this->getSubfieldsFromField($field) as $_subfield)
203216
{
204217
// Clone this virtual subfield to not interfere with the other rows
205218
$subfield = (clone $_subfield);
219+
206220
// Just to be sure, unset this subfields value (and rawvalue)
207221
$subfield->rawvalue = $subfield->value = '';
222+
208223
// If we have data for this field in the current row
209224
if (isset($row[$subfield->name]))
210225
{
@@ -229,7 +244,7 @@ public function onCustomFieldsPrepareField($context, $item, $field)
229244
else
230245
{
231246
// Render this virtual subfield
232-
$subfield->value = \JEventDispatcher::getInstance()->trigger(
247+
$subfield->value = \JEventDispatcher::getInstance()->trigger(
233248
'onCustomFieldsPrepareField',
234249
array($context, $item, $subfield)
235250
);
@@ -243,13 +258,15 @@ public function onCustomFieldsPrepareField($context, $item, $field)
243258

244259
// Store this subfields rendered value into our $row_values object
245260
$row_values->{$subfield->name} = $subfield->value;
261+
246262
// Store the value and rawvalue of this subfield into our $row_subfields object
247-
$row_subfields->{$subfield->name} = new \stdClass();
248-
$row_subfields->{$subfield->name}->value = $subfield->value;
263+
$row_subfields->{$subfield->name} = new \stdClass;
264+
$row_subfields->{$subfield->name}->value = $subfield->value;
249265
$row_subfields->{$subfield->name}->rawvalue = $subfield->rawvalue;
250266
}
251267
// Store all the rendered subfield values of this row
252268
$final_values[] = $row_values;
269+
253270
// Store all the rendered and raw subfield values of this row
254271
$subfield_rows[] = $row_subfields;
255272
}
@@ -272,11 +289,11 @@ public function onCustomFieldsPrepareField($context, $item, $field)
272289
* Returns a DOMElement which is the child of $orig_parent and represents
273290
* the form XML definition for this subform field.
274291
*
275-
* @param \stdClass $field
276-
* @param DOMElement $orig_parent
277-
* @param JForm $form
292+
* @param \stdClass $field The field
293+
* @param DOMElement $orig_parent The original parent element
294+
* @param JForm $form The form
278295
*
279-
* @return \DOMElement
296+
* @return \DOMElement
280297
*
281298
* @since __DEPLOY_VERSION__
282299
*/
@@ -304,6 +321,7 @@ public function onCustomFieldsPrepareDom($field, DOMElement $orig_parent, JForm
304321
$parent_fieldset = $parent_field->appendChild(new DOMElement('form'));
305322
$parent_fieldset->setAttribute('hidden', 'true');
306323
$parent_fieldset->setAttribute('name', ($field->name . '_modal'));
324+
307325
// If this subform should be repeatable, set some attributes on the modal
308326
if ($field_params->get('repeat', '1') == '1')
309327
{
@@ -327,9 +345,9 @@ public function onCustomFieldsPrepareDom($field, DOMElement $orig_parent, JForm
327345
/**
328346
* Returns an array of all options configured for this field.
329347
*
330-
* @param \stdClass $field
348+
* @param \stdClass $field The field
331349
*
332-
* @return \stdClass[]
350+
* @return \stdClass[]
333351
*
334352
* @since __DEPLOY_VERSION__
335353
*/
@@ -350,9 +368,9 @@ protected function getOptionsFromField(\stdClass $field)
350368
/**
351369
* Returns the configured params for a given subform field.
352370
*
353-
* @param \stdClass $field
371+
* @param \stdClass $field The field
354372
*
355-
* @return Joomla\Registry\Registry
373+
* @return \Joomla\Registry\Registry
356374
*
357375
* @since __DEPLOY_VERSION__
358376
*/
@@ -363,15 +381,16 @@ protected function getParamsFromField(\stdClass $field)
363381
{
364382
$params->merge($field->fieldparams);
365383
}
384+
366385
return $params;
367386
}
368387

369388
/**
370389
* Returns an array of all subfields for this subform field.
371390
*
372-
* @param stdClass $field
391+
* @param \stdClass $field The field
373392
*
374-
* @return \stdClass[]
393+
* @return \stdClass[]
375394
*
376395
* @since __DEPLOY_VERSION__
377396
*/
@@ -382,15 +401,15 @@ protected function getSubfieldsFromField(\stdClass $field)
382401
foreach ($this->getOptionsFromField($field) as $option)
383402
{
384403
/* @TODO Better solution to this? */
385-
$subfield = (clone $field);
386-
$subfield->id = null;
387-
$subfield->title = $option->label;
388-
$subfield->name = $option->name;
389-
$subfield->type = $option->type;
390-
$subfield->required = '0';
404+
$subfield = (clone $field);
405+
$subfield->id = null;
406+
$subfield->title = $option->label;
407+
$subfield->name = $option->name;
408+
$subfield->type = $option->type;
409+
$subfield->required = '0';
391410
$subfield->default_value = $option->default_value;
392-
$subfield->label = $option->label;
393-
$subfield->description = $option->description;
411+
$subfield->label = $option->label;
412+
$subfield->description = $option->description;
394413

395414
$result[] = $subfield;
396415
}
@@ -401,8 +420,10 @@ protected function getSubfieldsFromField(\stdClass $field)
401420
/**
402421
* Recursively prefixes the 'name' attribute of $node with $prefix
403422
*
404-
* @param DOMElement $node
405-
* @param string $prefix
423+
* @param \DOMElement $node The node
424+
* @param string $prefix The prefix
425+
*
426+
* @return void
406427
*
407428
* @since __DEPLOY_VERSION__
408429
*/

plugins/fields/subform/tmpl/subform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{
1717
echo '<li>';
1818
$buffer = array();
19-
foreach ((array)$row as $key => $value)
19+
foreach (((array) $row) as $key => $value)
2020
{
2121
$buffer[] = ($key . ': ' . $value);
2222
}

0 commit comments

Comments
 (0)