Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UPDATE CMS 6 compatibility #38

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,30 @@
}
],
"require": {
"dnadesign/silverstripe-elemental": "^5",
"silvershop/silverstripe-hasonefield": "^4",
"silverstripe/linkfield": "^4.0",
"unclecheese/display-logic": "^3"
"dnadesign/silverstripe-elemental": "^6",
"silvershop/silverstripe-hasonefield": "dev-silverstripe6",
"silverstripe/linkfield": "^5.0",
"unclecheese/display-logic": "dev-silverstripe6"
},
"require-dev": {
"silverstripe/recipe-testing": "^3",
"silverstripe/frameworktest": "^1"
"dnadesign/silverstripe-elemental": "6.x-dev",
"phpunit/phpunit": "^11.3",
"squizlabs/php_codesniffer": "^3.7",
"silverstripe/versioned": "^3",
"silverstripe/standards": "^1",
"phpstan/extension-installer": "^1.3",
"silverstripe/frameworktest": "^2"
},
"repositories": [
{
"type": "vcs",
"url": "[email protected]:muskie9/silverstripe-hasonefield.git"
},
{
"type": "vcs",
"url": "[email protected]:dynamic/silverstripe-display-logic.git"
}
],
"minimum-stability": "dev",
"prefer-stable": true,
"autoload": {
Expand Down
76 changes: 37 additions & 39 deletions src/Model/BaseElementObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

namespace Dynamic\BaseObject\Model;

use Exception;
use SilverStripe\Assets\Image;
use SilverStripe\ORM\DataObject;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Control\Director;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Versioned\Versioned;
use SilverStripe\ORM\ValidationResult;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\LinkField\Form\LinkField;
use DNADesign\Elemental\Models\BaseElement;
use DNADesign\Elemental\Forms\TextCheckboxGroupField;

/**
Expand All @@ -37,53 +35,53 @@ class BaseElementObject extends DataObject
/**
* @var array
*/
private static $db = array(
private static array $db = [
'Title' => 'Varchar(255)',
'ShowTitle' => 'Boolean',
'Content' => 'HTMLText',
);
];

/**
* @var array
*/
private static $has_one = array(
private static array $has_one = [
'Image' => Image::class,
'ElementLink' => Link::class,
);
];

/**
* @var array
*/
private static $owns = array(
private static array $owns = [
'Image',
'ElementLink',
);
];

/**
* @var string
*/
private static $default_sort = 'Title ASC';
private static string $default_sort = 'Title ASC';

/**
* @var array
*/
private static $summary_fields = array(
private static array $summary_fields = [
'Image.CMSThumbnail',
'Title',
);
];

/**
* @var array
*/
private static $searchable_fields = array(
private static array $searchable_fields = [
'Title',
'Content',
);
];

/**
* @var array
*/
private static $extensions = [
private static array $extensions = [
Versioned::class,
];

Expand All @@ -92,43 +90,43 @@ class BaseElementObject extends DataObject
*
* @var bool
*/
private static $versioned_gridfield_extensions = true;
private static bool $versioned_gridfield_extensions = true;

/**
* @var string
*/
private static $table_name = 'BaseElementObject';
private static string $table_name = 'BaseElementObject';

/**
* @param bool $includerelations
* @return array
*/
public function fieldLabels($includerelations = true)
public function fieldLabels($includerelations = true): array
{
$labels = parent::fieldLabels($includerelations);

$labels['Title'] = _t(__CLASS__ . '.TitleLabel', 'Title');
$labels['ElementLink'] = _t(__CLASS__ . '.LinkLabel', 'Link');
$labels['Image'] = _t(__CLASS__ . '.ImageLabel', 'Image');
$labels['Image.CMSThumbnail'] = _t(__CLASS__ . '.ImageLabel', 'Image');
$labels['Content'] = _t(__CLASS__. '.ContentLabel', 'Content');
$labels['Content'] = _t(__CLASS__ . '.ContentLabel', 'Content');

return $labels;
}

/**
* @return FieldList
*
* @throws \Exception
* @throws Exception
*/
public function getCMSFields()
public function getCMSFields(): FieldList
{
$this->beforeUpdateCMSFields(function ($fields) {
/** @var FieldList $fields */
$fields->removeByName(array(
$fields->removeByName([
'ElementFeaturesID',
'Sort',
));
]);

// Add a combined field for "Title" and "Displayed" checkbox in a Bootstrap input group
$fields->removeByName('ShowTitle');
Expand All @@ -147,7 +145,7 @@ public function getCMSFields()
$fields->insertBefore('Content', $fields->dataFieldByName('ElementLink'));

$image = $fields->dataFieldByName('Image')
->setDescription(_t(__CLASS__.'.ImageDescription', 'optional. Display an image.'))
->setDescription(_t(__CLASS__ . '.ImageDescription', 'optional. Display an image.'))
->setFolderName('Uploads/Elements/Objects');
$fields->insertBefore('Content', $image);

Expand All @@ -161,7 +159,7 @@ public function getCMSFields()
/**
* @return SiteTree|null
*/
public function getPage()
public function getPage(): SiteTree|null
{
$page = Director::get_current_page();
// because $page can be a SiteTree or Controller
Expand All @@ -171,10 +169,10 @@ public function getPage()
/**
* Basic permissions, defaults to page perms where possible.
*
* @param \SilverStripe\Security\Member|null $member
* @return boolean
* @param Member|null $member
* @return bool
*/
public function canView($member = null)
public function canView($member = null): bool
{
$extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) {
Expand All @@ -191,11 +189,11 @@ public function canView($member = null)
/**
* Basic permissions, defaults to page perms where possible.
*
* @param \SilverStripe\Security\Member|null $member
* @param Member|null $member
*
* @return boolean
* @return bool
*/
public function canEdit($member = null)
public function canEdit($member = null): bool
{
$extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) {
Expand All @@ -216,19 +214,19 @@ public function canEdit($member = null)
* element is not published, then it can be deleted by someone who doesn't
* have publishing permissions.
*
* @param \SilverStripe\Security\Member|null $member
* @param Member|null $member
*
* @return boolean
* @return bool
*/
public function canDelete($member = null)
public function canDelete($member = null): bool
{
$extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) {
return $extended;
}

if ($page = $this->getPage()) {
return $page->canArchive($member);
return $page->canDelete($member);
}

return Permission::check('CMS_ACCESS', 'any', $member);
Expand All @@ -237,12 +235,12 @@ public function canDelete($member = null)
/**
* Basic permissions, defaults to page perms where possible.
*
* @param \SilverStripe\Security\Member|null $member
* @param Member|null $member
* @param array $context
*
* @return boolean
* @return bool
*/
public function canCreate($member = null, $context = array())
public function canCreate($member = null, $context = []): bool
{
$extended = $this->extendedCan(__FUNCTION__, $member);
if ($extended !== null) {
Expand Down
Loading