Added a method to set the button name in a GridFieldAddByDBField component

This commit is contained in:
Ryan Potter 2019-07-01 09:37:12 +12:00 committed by Robbie Averill
parent dd18648ed1
commit ea2fcd0b6e
6 changed files with 216 additions and 2 deletions

6
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/silverstripe-blog.iml" filepath="$PROJECT_DIR$/.idea/silverstripe-blog.iml" />
</modules>
</component>
</project>

11
.idea/silverstripe-blog.iml generated Normal file
View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="SilverStripe\Blog\" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="false" packagePrefix="SilverStripe\Blog\Tests\" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

157
.idea/workspace.xml generated Normal file
View File

@ -0,0 +1,157 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="52b7d934-bcd3-4cbc-b6c5-80f46e806880" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/src/Forms/GridField/GridFieldAddByDBField.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/Forms/GridField/GridFieldAddByDBField.php" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ComposerSettings" synchronizationState="SYNCHRONIZE">
<pharConfigPath>$PROJECT_DIR$/composer.json</pharConfigPath>
<execution>
<executable />
</execution>
</component>
<component name="FileEditorManager">
<leaf>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/Forms/GridField/GridFieldAddByDBField.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="503">
<caret line="214" column="9" selection-start-line="214" selection-start-column="9" selection-end-line="214" selection-end-column="9" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>_t(</find>
</findStrings>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/Forms/GridField/GridFieldAddByDBField.php" />
</list>
</option>
</component>
<component name="ProjectConfigurationFiles">
<option name="files">
<list>
<option value="$PROJECT_DIR$/.idea/silverstripe-blog.iml" />
<option value="$PROJECT_DIR$/.idea/misc.xml" />
<option value="$PROJECT_DIR$/.idea/modules.xml" />
<option value="$PROJECT_DIR$/.idea/vcs.xml" />
</list>
</option>
</component>
<component name="ProjectFrameBounds">
<option name="x" value="-1920" />
<option name="y" value="23" />
<option name="width" value="1920" />
<option name="height" value="1057" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="silverstripe-blog" type="b2602c69:ProjectViewProjectNode" />
<item name="silverstripe-blog" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="editor.config.ad.shown" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="nodejs_package_manager_path" value="yarn" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="52b7d934-bcd3-4cbc-b6c5-80f46e806880" name="Default Changelist" comment="" />
<created>1561930166221</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1561930166221</updated>
<workItem from="1561930167730" duration="270000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="270000" />
</component>
<component name="ToolWindowManager">
<frame x="-1920" y="23" width="1920" height="1057" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="npm" side_tool="true" />
<window_info id="Favorites" order="0" side_tool="true" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Docker" order="0" show_stripe_button="false" />
<window_info anchor="bottom" id="Database Changes" order="1" />
<window_info anchor="bottom" id="Version Control" order="2" />
<window_info anchor="bottom" id="Terminal" order="3" />
<window_info anchor="bottom" id="Event Log" order="4" side_tool="true" />
<window_info anchor="bottom" id="Message" order="5" />
<window_info anchor="bottom" id="Find" order="6" />
<window_info anchor="bottom" id="Run" order="7" />
<window_info anchor="bottom" id="Debug" order="8" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="9" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="10" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="11" />
<window_info anchor="right" id="Database" order="0" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="1" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="2" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="3" weight="0.25" />
<window_info active="true" anchor="right" content_ui="combo" id="Project" order="4" visible="true" weight="0.18104367" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/Forms/GridField/GridFieldAddByDBField.php">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="503">
<caret line="214" column="9" selection-start-line="214" selection-start-column="9" selection-end-line="214" selection-end-column="9" />
</state>
</provider>
</entry>
</component>
</project>

View File

@ -37,6 +37,13 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
*/
protected $dataObjectField = 'Title';
/**
* Name for the buttons displayed in the CMS
*
* @var string
*/
protected $buttonName;
/**
* Creates a text field and add button which allows the user to directly create a new
* DataObject by just entering the title.
@ -142,6 +149,19 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
return $this->dataObjectField;
}
/**
* Set the button name
*
* @param $name
* @return $this
*/
public function setButtonName($name)
{
$this->buttonName = $name;
return $this;
}
/**
* Set the database field.
*
@ -188,14 +208,20 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
->setAttribute('placeholder', $obj->fieldLabel($dbField))
->addExtraClass('no-change-track');
if (!$this->buttonName) {
// provide a default button name, can be changed by calling {@link setButtonName()} on this component
$objectName = $obj->i18n_singular_name();
$this->buttonName = _t(__CLASS__ . '.ButtonName', 'Add {name}', array('name' => $objectName));
}
$addAction = GridField_FormAction::create(
$gridField,
'add',
_t(
__CLASS__ . '.Add',
'Add {name}',
'{name}',
'Add button text',
['name' => $obj->i18n_singular_name()]
['name' => $this->buttonName]
),
'add',
'add'