Skip to content

Commit

Permalink
After merge with PR joomla#17552 we can now successfully show the sub…
Browse files Browse the repository at this point in the history
…forms options for the different types.
  • Loading branch information
Rene Pasing committed Nov 7, 2017
1 parent 24082ef commit 306d316
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions plugins/fields/subform/subform.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,22 @@ public function onContentPrepareForm(JForm $form, $data)
{
return;
}

// Ensure it is an object
$formData = (object) $data;

// Gather the type
$type = $form->getValue('type');
if (!empty($formData->type))
{
$type = $formData->type;
}

// Load our own form definition
$xml = new DOMDocument();
$xml->load($path);

// Get the options subform
$xmlxpath = new DOMXPath($xml);
$hiddenform = $xmlxpath->evaluate(
'/form/fields[@name="fieldparams"]/fieldset[@name="fieldparams"]/field[@name="options"]/form'
Expand Down Expand Up @@ -79,7 +91,7 @@ public function onContentPrepareForm(JForm $form, $data)
for ($i = 0; $i < $fields->length; $i++)
{
$field = $fields->item($i);
/* @var $field DOMNode */
/* @var $field \DOMElement */

// Rewrite this fields name, e.g. rewrite name=='buttons' for
// the editor fieldtype to '_type-editor_buttons'
Expand All @@ -88,8 +100,8 @@ public function onContentPrepareForm(JForm $form, $data)
('_type-' . $fieldType['type'] . '_')
);

// And set it to hidden
//$field['hidden'] = 'true';
// Only show this field when the field 'type' is of the specific type
$field->setAttribute('showon', 'type:' . $fieldType['type']);

// Import the rewritten field into our parent form
$hiddenform->appendChild($xml->importNode($field, true));
Expand Down

0 comments on commit 306d316

Please sign in to comment.