This repository has been archived by the owner on Mar 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding MenuItem import and export and extracting GridFieldConfig
- Loading branch information
Showing
6 changed files
with
132 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* Class MenuAdminSquared | ||
* | ||
* @see MenuAdmin | ||
*/ | ||
class MenuAdminSquared extends DataExtension | ||
{ | ||
private static $model_importers = [ | ||
'MenuItem' => 'CsvBulkLoader', | ||
]; | ||
|
||
private static $managed_models = [ | ||
'MenuItem', | ||
]; | ||
|
||
/** | ||
* @param CMSForm $form | ||
*/ | ||
public function updateEditForm(CMSForm $form) | ||
{ | ||
$fields = $form->Fields(); | ||
$MenuSet = $fields->dataFieldByName('MenuSet'); | ||
$menuSet = $fields->dataFieldByName('MenuSet'); | ||
|
||
if ($menuSet instanceof GridField) { | ||
$menuSet->setTitle('Menus'); | ||
$config = $menuSet->getConfig(); | ||
|
||
$config->removeComponentsByType('GridFieldExportButton'); | ||
$config->removeComponentsByType('GridFieldPrintButton'); | ||
|
||
if ($MenuSet instanceof GridField) { | ||
$MenuSetConfig = $MenuSet->getConfig(); | ||
$MenuSetConfig->removeComponentsByType('GridFieldAddNewButton'); | ||
// Only remove add button if set by config. | ||
if (!empty(MenuSet::config()->get('default_sets'))) { | ||
$config->removeComponentsByType('GridFieldAddNewButton'); | ||
} | ||
} | ||
} | ||
|
||
$menuItems = $fields->dataFieldByName('MenuItem'); | ||
if ($menuItems instanceof GridField) { | ||
$menuItems->setTitle('Items'); | ||
$config = new MenuItemSquaredGridFieldConfig(); | ||
$menuItems->setConfig($config); | ||
|
||
$config->removeComponentsByType('GridFieldAddNewMultiClass'); | ||
|
||
$export = new GridFieldExportButton('buttons-before-left'); | ||
$config->addComponent($export); | ||
|
||
$export->setExportColumns([ | ||
'ID' => 'ID', | ||
'ClassName' => 'ClassName', | ||
'MenuTitle' => 'MenuTitle', | ||
'Link' => 'Link', | ||
'Sort' => 'Sort', | ||
'IsNewWindow' => 'IsNewWindow', | ||
'Name' => 'Name', | ||
'PageID' => 'PageID', | ||
'ImageID' => 'ImageID', | ||
'ParentItemID' => 'ParentItemID', | ||
]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/** | ||
* Class MenuItemSquaredGridFieldConfig | ||
*/ | ||
class MenuItemSquaredGridFieldConfig extends GridFieldConfig_RecordEditor | ||
{ | ||
/** | ||
* @param int $itemsPerPage | ||
*/ | ||
public function __construct($itemsPerPage = 25) | ||
{ | ||
parent::__construct($itemsPerPage); | ||
|
||
$this->removeComponentsByType('GridFieldAddNewButton'); | ||
|
||
$this->addComponent(new GridFieldOrderableRows('Sort')); | ||
$multiClass = new GridFieldAddNewMultiClass(); | ||
$classes = ClassInfo::subclassesFor('MenuItem'); | ||
$multiClass->setClasses($classes); | ||
|
||
$this->addComponent($multiClass); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,25 @@ | ||
<?php | ||
|
||
/** | ||
* Class MenuSetSquared | ||
* | ||
* @see MenuSet | ||
*/ | ||
class MenuSetSquared extends DataExtension | ||
{ | ||
private static $singular_name = 'Menu'; | ||
|
||
private static $plural_name = 'Menus'; | ||
|
||
/** | ||
* @param FieldList $fields | ||
*/ | ||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$menuItem = $fields->dataFieldByName('MenuItems'); | ||
|
||
if ($menuItem instanceof GridField) { | ||
$menuItemConfig = $menuItem->getConfig(); | ||
$menuItemConfig->removeComponentsByType('GridFieldAddNewButton'); | ||
|
||
$multiClass = new GridFieldAddNewMultiClass(); | ||
$classes = ClassInfo::subclassesFor('MenuItem'); | ||
|
||
$multiClass->setClasses($classes); | ||
$menuItemConfig->addComponent($multiClass); | ||
|
||
$menuItemConfig->removeComponentsByType('GridFieldDeleteAction'); | ||
$menuItemConfig->addComponent(new GridFieldDeleteAction()); | ||
$menuItem->setConfig(new MenuItemSquaredGridFieldConfig()); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"name": "marketo/silverstripe-menumanager-squared", | ||
"description": "SilverStripe MenuManager Squared", | ||
"type": "silverstripe-module", | ||
"keywords": ["silverstripe", "members", "default"], | ||
"keywords": ["silverstripe", "menu", "manager"], | ||
"require": { | ||
"silverstripe/framework": "3.*", | ||
"composer/installers": "*", | ||
|
@@ -21,6 +21,5 @@ | |
"name": "Brandon J. Marshall", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "dev" | ||
] | ||
} |