2

I've created a plugin and added a couple of custom fields to its backend. For that I followed the indications from the Joomla docs. I extended for example JFormFieldList to get a dropdown list of options.

My fields work fine if the plugin is enabled. But when the plugin is disabled, the list is not rendered. I get just a basic text box.

Same problem with another custom field that should display a button. The button appears if the plugin is enabled but if it’s disabled, I get the same basic text box instead.

I assume therefore that the problem is that the php of the custom fields is not run when the plugin is disabled. Is there a way around that?

EDIT: here’s one of my custom fields

<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
jimport('joomla.form.formfield');
class JFormFieldZotcslLocales extends JFormFieldList
{
    protected $type = 'ZotcslLocales';

    public function getOptions() {
        $path = JPATH_ROOT.'/media/plg_zotbib/locales/*.xml';
        foreach(glob($path) as $file){
            $name = basename($file, '.xml');
            $name = str_replace('locales-', '', $name);
            $locales[$name] = $name;
        }
        return $locales;
    }
}
?>   

And here’s how it’s included in the manifest file

<field name="locale" type="zotcsllocales"
    description="PLG_ZOTBIB_LOCALE_DESC"
    label="PLG_ZOTBIB_LOCALE_LABEL"
    required="true"
    />
2
  • Where did you include the field definition? And where do you want to show it? In a custom module or component?
    – pixx
    Apr 18, 2018 at 7:46
  • The field is shown in the plugin’s backend. It does appear there but my php code is only run when the plugin is published. When not published the fied still appears but as a simple text entry.
    – Victor
    Apr 23, 2018 at 7:06

2 Answers 2

1

The problem was solved by adding a property addfieldpath to the <config> tag of the xml manifest:

<config addfieldpath="/plugins/content/zotbib/fields">

Without this, the custom fields in the backend were only displayed when the plugin was published. When unpublished the corresponding code was not actually run. With this property set the code of the custom fields is always run and they are displayed correctly even if the plugin is unpublished.

The code of my plugin can be seen here: https://framagit.org/svictor/j3-zotbib

0

@Victor: Obviously, it does not show up since the field definition is part of the plugin, a quick & dirty workaround would be to create a plugin or such wich only serves to show the field type (an empty plugin wich contains the field definition, and since it does nothing else, you can publish it without having other issues). The clean workaround would be to create a field type for each content-type (module, component ecc.) with a different name (since they can be enabled / disabled and a plugin / module / component may not be available in some other parts of the site where you need the field-type)

2
  • sorry, I don’t understand the solution you propose. If I put a field of the standard type list in the plugin’s manifest, it shows up correctly in the backend. It works whether the plugin is published or not. If I now extend the list type, to make a custom field, the field behaves differently: it appears as a list when the plugin is published (correct) and as a mere text box when the plugin is unpublished (incorrect). I don’t understand how I could solve this with an additional plugin.
    – Victor
    Apr 26, 2018 at 13:41
  • Can you share your plugin code?
    – pixx
    Apr 27, 2018 at 14:43

Your Answer

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

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