0

I have the editors-xtd\vimeo plugin with this structure

..\plugins\editors-xtd\vimeo\models\fields\(a bunch of custom fields)
..\plugins\editors-xtd\vimeo\forms\form.xml
..\plugins\editors-xtd\vimeo\forms\extra.xml

In both the .xml files I used

<fieldset addfieldpath="/plugins/editors-xtd/vimeo/models/fields">

All working perfect in Joomla 3.9.5+ but I don't know how to set the addfieldprefix in Joomla 4, already tried (according to the JAB presentation) to

<fieldset name="vimeo-options" addfieldprefix="Plugin\EditorsXtd\Vimeo">

In a previous question, I found out how to use com_ajax to set a custom layout for the plugin, here is how I load the .xml files in my layout

..\plugins\editors-xtd\vimeo\tmpl\default.php

via

Form::addFormPath(JPATH_ROOT.'/plugins/editors-xtd/vimeo/forms/');
$form = Form::getInstance('form',JPATH_ROOT.'/plugins/editors-xtd/vimeo/forms/form.xml');
$form->addFieldPath(JPATH_ROOT.'/plugins/editors-xtd/vimeo/models/fields/');
$form->loadFile('extra',false,false);

The pop-up content is empty, no fields loaded from extra.xml.

Thanks for any input/suggestion.

  • Above you define the Form like this: $form = Form::getInstance('form',JPATH_ROOT.'/plugins/editors-xtd/vimeo/forms/form.xml'); but you want to load extra.xml, then the path is not correct. – Zollie May 18 at 8:02
  • I also do not think that you need to use field prefix. The fieldset should be like: <fieldset name="vimeo-options" label="PLG_SOMETHING_SOMETHING" addfieldpath="plugins/editors-xtd/vimeo/models/fields"> - these two things I can see suddenly... – Zollie May 18 at 8:04
  • Neither addfieldpath="something" or addfieldprefix="something" works. – thednp May 18 at 8:35
  • Update: the form is loaded with $form->addFieldPath(JPATH_ROOT.'/plugins/editors-xtd/vimeo/models/fields/'); and removed addfieldpath attribute for the fieldsets in the .xml files, but I didn't actually see anything until I inspected the source. The form is there, just for some reason getting a value of some field via $form->getField('fieldName') breaks everything. – thednp May 18 at 9:10
  • I mean a var_dump($form) right after loading the .xml files gets the form into the page. – thednp May 18 at 9:27
1

To implement Joomla standard namespacing in a plugin, follow these steps:

First, declare extension's namespace in manifest file:

<namespace>Joomla\Plugin\EditorsXtd\Vimeo</namespace>

If you are editing files on site, you need to delete libraries/autoload_ps4.php file so it can regenerated. If you update the plugin using extension manager, this should be done automatically.

Fields must be placed in plugin's Field directory. So move the contents of plugins/editors-xtd/vimeo/models/fields to plugins/editors-xtd/vimeo/Field.

Field classes and filenames consist of field type and Field suffix. Field type must start with an uppercase and is case sensitive. The filename would be plugins/editors-xtd/vimeo/Field/ExampleField.php and the class name ExampleField. $type property should not contain suffix. You must also add namespace delcaration. An example of field looks like this:

namespace Joomla\Plugin\EditorsXtd\Vimeo\Field;

defined('JPATH_BASE') or die;

use Joomla\CMS\Form\Field\ListField;

class ExampleField extends ListField
{
    protected $type = 'Example';
}

To register fields use addfieldprefix="Joomla\Plugin\EditorsXtd\Vimeo\Field in form.

In form field type should not have a suffix:

<field
    name="whatever"
    type="Example"
/>

If you use camelcase for files/classes, the type in form must be case correctly, e.g. if filename is MyExampleField, the type in form should be MyExample because Myexample or myexample will not be detected.

  • Thanks, and sorry to bother you. What about the plugin class declaration itself please? EditorsXtdVimeoPlugin extends CMSPlugin is that correct? – thednp May 18 at 18:35
  • 1
    Plugin class should remain as PlgEditorsXtdVimeo for now. – Sharky May 18 at 19:17
  • Omg this really worked, thank you so much, – thednp May 18 at 20:34
  • 1
    It's only in 4.0. – Sharky May 18 at 21:58
  • 1
    Yes, this does not work in 3.9. It might work in 3.10 if related code is backported from 4.0 (3.10 should receive some 4.0 compatibility features). Otherwise in 3.x you need another plugin for registering the namespace using JLoader::registerNamespace(). – Sharky May 20 at 6:53

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.