1

I'm trying to create a simple plugin that adds 4 textfields to the article options. But I'm not getting it to work.

This is my plugin structure:

extrafields.xml extrafields.php

These are the contents of the files:

extrafields.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.1" type="plugin" group="content" method="upgrade">
    <name>plg_content_extrafields</name>
    <version>3.6.5</version>
    <description>Extra fields voor articles</description>
    <files>
        <filename plugin="article">extrafields.php</filename>
    </files>
    <config>

    </config>
</extension>

extrafields.php

<?php
// no direct access
defined( '_JEXEC' ) or die;

class plgContentExtrafields extends JPlugin
{
    /**
     * Load the language file on instantiation. Note this is only available in Joomla 3.1 and higher.
     * If you want to support 3.0 series you must override the constructor
     *
     * @var    boolean
     * @since  3.1
     */
    protected $autoloadLanguage = true;

    /**
     * Plugin method with the same name as the event will be called automatically.
     */
    function onContentPrepareForm($form, $data)
    {
        $app    = JFactory::getApplication();
        $option = $app->input->get('option');

        switch($option)
        {
            case 'com_content' :
                if ($app->isAdmin())
                {
                    JForm::addFormPath(__DIR__ . '/forms');
                    $form->loadFile('extrafields', false);
                }
                return true;
        }

        return true;
    }
}
?>

Now I can install it succesfully but when I try to access the plugin it says "article.xml not found" And when I access the articles I don't see any extra fields or tabs or anything. The current documentation for adding fields are limited to contacts and it doesn't really translate well to the article component. Could someone help me out?

  • 1
    One point is that you haven't defined the folder containing the XML file of the extra form fields in your manifest eg: <folder plugin="article">extrafields</folder>. This tutorial might help. – Farahmand Jan 27 '17 at 12:32
  • The problem is is that is not a Joomla 3.0 documentation. It's 2.5. There doesn't seem to be a 3.0 documentation. – Huub S Jan 27 '17 at 13:17
1

There were a couple of errors. Like Farahmand already saw, the folder wasn't specified in the installation XML.

Also I made a couple of errors in the extrafields.php file:

switch($option)
        {
            case 'com_content' :
                if ($app->isAdmin())
                {
                    JForm::addFormPath(__DIR__ . '/extrafields');
                    $form->loadFile('extrafields', false);
                }
                return true;
        }

Needed to change the rating into the extafields map.

1

Expert Custom field is the easiest option for this, It is free to download and we can easily add custom field to article.

One more thing Joomla 3.7 will also comes with this feature as a core feature and functionality for adding custom field.

  • Yeah I know. I got it working with a small plugin, I don't need the extra bloat. Yeah I saw that, unfortunately, the final build will be released in March, and this website needs to be finished in January. – Huub S Jan 29 '17 at 16:21

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.