0

I am currently creating a custom field plugin for Joomla! I am now faced with the task / problem that the user needs more than just one field when adding the information. In detail it is so that it is a map plugin and the user can enter the coordinates in a field and set the label and the description (field type text & textarea) for the marker popup. So my plugin should not only be able to output one field type text in the backend but two text fields and a textarea.

I already tried to generate the fields and return them comma-separated or in an array (hoping this application scenario exists) which unfortunately failed.

most of the work for this plugin is done but is there a way to have multiple fields rendered? i know it is a custom field plugin not a custom fields plugin, but maybe...

class PlgFieldsPluginName extends FieldsPlugin{
protected $hint = '46.856112,9.517915';

public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form)
{
    $coordsField = parent::onCustomFieldsPrepareDom($field, $parent, $form);
    if (!$coordsField)
    {
        return $coordsField;
    };

    $coordsField->setAttribute('hint', $this->hint);
    $coordsField->setAttribute('description', JText::_('NX_BINGMP_VALUE_DESC'));
    

    return $coordsField;
}
}

As a completion: I am talking effectively about the area when you enter data in an article field. Not about the plugin parameters or the field parameters that are solved via XML.

UPDATE: As mentioned in the comments I tried to extend the Subbform Field. Unfortunately this leads to the following error:

     0 Class 'JFormFieldSubform' not found 

Code adjusted as follows:

protected $hint = '46.856112,9.517915';

public function onCustomFieldsPrepareDom($field, DOMElement $parent, JForm $form)
{
    $coordsField = parent::onCustomFieldsPrepareDom($field, $parent, $form);
    if (!$coordsField)
    {
        return $coordsField;
    };

    $coordsField->setAttribute('repeatable', 'false');
    $coordsField->setAttribute('formsource', '/plugins/fields/pluginname/fields/config.xml');
    $coordsField->setAttribute('description', JText::_('NX_BINGMP_VALUE_DESC'));


    return $coordsField;
}

$coordsField should now be of type subform...

My pluginname.php in fields folder looks like this:

class JFormFieldPluginname extends JFormFieldSubform
{
public $type = 'pluginname';
}

So after some research I found this thread that confirmed my half-knowledge - There is no Subform Field as a Custom Field in Joomla 3:

Github

3
  • Have you tried using Subform?
    – Sharky
    Oct 15, 2020 at 15:48
  • subform? is it available in j3.x?
    – Marco
    Oct 15, 2020 at 16:04
  • 1
    It is available. Inspect the code of Fields - Repeatable plugin, it already uses Subform for a similar purpose.
    – Sharky
    Oct 15, 2020 at 20:16

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.