Hide From menu in Aticles

Hi there!

Articles doesn’t haev a ‘hide from menu’ checkbo, which is tricky when youw ant a client to check the article before posting it live.

I found an old snippet written by Bob Ray (Thanks as ever Bob!) which allows the admin to use a checkbox TV to hide the article from menus using this snippet:

if($resource->get('class_key') == 'Article') {

   if ($resource->getTVValue('HideMenu')) {
  $resource->set('hidemenu', '1');
   }
}

return '';

But it says to attach this snippet to the ‘OnDocFormSave’ action.
I have been trying to find out how to do this, but I don’t know where to start.

Can anyone help me to understand how I attach a Snippet to this action?

Thanks in advance!
Andy

You have to add this code to a new Plugin (and not a Snippet) and check the checkbox “OnDocFormSave” in the tab “System Events” of the Plugin.

Ah Ok brilliant - thank you!
So I’ve done that but it’s not doing anything.
In the code of the plugin, I can’t work out what value it’s lookng for - it just says;

   if ($resource->getTVValue('HideMenu')) {

My TV is set up liike this:

Input Option Values
Yes==1

And it’s checked in the Article.

Do I need to do anything to get that plugin to run?

Thanks
Andy

Thinking about it - there’s nothing in the call to the resources to say 'only show artciels that aren’t ‘hide form menu’. It’s not sert up like getResources.

In The Artciels Advanced Settings I have a field which says:
Other Listing Parameters:
So I’ve added &showHidden=0

But then no stories appear in my listing!

I’ve added the name of the TV in the Include TVs List

Any other ideas of things to try?

Thanks
Andy

Right - so I’ve checked the DB and I realises that by default - all Arrticle resources are set to hide from menu! (which is why none are showing when I added the Listing Parameter!’.

So I guess I could reverse it so that you have to check the box to Show in menu - but it feels a bit counter intuitive?

Sorry for all the comment - so The checkbox isn’t ctuslly doing anything at all.
I have tried reversing the process tso that if it’s checked, it changes the value in the database to ‘0’ - but it doesn’t. All new articles are ‘1’ in the hide from menu column in the database.

Back to square one - just when I thought I was getting somewhere!

Is the name of your TV “HideMenu”?
Maybe you could add some log()-commands to your code and then check the error log to make sure, the plugin is even executed.

$modx->log(modX::LOG_LEVEL_ERROR,'Plugin executed');

As this seems to be a quite unsatisfying solution. Does an extra like Magic Preview eliminate the need for this?

Although it says here that there is “no need to run the $resource->save() method as that happens automatically”, I can only see the change in the database when I actually call $resource->save();.

if ($resource->getTVValue('HideMenu')) {
	$resource->set('hidemenu', '1');
	$resource->save();
} else {
	$resource->set('hidemenu', '0');
	$resource->save();
}
1 Like

This is great thank you so much for your time!
I will have a look at this abs see if it works for me.

Thanks again!

The note about no need to save is only related to $resource->setTVValue

Thi solution works perfectly - thank you so much for you time and help!

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.