Skip to content

Commit

Permalink
Merge pull request #30 from symbiote/ss5
Browse files Browse the repository at this point in the history
Silverstripe 5 updates
  • Loading branch information
nyeholt authored Sep 13, 2024
2 parents d230dbc + 45b4283 commit 89dd48a
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 121 deletions.
8 changes: 1 addition & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# Changelog

All notable changes to this project will be documented in this file.
For more information on changes and releases, please visit [Releases](https://github.com/symbiote/silverstripe-dynamiclists/releases).

This project adheres to [Semantic Versioning](http://semver.org/) as of version 2.0.0

## [2.0.0]

* Now compatible with SilverStripe4
* Namespaced under Symbiote\DynamicLists
* DataListUpdgradeTask and DynamicListUserFormsUpgradeTask removed. Users needing to these upgrade paths should install version 1.0.0 initially and run these tasks.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ in a central location that might be used across several forms.
## Composer Install

```
composer require symbiote/silverstripe-dynamiclists:~2.0
composer require symbiote/silverstripe-dynamiclists: ^2
```

## Requirements

* SilverStripe 4.0+
* SilverStripe 4 & 5

## Documentation

Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

48 changes: 23 additions & 25 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
{
"name": "symbiote/silverstripe-dynamiclists",
"description": "A Module that allows users to create custom data lists. These lists can then be used in a form control (specified via code by a developer) or within a user defined form to be able to define controlled vocabularies managed in a central location that might be used across several forms.",
"type": "silverstripe-vendormodule",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Shea Dawson",
"email": "shea@symbiote.com.au"
}
"name": "symbiote/silverstripe-dynamiclists",
"description": "A Module that allows users to create custom data lists. These lists can then be used in a form control (specified via code by a developer) or within a user defined form to be able to define controlled vocabularies managed in a central location that might be used across several forms.",
"type": "silverstripe-vendormodule",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Shea Dawson",
"email": "shea@symbiote.com.au"
}
],
"require": {
"php": ">=5.6.0",
"silverstripe/cms": "~4.0",
"silverstripe/framework": "~4.0",
"symbiote/silverstripe-gridfieldextensions": "~3.0"
},
"extra": {
"require": {
"php": "^8.1",
"silverstripe/cms": "^4.12 || ^5",
"symbiote/silverstripe-gridfieldextensions": "^3 || ^4"
},
"extra": {
"expose": [
"javascript"
],
"installer-name": "dynamiclists",
"branch-alias": {
"dev-master": "2.0.x-dev"
}
],
"branch-alias": {
"dev-master": "2.1.x-dev"
}
},
"replace": {
"sheadawson/silverstripe-dynamiclists": "self.version"
},
"replace": {
"sheadawson/silverstripe-dynamiclists": "self.version"
},
"minimum-stability": "dev"
"minimum-stability": "dev"
}
12 changes: 7 additions & 5 deletions src/controllers/DynamicListAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
*/
class DynamicListAdmin extends ModelAdmin
{

private static $url_segment = 'dynamiclistadmin';
private static $menu_title = "Dynamic Lists";

private static $managed_models = array(DynamicList::class);
private static $model_importers = array(
DynamicList::class => DynamicListCsvLoader::class,
);
private static $managed_models = [
DynamicList::class
];

private static $model_importers = [
DynamicList::class => DynamicListCsvLoader::class
];
}
29 changes: 14 additions & 15 deletions src/dataobjects/DynamicList.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
*/
class DynamicList extends DataObject
{

private static $table_name = 'DynamicList';
private static $db = array(

private static $db = [
'Title' => 'Varchar(128)',
'CachedItems' => 'Text',
);
'CachedItems' => 'Text'
];

private static $has_many = [
'Items' => DynamicListItem::class
];

private static $has_many = array(
'Items' => DynamicListItem::class,
);

/**
* Should list items be cached?
*
Expand All @@ -41,9 +40,9 @@ class DynamicList extends DataObject
public function getCMSFields()
{
$fields = parent::getCMSFields();

$fields->removeByName('CachedItems');

if ($this->ID) {
$orderableComponent = new GridFieldOrderableRows('Sort');
$conf=GridFieldConfig_RelationEditor::create(20);
Expand All @@ -52,7 +51,7 @@ public function getCMSFields()
}

// Allow extension.

$this->extend('updateDynamicListCMSFields', $fields);
return $fields;
}
Expand Down Expand Up @@ -96,7 +95,7 @@ public function canDelete($member = null)
* @param Member $member
* @return boolean
*/
public function canCreate($member = null, $context = array())
public function canCreate($member = null, $context = [])
{
return Permission::check('CMS_ACCESS_Symbiote\DynamicLists\DynamicListAdmin', 'any', $member);
}
Expand Down Expand Up @@ -132,13 +131,13 @@ public function cacheListData()
{
$items = $this->Items();
if ($items) {
$mapped = array();
$mapped = [];
foreach ($items as $i) {
$mapped[$i->ID] = $i->Title;
}
}
}

/**
* Get a map of ID => Title for the contained items in this list
*/
Expand Down
27 changes: 13 additions & 14 deletions src/dataobjects/DynamicListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@
*/
class DynamicListItem extends DataObject
{

private static $table_name = 'DynamicListItem';
private static $db = array(

private static $db = [
'Title' => 'Varchar(128)',
'Sort' => 'Int',
);
'Sort' => 'Int'
];

private static $has_one = array(
private static $has_one = [
'List' => DynamicList::class
);
];

private static $summary_fields = array(
private static $summary_fields = [
'Title'
);
];

private static $default_sort = 'Sort, ID';


public function getCMSFields()
{
Expand All @@ -50,7 +49,7 @@ public function onBeforeWrite()
// $this->Sort = DB::query("SELECT MAX(\"Sort\") + 1 FROM \"DynamicListItem\" WHERE \"ListID\" = $parentID")->value();
// }
}

public function onAfterWrite()
{
if ($list = $this->List()) {
Expand All @@ -59,12 +58,12 @@ public function onAfterWrite()
}
}
}

public function canView($member = null)
{
return true;
}

/**
* @param Member $member
* @return boolean
Expand All @@ -89,7 +88,7 @@ public function canDelete($member = null)
* @param Member $member
* @return boolean
*/
public function canCreate($member = null, $context = array())
public function canCreate($member = null, $context = [])
{
return Permission::check('CMS_ACCESS_Symbiote\DynamicLists\DynamicListAdmin', 'any', $member);
}
Expand Down
32 changes: 22 additions & 10 deletions src/editableformfields/EditableDependentDynamicListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@

class EditableDependentDynamicListField extends EditableDropdown
{
private static $db = array(
'SourceList' => 'Varchar(512)',
);
private static $db = [
'SourceList' => 'Varchar(512)'
];

private static $table_name = 'EditableDependentDynamicListField';

Expand All @@ -69,15 +69,22 @@ public function getCMSFields()
// select another form field that has the titles of the lists to use for this list when displayed
// The assumption being made here is that each entry in the source list has a corresponding dynamic list
// defined for it, which we use later on.
$options = array();
$options = [];
if ($this->Parent()) {
$sourceList = $this->Parent()->Fields();
if ($sourceList) {
$options = $sourceList->map('Name', 'Title');
}
}

$fields->addFieldToTab('Root.Main', DropdownField::create('SourceList', _t('EditableDependentDynamicListField.SOURCE_LIST_TITLE', 'Source List'), $options));
$fields->addFieldToTab(
'Root.Main',
DropdownField::create(
'SourceList',
_t('EditableDependentDynamicListField.SOURCE_LIST_TITLE', 'Source List'),
$options
)
);

return $fields;
}
Expand All @@ -96,7 +103,7 @@ public function getFormField()
}
}

