1

Is there a way, to load with an XML element, the custom fields, from the Joomla component, com_fields in the backend of a module? I know how to take them from the default.php and display them, but I was wondering if there is a way to load them in the backend of a module administration and then reproduce them like a repeatable field? Thank you in advance!

4
  • Welcome to JSE. Please take our tour. – mickmackusa Feb 16 at 23:07
  • Short answer is no. Slightly longer answer is why would you want that? Or put another way: why would a subform in the module's xml config not be sufficient? – jamesgarrett Feb 17 at 23:04
  • Hello and thank you for your answer. I am developing a module and I want to store besides the repeatable fields values, informations like when the field was created or edited and by whom. So I thought that by creating a custom field and by the time is stored in the database I could acces thise kind of informations. – leno1232 Feb 17 at 23:57
  • Sounds like you need a component – jamesgarrett Feb 18 at 22:45
1

You can do this with a content plugin quite easily. See this guide for starters.

You create the XML in your plugin form/modwhatever.xml. Now you can add whatever fields you wish - you might want to look at the articles form for examples of user, publishing dates etc, which can be located in administrator/components/com_content/models/forms/article.xml.

Your plugin would implement a method like so:

    public function onContentPrepareForm($form, $data)
    {

        $app = JFactory::getApplication();
        $option = $app->input->get('option');

        switch ($option) {

            case 'mod_whatever':

                if ($app->isAdmin()) {

                    JForm::addFormPath(__DIR__ . '/forms');

                    $form->loadFile('modwhatever', false);

                }

                return true;

        }

        return true;

    }

To ensure you don't need to apply any further changes, you can use the attribs form as a basis so that your new fields are available on the modules params, e.g.:

<?xml version="1.0" encoding="UTF-8"?>
<form>
  <fields name="attribs">
     <fieldset name="customstuff" label="Custom Stuff">
        <field 
            name="created_by" 
            type="user"
            label="COM_CONTENT_FIELD_CREATED_BY_LABEL" 
            description="COM_CONTENT_FIELD_CREATED_BY_DESC" 
        />

        <field 
            name="created_by_alias" 
            type="text"
            label="COM_CONTENT_FIELD_CREATED_BY_ALIAS_LABEL" 
            description="COM_CONTENT_FIELD_CREATED_BY_ALIAS_DESC"
            size="20" 
        />
     </fieldset>
  </fields>
</form>

4
  • thank you Grant G . I implemented with simple repeatable fields. But I have another question. Where are the repeatable field values stored in the database? – leno1232 Feb 24 at 0:08
  • @leno1232 I answered on your other question. Depending on how you added the fields, it is entirely possible that they are not saved to the database. For instance, if your XML sets a name <fields name="doesnotalreadyexist">, then it will not save. – Grant G Feb 24 at 0:25
  • thank you for answering my questions! I am grateful! – leno1232 Feb 24 at 0:44
  • @len Please take our tour and then please read: meta.stackexchange.com/a/5235/352329 – mickmackusa Feb 24 at 2:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.