I would like to add a new radio button set to Root.Content.Metadata tab.
This field set will be used to allow the user to select whether to "hide" the page from search engines. Basically, depending on the users selection, either no meta tag will be added, a meta robots tag with a content value of noindex will be added, or a meta robots tag with a content value of noindex,nofollow will be added.
So ultimately my radio button set would look like:
[X] Treat this page as a normal page (no meta tag is inserted, this should also be the default selected value for the radio button set).
[ ] Let search engines see this page, but not list it in their search results (this would insert a noindex robots metatag)
[ ] Completely hide this page from search engines? (This would insert a nofollow, no index robots metatag).
I would like this to appear above the "Title' meta tag field currently in the Metadata tab.
From what I know of SS, I would modify the sitetree class in mysite/code/Page.php, so here is what I have attempted. Please note that I wasn't sure of the correct syntax for adding the radio button set, so in this example I am using a text field to simplify learning how to add fields. If anyone can give me an example with the radio button set with a default value, it would be greatly appreciated.
At the end of the mysite/code/Page.php I've added:
//custom-code: BOF New Class for MetaRobots tag
class Page_MetaRobotsTag extends SiteTree {
public static $db = array(
'MetaRobotsTag' => 'Text'
);
public static $has_one = array(
);
/** Add code here **/
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Metadata', new TextField('MetaRobotsTag'), 'Title');
return $fields;
}
}
//custom-code: EOF New Class for MetaRobots tag
I have /dev/build?flush=1 to rebuild the db and clear my cache, but the new field will not appear in my admin areas Root.Content.Metadata tab, can anyone tell me if I missed something in my code or what else I may be doing wrong.
I assume once I can get this to show I will then be able to make the selection and hav ethe DB store it and my next step will be to somehow change the way metatags are created to include my stored value. I see that in /sapphire/core/model/Sitetree.php around line 1228 (commented with * Return the title, description, keywords and language metatags.) I can add my code to be generated with the other metatags. Is there a better place or method to do this. I assume I generally should not be altering the core SiteTree file.
Thank you in advance for any help or advice you can give me.