Page 1 of 1

Hide Backend Articles?

Posted: Sat Jul 07, 2012 10:00 pm
by ahuppert
I am new to ACL, but I think I get the concept. I have a group of editors that only need access to specific articles. I DO NOT want them even seeing that there are other articles that can be edited.

I created a new user group under Public>Manager and removed some of the permissions (like create, own, etc).

I then went into my categories and assigned that group ONLY to be able to edit the articles in the Category that I want them to.

This works completely fine, EXCEPT that I have over 100 articles. The user can see ALL OF THEM, but they are grayed out and they can only edit the ones that they are assigned to.

My question is, can I hide all of the other article titles from this user? If so, how do you do it?

Re: Hide Backend Articles?

Posted: Sun Jul 08, 2012 1:27 pm
by rcarey
I have a quick solution, but it requires you to add a line of code...

Focus on the file that displays the list of articles. The file includes logic for knowing whether or not the user has rights to edit the article. We will re-use that logic, and when we find an article that the user is unable to edit, we'll just skip that record and not display it. Here is how.

You should override the file that displays the list of article to be edited.
Copy this file: /administrator/components/com_content/views/articles/tmpl/default.php
Paste the copy here: /administrator/<admin-template>/html/com_content/articles/default.php

Now edit the copied file (which now overrides the original file). Around line 117 is a foreach statement, and around line 121 is the creation of the variagle $canEdit. This variable is true if the user can edit the article, otherwise false.

Somewhere around or shortly after line 125 (just after several variable are created) add this line of php code:

Code: Select all

That is it. What this does: If the user can't edit this article, don't process any more of this item and continue with the next item in the "foreach" loop.

Re: Hide Backend Articles?

Posted: Tue Jul 10, 2012 3:24 pm
by keithriches
Hi i have found this post and its just what I was looking for but im not sure i follow whats happening? I can find the file:

I can see roughly the bits youre talking about but im not sure what this path means?
Paste the copy here: /administrator/<admin-template>/html/com_content/articles/default.php

Any help would be greatly received!

Re: Hide Backend Articles?

Posted: Tue Jul 10, 2012 3:28 pm
by keithriches

I have added some code which seems to do the job but im not sure how safe this is?
<?php foreach ($this->items as $i => $item) :
$item->max_ordering = 0; //??
$ordering = ($listOrder == 'a.ordering');
$canCreate = $user->authorise('core.create', 'com_content.category.'.$item->catid);
$canEdit = $user->authorise('core.edit', 'com_content.article.'.$item->id);
$canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $userId || $item->checked_out == 0;
$canEditOwn = $user->authorise('core.edit.own', 'com_content.article.'.$item->id) && $item->created_by == $userId;
$canChange = $user->authorise('core.edit.state', 'com_content.article.'.$item->id) && $canCheckin;
<?php if(!$canEdit){continue;}; ?>
<tr class="row<?php echo $i % 2; ?>">
<td class="center">
<?php echo JHtml::_('', $i, $item->id); ?>
<?php if ($item->checked_out) : ?>
<?php echo JHtml::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'articles.', $canCheckin); ?>
<?php endif; ?>
<?php if ($canEdit || $canEditOwn) : ?>
<a href="<?php echo JRoute::_('index.php?option=com_content&task=article.edit&id='.$item->id);?>">
<?php echo $this->escape($item->title); ?></a>
<?php else : ?>
<?php echo $this->escape($item->title); ?>
<?php endif; ?>
<p class="smallsub">
<?php echo JText::sprintf('JGLOBAL_LIST_ALIAS', $this->escape($item->alias));?></p>

Would this be ok to use do you know?

Re: Hide Backend Articles?

Posted: Tue Jul 10, 2012 4:34 pm
by rcarey
The path i listed refers to the path for overriding a "view" file. When I listed <admin-template> I meant for you to use the directory for whatever admin template you are using.

for instance, if you are using blueStork for your admin template, you will find this directory
this is the folder in which "overrides" are placed, so from this path...
...create the remaining directories and add the copied file:

This copied file is now used by Joomla instead of the file found under the component. This pattern is used for overriding files, and in a way so that an upgrade in the component will not overwrite your changes - because your changes should be in the override file.

If the only code change you made is the line I supplied, then the change I'm seeing appears fine. That extra line of code is placed at the same place I put it when I need something like this.

Of course, test a bit whenever you make a code change.

Let me add, if you make this change to the overriding file and leave the original as is... then in case you make a mistake and can't back out easily, you just rename or move the overriding file and the original is used again. This can be very helpful as you make code changes and test them.

One small detail to point out... You don't need the semicolon after the curly bracket - keep just the semicolon inside the brackets.

Re: Hide Backend Articles?

Posted: Tue Jul 10, 2012 9:05 pm
by ahuppert
I added the code here:

Code: Select all

		<?php foreach ($this->items as $i => $item) :
			$item->max_ordering = 0; //??
			$ordering	= ($listOrder == 'a.ordering');
			$canCreate	= $user->authorise('core.create',		'com_content.category.'.$item->catid);
			$canEdit	= $user->authorise('core.edit',			'com_content.article.'.$item->id);
			$canCheckin	= $user->authorise('core.manage',		'com_checkin') || $item->checked_out == $userId || $item->checked_out == 0;
			$canEditOwn	= $user->authorise('core.edit.own',		'com_content.article.'.$item->id) && $item->created_by == $userId;
			$canChange	= $user->authorise('core.edit.state',	'com_content.article.'.$item->id) && $canCheckin;

