0

I'm looking to display my system plugin options in a custom layout.
So i checked something like options for article blog layout:

enter image description here

But these use a custom layout that renders the options with a form-grid class:

<div class="form-grid">
     <?php echo $this->form->renderFieldset('editorConfig'); ?>
</div>

The rendered fields have attributes like this: parentclass="stack span-1". They work in combinations with the grid class from the layout.

Is there a way to get a custom layout for system plugin options rendered? I can use the parentclass option for single fields but how would one use an options layout override at this place?

2 Answers 2

0

Yes, you can use a administrator template override to change the presentation of the form which captures plugin options.

When you're editing plugin options you have a URL like .../administrator/index.php?option=com_plugins&view=plugin&layout=edit&extension_id=... and this provides an indication of which file is outputting the html:

  • administrator
  • component = com_plugins
  • view = plugin
  • layout = edit

So the file is in administrator/components/com_plugins/tmpl/plugin/edit.php.

You can create an override of this by going via System / Administrator Templates and clicking on Atum Details and Files (or whatever admin template you're using), and then Create Overrides tab, Components / com_plugins/plugin.

You can then edit this edit.php file by going to the Editor tab and expanding down the html folder below /administrator/templates/atum.

If you're just changing the presentation using CSS then you can easily just insert a class into the enclosing <div> of the form, and that will allow you to address elements within the form.

If you're looking to perform more structural changes then you may need to change one of the layouts used within the form. For example the line

<?php echo LayoutHelper::render('joomla.edit.global', $this); ?>

outputs the Status, Access, Ordering, ... parameters on the right hand side. So to change this you'd have to create an override of that layout as well. However, that layout is used multiple times in joomla, so to apply changes to it for just the plugins form you could copy the override file (administrator/templates/atum/html/layouts/joomla/edit/global.php) into another file myglobal.php in the same directory. Then you can change your line in the edit.php file to:

<?php echo LayoutHelper::render('joomla.edit.myglobal', $this); ?>

I wasn't sure from your question whether you wanted to change the options presentation of all plugins, or of all plugins of type="system", or of just your own system plugin which you wrote. If you use a debugger and break at a point in your override edit.php file then you can see that the plugin data is available via $this->item, and you can use the fields of this variable to control how the html output is changed, eg

  • $this->item->type should be set to "plugin"
  • $this->item->folder folder where the plugin is found, equating to the type of the plugin
  • $this->item->name name of the plugin
2
  • Doing a backend template override is kind of shooting at sparrows with cannons. And it is a plugin which can be installed, so no manual operations for creating an override are possible. The best solution would be if the plugin options layout could be influenced via the plugin xml file and a layout file instaled with the plugin.
    – maidan
    Jul 5, 2023 at 16:40
  • Can you do what you want to do with CSS? If so, I would have thought you could capture eg onContentPrepareForm event, check if it's the plugin edit form and if it's your plugin, and then set some class attribute on an element of the form that you could use in the CSS (which you could add via the web asset manager). Jul 5, 2023 at 20:24
0

You can define classes on <fieldset> elements in your XML but that's about it. The rest is part of the layout and can't be altered by form definition. You can use layout overrides to change the output completely. Since 4.0 there is onBeforeDisplay event which exposes the view to plugins. This way you can use Joomla\CMS\MVC\View\HtmlView::addTemplatePath() to add a custom layout path, i.e. for loading the layout from your plugin directory. The disadvantage of this is that you have to maintain the entire view layout (edit.php).

public function onBeforeDisplay(Joomla\CMS\Event\View\DisplayEvent $event)
{
    // Check that it's the plugin view.
    if ($event->getArgument('extension') !== 'com_plugins.plugin')
    {
        return;
    }
    
    // Get the view.
    $view = $event->getArgument('subject');

    // Check that it's a HTML view
    if (!$view instanceof Joomla\CMS\MVC\View\HtmlView)
    {
        return;
    }

    // Get the form.
    $form = $view->getForm();

    // Check that we have a valid form.
    if (!$form instanceof Joomla\CMS\Form\Form)
    {
        return;
    }

    // Check that our plugin is being edited.
    if ($form->getValue('element') !== 'example' || $form->getValue('folder') !== 'content')
    {
        return;
    }

    // Add layout lookup path.
    $view->addTemplatePath(JPATH_PLUGINS . '/content/example/tmpl');
}
1
  • OK. Thanks. Thats seams to be the only reasonable solution.
    – maidan
    Jul 26, 2023 at 11:50

Your Answer

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

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