1

I created a plugin to add a custom field following this answer. Works fine when I am logged in the backend and edit the article but the tab is not displaying when the article is being edited from the front. Am I missing something here or do I have to do it like the docs mention here

Plugin XML:

<?xml version="1.0" encoding="UTF-8"?>
<form>
    <fields name="attribs" >
        <fieldset name="custom" >
            <field name="full_article_image_overlay"
                type="editor"
                filter="safehtml"
                buttons="true"
                label="PLG_FULL_ARTILCE_IMAGE_TEXT"
                />
        </fieldset>
    </fields>
</form>

Plugin PHP:

function onContentPrepareForm($form, $data) {

        $app = JFactory::getApplication();
        $option = $app->input->get('option');

        switch($option) {

            case 'com_content':
                if ($app->isAdmin()) {
                        JForm::addFormPath(__DIR__ . '/forms');
                        //Show specific forms based on categories
                        $form->loadFile('content', false);
                }
                return true;

        }

        return true;
    }
}

Stored Data in 'attribs' column

{
  "show_title": "",
  "link_titles": "",
  "show_tags": "",
  "show_intro": "",
  "info_block_position": "",
  "show_category": "",
  "link_category": "",
  "show_parent_category": "",
  "link_parent_category": "",
  "show_author": "",
  "link_author": "",
  "show_create_date": "",
  "show_modify_date": "",
  "show_publish_date": "",
  "show_item_navigation": "",
  "show_icons": "",
  "show_print_icon": "",
  "show_email_icon": "",
  "show_vote": "",
  "show_hits": "",
  "show_noauth": "",
  "urls_position": "",
  "alternative_readmore": "",
  "article_layout": "",
  "show_publishing_options": "",
  "show_article_options": "",
  "show_urls_images_backend": "",
  "show_urls_images_frontend": "",
  "full_article_image_overlay": "<p>Test Test<\/p>"
}
2

In front article edit form there are only selected fields added. If you want to add something there you will have to use Template Overrides to edit this file: /components/com_content/views/form/tmpl/edit.php. This component for now does not load custom form fields automatically like com_content does.

Adding field in form.php layout of article view

If you have your data stored in attribs field (params fieldset in form) something like this should work:

<?php echo $this->form->renderField('YOUR_FIEL_DNAME', 'params'); ?>

Adding field field into article form object by plugin

To add custom field to Article Form you can use this tutorial: https://docs.joomla.org/Adding_custom_fields_to_core_components_using_a_plugin But remember that you still have to add proper field in the view.

  • Thanks for that but I can't seem to find the 'attribs' in the JForm Object and since the extra field I have is stored in the 'attribs' column, would I need some more code unlike the backend where I simply created the field? Any pointers would be great. Thanks. – sifu Jul 17 '15 at 10:58
  • I updated the answer. – Artur Stępień Jul 17 '15 at 15:30
  • Tried doing this: <?php echo $this->form->renderField('full_article_image_overlay', 'params'; ?> Edit: Sorry added that by mistake as I hit enter before completing. But the above code return empty when var_dumped. Attaching the plugin code now. – sifu Jul 17 '15 at 16:03
  • I don't understand. Why did you added this JSON after? Also it would be good for you to add your plugin code and form XML code into question. – Artur Stępień Jul 17 '15 at 16:05
  • Updated the question with relevant code. – sifu Jul 17 '15 at 16:12

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.