ENHANCEMENT Added fieldLabels() overloading to various DataObject subclasses. Use this method instead of directly calling _t() in getCMSFields(), and use fieldLabel('MyField') to get the label for a specific FormField. This way, we can transparently support formfield scaffolding and re-use the labels for search fields automatically.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@65072 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2008-11-02 20:04:10 +00:00
parent eb4c950655
commit 3edc358ead
8 changed files with 108 additions and 24 deletions

View File

@ -52,7 +52,7 @@ class ErrorPage extends Page {
"Root.Content.Main",
new DropdownField(
"ErrorCode",
_t('ErrorPage.CODE', "Error code"),
$this->fieldLabel('ErrorCode'),
array(
400 => _t('ErrorPage.400', '400 - Bad Request'),
401 => _t('ErrorPage.401', '401 - Unauthorized'),
@ -121,6 +121,13 @@ class ErrorPage extends Page {
return $this->extension_instances['Versioned']->publish($fromStage, $toStage, $createNewVersion);
}
function fieldLabels() {
$labels = parent::fieldLabels();
$labels['ErrorCode'] = _t('ErrorPage.CODE', "Error code");
return $labels;
}
}
/**

View File

@ -91,8 +91,8 @@ class RedirectorPage extends Page {
$fields = new FieldSet(
new TabSet("Root",
$tabContent = new Tab("Content",
new TextField("Title", _t('SiteTree.PAGETITLE')),
new TextField("MenuTitle", _t('SiteTree.MENUTITLE')),
new TextField("Title", $this->fieldLabel('Title')),
new TextField("MenuTitle", $this->fieldLabel('MenuTitle')),
new FieldGroup(_t('SiteTree.URL'),
new LabelField('BaseUrlLabel',Director::absoluteBaseURL()),
new UniqueRestrictedTextField("URLSegment",
@ -128,9 +128,9 @@ class RedirectorPage extends Page {
new TextareaField("MetaDescription", _t('SiteTree.METADESC'))
),
$tabBehaviour = new Tab("Behaviour",
new DropdownField("ClassName", _t('SiteTree.PAGETYPE'), $this->getClassDropdown()),
new CheckboxField("ShowInMenus", _t('SiteTree.SHOWINMENUS')),
new CheckboxField("ShowInSearch", _t('SiteTree.SHOWINSEARCH'))
new DropdownField("ClassName",$this->fieldLabel('ClassName'), $this->getClassDropdown()),
new CheckboxField("ShowInMenus", $this->fieldLabel('ShowInMenus')),
new CheckboxField("ShowInSearch", $this->fieldLabel('ShowInSearch'))
)
)
);

View File

@ -1059,14 +1059,14 @@ class SiteTree extends DataObject {
new TabSet("Root",
$tabContent = new TabSet('Content',
$tabMain = new Tab('Main',
new TextField("Title", _t('SiteTree.PAGETITLE', "Page name")),
new TextField("Title", $this->fieldLabel('Title')),
/*new UniqueTextField("Title",
"Title",
"SiteTree",
"Another page is using that name. Page names should be unique.",
"Page Name"
),*/
new TextField("MenuTitle", _t('SiteTree.MENUTITLE', "Navigation label")),
new TextField("MenuTitle", $this->fieldLabel('MenuTitle')),
new HtmlEditorField("Content", _t('SiteTree.HTMLEDITORTITLE', "Content", PR_MEDIUM, 'HTML editor title'))
),
$tabMeta = new Tab('Meta-data',
@ -1086,15 +1086,15 @@ class SiteTree extends DataObject {
),
new LabelField('TrailingSlashLabel',"/")
),
new HeaderField('MetaTagsHeader',_t('SiteTree.METAHEADER', "Search Engine Meta-tags")),
new TextField("MetaTitle", _t('SiteTree.METATITLE', "Title")),
new TextareaField("MetaDescription", _t('SiteTree.METADESC', "Description")),
new TextareaField("MetaKeywords", _t('SiteTree.METAKEYWORDS', "Keywords")),
new HeaderField('MetaTagsHeader',$this->fieldLabel('MetaTagsHeader')),
new TextField("MetaTitle", $this->fieldLabel('MetaTitle')),
new TextareaField("MetaDescription", $this->fieldLabel('MetaDescription')),
new TextareaField("MetaKeywords", $this->fieldLabel('MetaKeywords')),
new ToggleCompositeField(
'AdvancedOptions',
_t('SiteTree.METAADVANCEDHEADER', "Advanced Options..."),
array(
new TextareaField("ExtraMeta",_t('SiteTree.METAEXTRA', "Custom Meta Tags")),
new TextareaField("ExtraMeta",$this->fieldLabel('ExtraMeta')),
new LiteralField(
"",
"<p>" .
@ -1107,7 +1107,7 @@ class SiteTree extends DataObject {
) .
"</p>"
),
new DropdownField("Priority", _t('SiteTree.METAPAGEPRIO', "Page Priority"), $pagePriorities)
new DropdownField("Priority", $this->fieldLabel('Priority'), $pagePriorities)
),
true
)
@ -1116,13 +1116,13 @@ class SiteTree extends DataObject {
$tabBehaviour = new Tab('Behaviour',
new DropdownField(
"ClassName",
_t('SiteTree.PAGETYPE', "Page type", PR_MEDIUM, 'Classname of a page object'),
$this->fieldLabel('ClassName'),
$this->getClassDropdown()
),
new CheckboxField("ShowInMenus", _t('SiteTree.SHOWINMENUS', "Show in menus?")),
new CheckboxField("ShowInSearch", _t('SiteTree.SHOWINSEARCH', "Show in search?")),
new CheckboxField("ShowInMenus", $this->fieldLabel('ShowInMenus')),
new CheckboxField("ShowInSearch", $this->fieldLabel('ShowInSearch')),
/*, new TreeMultiselectField("MultipleParents", "Page appears within", "SiteTree")*/
new CheckboxField("ProvideComments", _t('SiteTree.ALLOWCOMMENTS', "Allow comments on this page?")),
new CheckboxField("ProvideComments", $this->fieldLabel('ProvideComments')),
new LiteralField(
"",
"<p>" .
@ -1156,7 +1156,7 @@ class SiteTree extends DataObject {
"OnlyTheseUsers" => _t('SiteTree.ACCESSONLYTHESE', "Only these people (choose from list)")
)
),
new DropdownField("ViewersGroup", _t('SiteTree.GROUP', "Group"), Group::map()),
new DropdownField("ViewersGroup", $this->fieldLabel('ViewersGroup'), Group::map()),
new HeaderField('WhoCanEditHeader',_t('SiteTree.EDITHEADER', "Who can edit this inside the CMS?"), 2),
new OptionsetField(
"Editors",
@ -1166,7 +1166,7 @@ class SiteTree extends DataObject {
"OnlyTheseUsers" => _t('SiteTree.EDITONLYTHESE', "Only these people (choose from list)")
)
),
new DropdownField("EditorsGroup", _t('SiteTree.GROUP'), Group::map())
new DropdownField("EditorsGroup", $this->fieldLabel('EditorsGroup'), Group::map())
)
)
//new NamedLabelField("Status", $message, "pageStatusMessage", true)
@ -1184,6 +1184,38 @@ class SiteTree extends DataObject {
return $fields;
}
function fieldLabels() {
$labels = parent::fieldLabels();
$labels['Title'] = _t('SiteTree.PAGETITLE', "Page name");
$labels['MenuTitle'] = _t('SiteTree.MENUTITLE', "Navigation label");
$labels['MetaTagsHeader'] = _t('SiteTree.METAHEADER', "Search Engine Meta-tags");
$labels['MetaTitle'] = _t('SiteTree.METATITLE', "Title");
$labels['MetaDescription'] = _t('SiteTree.METADESC', "Description");
$labels['MetaKeywords'] = _t('SiteTree.METAKEYWORDS', "Keywords");
$labels['ExtraMeta'] = _t('SiteTree.METAEXTRA', "Custom Meta Tags");
$labels['Priority'] = _t('SiteTree.METAPAGEPRIO', "Page Priority");
$labels['ClassName'] = _t('SiteTree.PAGETYPE', "Page type", PR_MEDIUM, 'Classname of a page object');
$labels['ShowInMenus'] =_t('SiteTree.SHOWINMENUS', "Show in menus?");
$labels['ShowInSearch'] = _t('SiteTree.SHOWINSEARCH', "Show in search?");
$labels['ProvideComments'] = _t('SiteTree.ALLOWCOMMENTS', "Allow comments on this page?");
$labels['ViewersGroup'] = _t('SiteTree.GROUP', "Group");
$labels['EditorsGroup'] = _t('SiteTree.GROUP');
$labels['URLSegment'] = _t('SiteTree.URLSegment', 'URL Segment', PR_MEDIUM, 'URL for this page');
$labels['Content'] = _t('SiteTree.Content', 'Content', PR_MEDIUM, 'Main HTML Content for a page');
$labels['HomepageForDomain'] = _t('SiteTree.HomepageForDomain', 'Hompage for this domain');
$labels['Viewers'] = _t('SiteTree.Viewers', 'Viewers Group');
$labels['Editors'] = _t('SiteTree.Editors', 'Editors Group');
$labels['ToDo'] = _t('SiteTree.ToDo', 'Todo Notes');
$labels['Parent'] = _t('SiteTree.has_one_Parent', 'Parent Page', PR_MEDIUM, 'The parent page in the site hierarchy');
$labels['Comments'] = _t('SiteTree.Comments', 'Comments');
$labels['LinkTracking'] = _t('SiteTree.many_many_LinkTracking', 'Link Tracking');
$labels['ImageTracking'] = _t('SiteTree.many_many_ImageTracking', 'Image Tracking');
$labels['BackLinkTracking'] = _t('SiteTree.many_many_BackLinkTracking', 'Backlink Tracking');
return $labels;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -713,6 +713,10 @@ class Versioned extends DataObjectDecorator {
protected static $reading_stage = null;
protected static $reading_archived_date = null;
function updateFieldLabels(&$labels) {
$labels['Versions'] = _t('Versioned.has_many_Versions', 'Versions', PR_MEDIUM, 'Past Versions of this page');
}
}
/**

View File

@ -530,6 +530,18 @@ class File extends DataObject {
self::$cache_file_fields = null;
}
function fieldLabels() {
$labels = parent::fieldLabels();
$labels['Name'] = _t('File.Name', 'Name');
$labels['Title'] = _t('File.Title', 'Title');
$labels['Filename'] = _t('File.Filename', 'Filename');
$labels['Filename'] = _t('File.Filename', 'Filename');
$labels['Content'] = _t('File.Content', 'Content');
$labels['Sort'] = _t('File.Sort', 'Sort Order');
return $labels;
}
}
?>

View File

@ -41,7 +41,7 @@ class Group extends DataObject {
$fields = new FieldSet(
new TabSet("Root",
new Tab(_t('SecurityAdmin.MEMBERS', 'Members'),
new TextField("Title", _t('SecurityAdmin.GROUPNAME', 'Group name')),
new TextField("Title", $this->fieldLabel('Title')),
$memberList = new MemberTableField(
$this,
"Members",
@ -110,6 +110,21 @@ class Group extends DataObject {
return $fields;
}
function fieldLabels() {
$labels = parent::fieldLabels();
$labels['Title'] = _t('SecurityAdmin.GROUPNAME', 'Group name');
$labels['Description'] = _t('Group.Description', 'Description');
$labels['Code'] = _t('Group.Code', 'Group Code', PR_MEDIUM, 'Programmatical code identifying a group');
$labels['Locked'] = _t('Group.Locked', 'Locked?', PR_MEDIUM, 'Group is locked in the security administration area');
$labels['Sort'] = _t('Group.Sort', 'Sort Order');
$labels['IPRestrictions'] = _t('Group.IPRestrictions', 'IP Address Restrictions');
$labels['Parent'] = _t('Group.Parent', 'Parent Group', PR_MEDIUM, 'One group has one parent group');
$labels['Permissions'] = _t('Group.has_many_Permissions', 'Permissions', PR_MEDIUM, 'One group has many permissions');
$labels['Members'] = _t('Group.many_many_Members', 'Members', PR_MEDIUM, 'One group has many members');
return $labels;
}
/**
* Add a member to a group.
*

View File

@ -27,5 +27,14 @@ class LoginAttempt extends DataObject {
'Member' => 'Member', // only linked if the member actually exists
);
function fieldLabels() {
$labels = parent::fieldLabels();
$labels['Email'] = _t('LoginAttempt.Email', 'Email Address');
$labels['Status'] = _t('LoginAttempt.Status', 'Status');
$labels['IP'] = _t('LoginAttempt.IP', 'IP Address');
return $labels;
}
}
?>

View File

@ -866,9 +866,14 @@ class Member extends DataObject {
$labels['FirstName'] = _t('Member.FIRSTNAME');
$labels['Surname'] = _t('Member.SURNAME');
$labels['Email'] = _t('Member.EMAIL');
$labels['FirstName'] = _t('Member.FIRSTNAME');
$labels['FirstName'] = _t('Member.FIRSTNAME');
$this->extend('updateFieldLabels', $labels);
$labels['Password'] = _t('Member.db_Password', 'Password');
$labels['NumVisit'] = _t('Member.db_NumVisit', 'Number of Visits');
$labels['LastVisited'] = _t('Member.db_LastVisited', 'Last Visited Date');
$labels['PasswordExpiry'] = _t('Member.db_PasswordExpiry', 'Password Expiry Date', PR_MEDIUM, 'Password expiry date');
$labels['LockedOutUntil'] = _t('Member.db_LockedOutUntil', 'Locked out until', PR_MEDIUM, 'Security related date');
$labels['Locale'] = _t('Member.db_Locale', 'Interface Locale');
$labels['Groups'] = _t('Member.belongs_many_many_Groups', 'Groups', PR_MEDIUM, 'Security Groups this member belongs to');
return $labels;
}