and it DOES in fact work. HOWEVER, is there now a way to make the default DISPLAY # (for this user) "ALL"?

I'm asking because I have 10+ pages of articles, when it is set to 20/page. With the code addition, when the person views articles, they are shown a blank page of articles unless they select DISPLAY ALL so that the 5-10 articles in the category (that they are allowed to edit) finally show up.

If that is not selected, then they have to either navigate the Display Category drop down, or select ALL to show all of the articles. To do this every time would be annoying and probably too much for a novice user.

I would love to allow them to do this from the front end, but the editing capabilities in the back end are so much cleaner and it adds a level of separation from the front end.

Re: Hide Backend Articles?

Posted: Tue Jul 10, 2012 9:22 pm
by rcarey
I am aware that this technique strips out items after the pagination is calculated - leading to the possibility of sparse-to-empty screens. But to limit the custom coding to a file you can override, this seems to be the best option. (and relatively simple to implement)

As to extending the default number of items to display, go to GlobalConfiguration->Site and you will find a field to default list limit. The highest it goes it 100, and setting this to 100 or whatever will apply this list limit to every list within the site. There might be a plugin (written or waiting to be written) that can initially set the list limit to All, but I don't know.

Re: Hide Backend Articles?

Posted: Tue Jul 10, 2012 9:30 pm
by ahuppert
Thanks for the help! It worked... I'll just have to write a more detailed HOWTO for the users...

Re: Hide Backend Articles?

Posted: Wed Jul 11, 2012 8:25 am
by keithriches

Thanks for your response rcarey. I have looked on the server and found the directory but when i go into:


I can only see 3 files:


Would i need to create a folder to get to the path:


Many thanks for your assistance on this

Re: Hide Backend Articles?

Posted: Wed Jul 11, 2012 12:18 pm
by rcarey
Yes. You need to create those additional directories. The "html" directory is the starting place for all overrides. Each override must be placed in additional directories that instruct the template for which component or module (and for which view) the overriding file applies. If any part of the new path (misspelled or missing folder/file) does not meet the expected naming convention, then that file will not override the corresponding "view" file from the component or module.

The overriding technique is a very important aspect of Joomla, in my opinion. It is part of the MVC model that sets Joomla apart from most of the other open source CMSs (e.g., WP, Drupal). More commonly, it is used to override the view or formatting of the frontend, but it can be very powerful in tailoring the backend that we deliver to our clients.

A discussion of overriding components and modules is found in this Joomla documentation:

Re: Hide Backend Articles?

Posted: Tue Jan 14, 2014 3:40 am
by numinousmedia
Thank you for posting this solution rcarey. I used it to apply the same "Hide Articles" fix to a Joomla 3.2.1 site.

Re: Hide Backend Articles?

Posted: Tue Sep 01, 2015 4:23 am
by shawnhy
Thanks for the amazing code, rcarey.
I apply the code on joomla!3.4.3 and make unauthorized items hidden. However, the td tag remains and result to the result of ugly table.


Is there any way I can fix it?
Many thanks.

Re: Hide Backend Articles?

Posted: Tue Sep 01, 2015 4:42 am
by shawnhy
well. I fix if by add a

Code: Select all

style="<?php if(!$canEdit){ echo 'display: none';} ?>"
into to tr tag.

Re: Hide Backend Articles?

Posted: Tue Sep 01, 2015 4:49 am
by rcarey
@Shawnhy. You just posted as I was answering. I would expect your code to work. But I think it is better to add the code that I suggested. If I saw the page gerneated by your code, I would be able to look at the source code to see the values you intended to hide.

I assume the problem is that you placed the continue; statement too late in the code - i.e., after the <tr> so that a table row is added each time. I looked at the template file in the latest version (3.4.3), and one could place this conditional line right after line 110. And becasue the condition needs to know only the value of $canEdit, then you could place that added line of code right after the value of $canEdit is set. In other words, place it right after line 107 or this statement:

Code: Select all

$canEdit    = $user->authorise('core.edit',       'com_content.article.' . $item->id);

Re: Hide Backend Articles?

Posted: Thu Jul 14, 2016 8:34 pm
by ryank1
this is great! is there a way to add it to a template so it does not get overwritten on updates?

Re: Hide Backend Articles?

Posted: Thu Jul 14, 2016 9:45 pm
by rcarey
The changes should be made to an overriding file - one that is not overwritten on upgrades. That is a common practice in Joomla. Please read earlier in this discussion to learn more about that.

Re: Hide Backend Articles?

Posted: Fri Jul 15, 2016 1:02 pm
by ryank1
Hey @ahuppert I did read through the comments and thought maybe since the post was so old joomla core changed a bit. I do normally work with html overides but for some reason this one wasnt working. see my screen shot of my overided in the isis theme.
Screen Shot 2016-07-15 at 7.54.19 AM.png