0

I'm try to create a system plugin with Joomla 4. Its purpose is adding a new field (pippo) in the article editing form and save its value in the attribs column of the content table.

I used the "onContentPrepareForm" event. The field is displayed correctly in the metadata section of the article but it is not stored into the content table.

This is the function of the plugin:

public function onContentPrepareForm($form, $data)
{
    $doc = $this->app->getDocument();

    if ((!$this->app->isClient('administrator')) && ($doc->getType() != 'html')) return;
    $plg_path = JPATH_ROOT.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'system'.DIRECTORY_SEPARATOR.$this->_name;

    if ((JFactory::getApplication()->input->get('option') == 'com_content') && 
        (JFactory::getApplication()->input->get('view') == 'article') &&
        (JFactory::getApplication()->input->get('layout') == 'edit')) {
        
        FormHelper::addFormPath($plg_path.DIRECTORY_SEPARATOR.'params');
        $form->loadFile('article', false);
    }
}

And this is the XML of the field:

<?xml version="1.0" encoding="utf-8"?>
<form>
    <fields name="attribs">
        <fieldset name="jmetadata" label="PLG_SYSTEM_PIPPO_LABEL_TEXT">
            <field name="pippo" type="text" size="50" label="PLG_SYSTEM_PIPPO_LABEL_TEXT" placeholder="PLG_SYSTEM_PIPPO_PLACEHOLDER"/>
        </fieldset>
    </fields>
</form>

I remember in Joomla 3 this is the way to go. But in Joomla 4... What's wrong?

Thanks in advance

EDIT: SOLVED!

Changed this:

FormHelper::addFormPath($plg_path.DIRECTORY_SEPARATOR.'params');

with this:

Form::addFormPath($plg_path.DIRECTORY_SEPARATOR.'params');

and it works!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.