In one of my previous questions, I learned how to properly set up a namespaced custom form field, but it turns out that it's only available within its plugin scope for some reason.

I need the field defined in plugins/editorsxtd/vimeo/Field/VimeoOptionsField.php to use its class in plugins/content/vimeo/vimeo.php -- also a namespaced extension now.

// namespace Joomla\Plugin\Content;

defined('JPATH_BASE') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Plugin\EditorsXtd\Vimeo\Field\VimeoOptionsField;

class PlgContentVimeo extends CMSPlugin
  protected $autoloadLanguage = true;
  public static $options = array();

  function __construct(&$a, $b)
      // returns an array with options
      static::$options = Joomla\Plugin\EditorsXtd\Vimeo\Field\VimeoOptionsField::getOptionsList();
  public function onContentPrepare($context, &$article, &$params, $page = 0){
    // do the magic with static::$options

This setup throws this error:

Class 'Joomla\Plugin\EditorsXtd\Vimeo\Field\VimeoOptionsField' not found site\plugins\content\vimeo\vimeo.php:31


The use Joomla\Plugin\EditorsXtd\Vimeo\Field\VimeoOptionsField; declaration doesn't load the class into my plugin. I also tried JLoader:

JLoader::registerNamespace('Joomla\Plugin\EditorsXtd\Vimeo\Field\VimeoOptionsField', JPATH_PLUGINS.'/editors-xtd/vimeo/Field/VimeoOptionsField.php');

But this is not working either.


Does JLoader::('NAMESPACE','PATH_TO_FIELD') need anything else? or what exactly do I need to call to access the methods in the plugins/content/vimeo/vimeo.php class shown here?

UPDATE 2: After a close inspection, comparing code from Joomla 3.9 and Joomla 4, I came to the realization that Joomla 3.9. still uses old JFormFieldFieldname class, no namespace so that explains why it's not working in Joomla 3, not yet, perhaps with v3.9.10.

  • Which version of Joomla are you using?
    – Sharky
    May 20 '19 at 6:54
  • I want to make extensions to work with both Joomla versions. I have to make use of something like !class_exists -> New_class extend OLD_Class.
    – thednp
    May 20 '19 at 6:57
  • Just FYI: on Joomla 4 it works, but only inside the plugin scope, not outside, in something like another plugin or template. I would like to know how to make that work at least so I can prepare my extensions roadmap accordingly.
    – thednp
    May 20 '19 at 6:58
  • I will post another question regarding reusing these namespaced custom form fields in other plugins or extensions.
    – thednp
    May 20 '19 at 9:49

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.