Skip to content

Commit

Permalink
Merge pull request #55 from silverstripeltd/upgrade/cms-5-upgrade
Browse files Browse the repository at this point in the history
cms-5-upgrade
  • Loading branch information
wilr authored Jul 5, 2023
2 parents 8bb9ceb + bc45582 commit e5fc0d2
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 48 deletions.
17 changes: 12 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"description": "Allows complex menu management to be handled through the CMS when a simple tree structure is not enough.",
"license": "MIT",
"require": {
"silverstripe/framework": "~4.0",
"silverstripe/vendor-plugin": "^1.0",
"symbiote/silverstripe-gridfieldextensions": "^3.0"
"silverstripe/framework": "^5",
"silverstripe/vendor-plugin": "^2.0",
"silverstripe/admin": "^2.0.0-beta1",
"symbiote/silverstripe-gridfieldextensions": "^4.0.0-beta1"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.5"
"squizlabs/php_codesniffer": "^3.7.2"
},
"autoload": {
"psr-4": {
Expand All @@ -20,5 +21,11 @@
"dev-main": "3.3.x-dev"
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"config": {
"allow-plugins": {
"composer/installers": true,
"silverstripe/vendor-plugin": true
}
}
}
14 changes: 8 additions & 6 deletions src/MenuAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use SilverStripe\Admin\ModelAdmin;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldAddNewButton;
use SilverStripe\Forms\GridField\GridFieldImportButton;
Expand All @@ -17,34 +19,34 @@ class MenuAdmin extends ModelAdmin
/**
* @var array
*/
private static $managed_models = [
private static array $managed_models = [
MenuSet::class,
];

/**
* @var string
*/
private static $url_segment = 'menu-manager';
private static string $url_segment = 'menu-manager';

/**
* @var string
*/
private static $menu_title = 'Menus';
private static string $menu_title = 'Menus';

/**
* @var string
*/
private static $menu_icon_class = 'font-icon-link';
private static string $menu_icon_class = 'font-icon-link';

/**
* @var array
*/
private static $model_importers = [];
private static array $model_importers = [];

/**
* @var bool
*/
private static $enable_cms_create = true;
private static bool $enable_cms_create = true;

/**
* Adjust the CMS's ability to create MenuSets
Expand Down
26 changes: 13 additions & 13 deletions src/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class MenuItem extends DataObject implements PermissionProvider
/**
* @var string
*/
private static $table_name = 'MenuItem';
private static string $table_name = 'MenuItem';

/**
* @var array
*/
private static $db = [
private static array $db = [
// If you want to customise the MenuTitle use this field - leaving blank will use MenuTitle of associated Page
'MenuTitle' => 'Varchar(255)',
// This field is used for external links (picking a page from the dropdown will overwrite this link)
Expand All @@ -39,23 +39,23 @@ class MenuItem extends DataObject implements PermissionProvider
/**
* @var array
*/
private static $has_one = [
private static array $has_one = [
'Page' => SiteTree::class, // page the MenuItem refers to
'MenuSet' => MenuSet::class, // parent MenuSet
];

/**
* @var array
*/
private static $searchable_fields = [
private static array $searchable_fields = [
'MenuTitle',
'Page.Title'
];

/**
* @return string
*/
public function IsNewWindowNice()
public function IsNewWindowNice(): string
{
return $this->IsNewWindow
? _t('SilverStripe\\Forms\\CheckboxField.YESANSWER', 'Yes')
Expand All @@ -65,12 +65,12 @@ public function IsNewWindowNice()
/**
* @var string
*/
private static $default_sort = 'Sort';
private static string $default_sort = 'Sort';

/**
* @return array
*/
public function providePermissions()
public function providePermissions(): array
{
return [
'MANAGE_MENU_ITEMS' => _t(__CLASS__ . '.ManageMenuItems', 'Manage Menu Items')
Expand All @@ -82,7 +82,7 @@ public function providePermissions()
* @param array $context
* @return boolean
*/
public function canCreate($member = null, $context = [])
public function canCreate($member = null, $context = []): bool
{
return Permission::check('MANAGE_MENU_ITEMS');
}
Expand All @@ -91,7 +91,7 @@ public function canCreate($member = null, $context = [])
* @param mixed $member
* @return boolean
*/
public function canDelete($member = null)
public function canDelete($member = null): bool
{
return Permission::check('MANAGE_MENU_ITEMS');
}
Expand All @@ -100,7 +100,7 @@ public function canDelete($member = null)
* @param mixed $member
* @return boolean
*/
public function canEdit($member = null)
public function canEdit($member = null): bool
{
return Permission::check('MANAGE_MENU_ITEMS');
}
Expand All @@ -109,15 +109,15 @@ public function canEdit($member = null)
* @param mixed $member
* @return boolean
*/
public function canView($member = null)
public function canView($member = null): bool
{
return Permission::check('MANAGE_MENU_ITEMS');
}

/**
* @return FieldList
*/
public function getCMSFields()
public function getCMSFields(): FieldList
{
$fields = FieldList::create(TabSet::create('Root'));

Expand Down Expand Up @@ -206,7 +206,7 @@ public function __get($field)
/**
* @return mixed
*/
public function getTitle()
public function getTitle(): string
{
return $this->MenuTitle;
}
Expand Down
19 changes: 10 additions & 9 deletions src/MenuManagerTemplateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use InvalidArgumentException;
use SilverStripe\Core\Extensible;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject;
use SilverStripe\View\TemplateGlobalProvider;

class MenuManagerTemplateProvider implements TemplateGlobalProvider
Expand All @@ -14,7 +16,7 @@ class MenuManagerTemplateProvider implements TemplateGlobalProvider
/**
* @return array
*/
public static function get_template_global_variables()
public static function get_template_global_variables(): array
{
return [
'MenuSet' => 'MenuSet',
Expand All @@ -26,29 +28,28 @@ public static function get_template_global_variables()
* @param $name
* @return MenuSet|null
*/
public static function MenuSet($name)
public static function MenuSet($name): ?MenuSet
{
return Injector::inst()->get(self::class)->findMenuSetByName($name);
}

/**
* @param $name
* @return MenuSet|null
*/
public static function MenuSets()
{
return MenuSet::get();
}
public static function MenuSets(): ?MenuSet
{
return MenuSet::get();
}


/**
* Find a MenuSet by name
*
* @param string $name
* @return MenuSet|null
* @return DataObject|null
* @throws InvalidArgumentException
*/
public function findMenuSetByName($name)
public function findMenuSetByName(string $name): ?DataObject
{
if (empty($name)) {
throw new InvalidArgumentException("Please pass in the name of the MenuSet you're trying to find");
Expand Down
30 changes: 15 additions & 15 deletions src/MenuSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,33 @@
*/
class MenuSet extends DataObject implements PermissionProvider
{
private static $table_name = 'MenuSet';
private static string $table_name = 'MenuSet';

private static $db = [
private static array $db = [
'Name' => 'Varchar(255)',
'Description' => 'Text',
'Sort' => 'Int'
];

private static $has_many = [
private static array $has_many = [
'MenuItems' => MenuItem::class,
];

private static $cascade_deletes = [
private static array $cascade_deletes = [
'MenuItems'
];

private static $searchable_fields = [
private static array $searchable_fields = [
'Name',
'Description'
];

private static $default_sort = 'Sort ASC';
private static string $default_sort = 'Sort ASC';

/**
* @return array
*/
public function providePermissions()
public function providePermissions(): array
{
return [
'MANAGE_MENU_SETS' => _t(__CLASS__ . '.ManageMenuSets', 'Manage Menu Sets'),
Expand Down Expand Up @@ -89,7 +89,7 @@ public function validate()
* @param array $context
* @return boolean
*/
public function canCreate($member = null, $context = [])
public function canCreate($member = null, $context = []): bool
{
if (Permission::check('MANAGE_MENU_SETS')) {
return true;
Expand All @@ -102,7 +102,7 @@ public function canCreate($member = null, $context = [])
* @param mixed $member
* @return boolean
*/
public function canDelete($member = null)
public function canDelete($member = null): bool
{
$canDelete = parent::canDelete($member);

Expand All @@ -126,7 +126,7 @@ public function canDelete($member = null)
* @param mixed $member
* @return boolean
*/
public function canEdit($member = null)
public function canEdit($member = null): bool
{
if (Permission::check('MANAGE_MENU_SETS') || Permission::check('MANAGE_MENU_ITEMS')) {
return true;
Expand All @@ -139,7 +139,7 @@ public function canEdit($member = null)
* @param mixed $member
* @return boolean
*/
public function canView($member = null)
public function canView($member = null): bool
{
if (Permission::check('MANAGE_MENU_SETS') || Permission::check('MANAGE_MENU_ITEMS')) {
return true;
Expand All @@ -162,7 +162,7 @@ public function Children()
* Check if this menu set appears in the default sets config
* @return bool
*/
public function isDefaultSet()
public function isDefaultSet(): bool
{
return in_array($this->Name, $this->getDefaultSetNames());
}
Expand All @@ -171,7 +171,7 @@ public function isDefaultSet()
/**
* Set up default records based on the yaml config
*/
public function requireDefaultRecords()
public function requireDefaultRecords(): void
{
parent::requireDefaultRecords();

Expand All @@ -194,7 +194,7 @@ public function requireDefaultRecords()
/**
* @return FieldList
*/
public function getCMSFields()
public function getCMSFields(): FieldList
{
$fields = FieldList::create(TabSet::create('Root'));

Expand Down Expand Up @@ -275,7 +275,7 @@ protected function getDefaultSetNames()
/**
* @return array
*/
public function summaryFields()
public function summaryFields(): array
{
return [
'Name' => _t(__CLASS__ . '.DB_Name', 'Name'),
Expand Down

0 comments on commit e5fc0d2

Please sign in to comment.