From bc45582c023eefb375dc42aa926494b8dfe3b6fa Mon Sep 17 00:00:00 2001 From: "y2ksoft@gmail.com" Date: Thu, 2 Mar 2023 13:55:33 +1300 Subject: [PATCH] cms-5-upgrade --- composer.json | 17 +++++++++++----- src/MenuAdmin.php | 14 ++++++++------ src/MenuItem.php | 26 ++++++++++++------------- src/MenuManagerTemplateProvider.php | 19 +++++++++--------- src/MenuSet.php | 30 ++++++++++++++--------------- 5 files changed, 58 insertions(+), 48 deletions(-) diff --git a/composer.json b/composer.json index 4a6f774..756829e 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -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 + } + } } diff --git a/src/MenuAdmin.php b/src/MenuAdmin.php index 15c46f1..e983a80 100644 --- a/src/MenuAdmin.php +++ b/src/MenuAdmin.php @@ -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; @@ -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 diff --git a/src/MenuItem.php b/src/MenuItem.php index 229a4fc..dc2d3f0 100644 --- a/src/MenuItem.php +++ b/src/MenuItem.php @@ -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) @@ -39,7 +39,7 @@ 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 ]; @@ -47,7 +47,7 @@ class MenuItem extends DataObject implements PermissionProvider /** * @var array */ - private static $searchable_fields = [ + private static array $searchable_fields = [ 'MenuTitle', 'Page.Title' ]; @@ -55,7 +55,7 @@ class MenuItem extends DataObject implements PermissionProvider /** * @return string */ - public function IsNewWindowNice() + public function IsNewWindowNice(): string { return $this->IsNewWindow ? _t('SilverStripe\\Forms\\CheckboxField.YESANSWER', 'Yes') @@ -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') @@ -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'); } @@ -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'); } @@ -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'); } @@ -109,7 +109,7 @@ 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'); } @@ -117,7 +117,7 @@ public function canView($member = null) /** * @return FieldList */ - public function getCMSFields() + public function getCMSFields(): FieldList { $fields = FieldList::create(TabSet::create('Root')); @@ -206,7 +206,7 @@ public function __get($field) /** * @return mixed */ - public function getTitle() + public function getTitle(): string { return $this->MenuTitle; } diff --git a/src/MenuManagerTemplateProvider.php b/src/MenuManagerTemplateProvider.php index e55add6..3ba1f48 100644 --- a/src/MenuManagerTemplateProvider.php +++ b/src/MenuManagerTemplateProvider.php @@ -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 @@ -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', @@ -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"); diff --git a/src/MenuSet.php b/src/MenuSet.php index 6c49c72..5343720 100644 --- a/src/MenuSet.php +++ b/src/MenuSet.php @@ -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'), @@ -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; @@ -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); @@ -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; @@ -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; @@ -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()); } @@ -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(); @@ -194,7 +194,7 @@ public function requireDefaultRecords() /** * @return FieldList */ - public function getCMSFields() + public function getCMSFields(): FieldList { $fields = FieldList::create(TabSet::create('Root')); @@ -275,7 +275,7 @@ protected function getDefaultSetNames() /** * @return array */ - public function summaryFields() + public function summaryFields(): array { return [ 'Name' => _t(__CLASS__ . '.DB_Name', 'Name'),