$optionLists = array();
$optionLists = [];
if ($source) {
// all our potential lists come from the source list's dynamic list source, so we need to go load that
// first, then iterate it and build all the additional required lists
Expand All @@ -115,19 +122,24 @@ public function getFormField()
}

if (count($optionLists)) {
$field = DependentDynamicListDropdownField::create($this->Name, $this->Title, $optionLists, $source->Name)->addExtraClass('uf-dependentdynamiclistdropdown');
$field = DependentDynamicListDropdownField::create(
$this->Name,
$this->Title,
$optionLists,
$source->Name
)->addExtraClass('uf-dependentdynamiclistdropdown');
} else {
$field = DropdownField::create($this->Name, $this->Title, array());
$field = DropdownField::create($this->Name, $this->Title, []);
}
$field
->setFieldHolderTemplate(EditableFormField::class . '_holder')
->setTemplate(__CLASS__);
->setTemplate(self::class);
$this->doUpdateFormField($field);
return $field;
}


// return a new list
return new LiteralField($this->Name);
return LiteralField::create($this->Name, 'no source list found');
}
}
26 changes: 17 additions & 9 deletions src/editableformfields/EditableDynamicListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@

class EditableDynamicListField extends EditableDropdown
{

private static $db = array(
'ListTitle' => 'Varchar(512)',
);
private static $db = [
'ListTitle' => 'Varchar(512)'
];

private static $table_name = 'EditableDynamicListField';

Expand All @@ -63,29 +62,38 @@ public function getHasAddableOptions()
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->removeByName(array('Options'));
$fields->removeByName(['Options']);

// get a list of data lists to select from
$allLists = DataObject::get(DynamicList::class);

$options = array('Please create a DynamicList!' => '(No DynamicLists available)');
$options = [
'Please create a DynamicList!' => '(No DynamicLists available)'
];

if ($allLists) {
/* @var $allLists DataObjectSet */
$options = $allLists->map('Title', 'Title');
}

$fields->addFieldToTab('Root.Main', DropdownField::create('ListTitle', _t('EditableDataListField.DYNAMICLIST_TITLE', 'List Title'), $options));
$fields->addFieldToTab(
'Root.Main',
DropdownField::create(
'ListTitle',
_t('EditableDataListField.DYNAMICLIST_TITLE', 'List Title'),
$options
)
);
return $fields;
}

public function getFormField()
{
$field = DynamicListField::create($this->Name, $this->Title, $this->ListTitle)
->setFieldHolderTemplate(EditableFormField::class . '_holder')
->setTemplate(__CLASS__);
->setTemplate(self::class);
if ($this->UseEmptyString) {
$field->setEmptyString(($this->EmptyString) ? $this->EmptyString : '');
$field->setEmptyString($this->EmptyString ?: '');
}
$this->doUpdateFormField($field);
return $field;
Expand Down
Loading

0 comments on commit 89dd48a

Please sign in to comment.