1

I want to check the admin edit article for the category of the article. Much in the same way fields does.

And if the category is a certain one then don't show the content tab (as I will be using fields instead).

Then I can create custom templates, but it is less confusing for the user.

It needs to change if the category changes so it can't be on initial page load.

2

You might be able to do this with a editor-xtd plugin. Instead of having it create/inject a button it'll inject the javascript that does what you're wanting.

Question: the category select field is part of the content tab so if you have the content tab be hidden (for certain categories) then the user will never be able to change that category from inside the article edit page after changing to one of those categories (or the Publish Status, Access level, etc for that matter). So are you wanting to hide the content tab, or just the editor?

update

Here is a proof of concept of a plugin-xtd that I believe does what you're wanting. You'd need to change the category IDs in in the $cats variable.

cm_hidecontent.xml

<?xml version="1.0" encoding="utf-8"?>
<extension version="3.6" type="plugin" group="editors-xtd" method="upgrade">
    <name>plg_editor-xtd_cm_hidecontent</name>
    <author>Drew G</author>
    <creationDate>Oct 2017</creationDate>
    <copyright>-</copyright>
    <authorEmail>-</authorEmail>
    <authorUrl>-</authorUrl>
    <version>3.6.0</version>
    <description>Proof of concept for hiding the content editor when certain categories are selected.</description>
    <files>
        <filename plugin="cm_hidecontent">cm_hidecontent.php</filename>
    </files>
</extension>

cm_hidecontent.php

<?php
defined('_JEXEC') or die;

/**
 * 
 */
class plgButtonCm_hidecontent extends JPlugin
{

    /**
     * Load the language file on instantiation.
     *
     * @var    boolean
     * @since  3.1
     */
    protected $autoloadLanguage = true;


    /**
     * Inject the needed javascript
     */
    function onDisplay($name, $asset, $author)
    {

        // List which category IDs you want the editor to hide from.
        // You can pull this data from a plugin parameter or leave it hardcoded
        $cats = json_encode(array(1536, 419));

        $js =
<<<EOF

jQuery(function($){

    jQuery('#jform_catid').change(function()
    {
        checkStatus();
    });

    var checkStatus = function()
    {
        // Need to cast the value to a number else Array.includes() will fail
        var val = Number(jQuery('#jform_catid').val());

        // You could hard code this array.
        var cats = {$cats};

        if(cats.includes(val))
        {
            jQuery('#myTabContent .adminform').css('visibility','hidden');
        }
        else
        {
            jQuery('#myTabContent .adminform').css('visibility','visible');
        }
    }

    // Initial pageload check
    checkStatus();

});

EOF;
        $doc = JFactory::getDocument();
        $doc->addScriptDeclaration($js);

    }
}
  • Yes, I noticed that in my testing :) I just want to remove the editor. Which then meant I needed to change the category from span3 to span12. However, although I did manage to get the tab to disappear using if ($this->item->catid == 14): so I'm halfway there. The close button stopped working though. My efforts continue. – Eoin Oct 18 '17 at 15:13
  • 1
    The close button my not work if you hide the editor via display:none or by removing it from DOM (I have a faint memory I had a similar issue one time). I added a proof-of-concept to my answer. Give it a go; it worked for me. – Drew G Oct 18 '17 at 18:42
  • 1
    Go for it! You can give me credit somewhere for the original code if you want and remove the "cm_" from the name (that's a prefix I use for my own extensions) but otherwise have at it. – Drew G Oct 20 '17 at 15:03
  • 1
    I haven't used needed to use any of the "Joomla! Custom Fields" yet but in the documentation https://docs.joomla.org/J3.x:Adding_custom_fields/Editor_Field their editor has the read more link. It may just be an issue of configuration for you. I'd look into that first before attempting to move the content editor or injecting an editor using the pre-Custom Fields method (that I mentioned in my last comment). – Drew G Oct 27 '17 at 13:57
  • 1
    That fatal error seems to indicate that whatever you named the plugin is the same name as another already installed plugin. You should be able to fix it by simply renaming the plugin to something else. – Drew G Oct 30 '17 at 14:36
2

Override the administrator/components/com_content/views/article/edit.php in your admin template, and then, in the overridden file, create a condition to hide the following code if $this->item->catid = '8' (where 8 is the category ID that you want to hide the content table for):

<?php if ($this->item->catid != '8') {
<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'general')); ?>
echo JHtml::_('bootstrap.addTab', 'myTab', 'general', JText::_('COM_CONTENT_ARTICLE_CONTENT')); ?>
<div class="row-fluid">
    <div class="span9">
        <fieldset class="adminform">
            <?php echo $this->form->getInput('articletext'); ?>
        </fieldset>
    </div>
    <div class="span3">
        <?php echo JLayoutHelper::render('joomla.edit.global', $this); ?>
    </div>
</div>
<?php echo JHtml::_('bootstrap.endTab');
} else{
    <?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'images')); ?>
}?>

If you only want to hide the editor (and the whole content tab), then just create the condition around the following code:

<fieldset class="adminform">
    <?php echo $this->form->getInput('articletext'); ?>
</fieldset>
  • Right, this is what I had tried, but the close button stopped working. I only did it around the admin form bit. I also wanted to make the category from span3 to span12 as it didn't need to be so small after that instance. In any case it didn't quite work so I'm going to try Drew G's solution. But thank you for your answer, it's an honour to have ioctopus answer one of my questions! – Eoin Oct 20 '17 at 12:31

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.