Skip to content
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ class Page extends SiteTree

## Customising how DataObject look in the field

Any DataObject can be managed by the AnyField and ManyAnyField without any special tweaks. However, you can get a bit more value with some simple tweaks. Those tweaks can be applied with DataExtension.
Any DataObject can be managed by the AnyField and ManyAnyField without any special tweaks. However, you can get a bit more value with some simple tweaks. Those tweaks can be applied with Extension.

### Customising the Title

The AnyFields displays the selected DataObject title. By defining a `getTitle` method for DataObject class, you can customise the title displayed in the field.

### Showing a summary

The AnyFields displays the type of the selected DataObject below its title. You can also display a summary by implementing a `getSummary` method on your DataObject class. This can be done with a DataExtension as well.
The AnyFields displays the type of the selected DataObject below its title. You can also display a summary by implementing a `getSummary` method on your DataObject class. This can be done with a Extension as well.

### Showing an icon

Expand Down
2 changes: 1 addition & 1 deletion client/dist/js/bundle.js

Large diffs are not rendered by default.

18 changes: 12 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"description": "Add Silverstripe CMS field that can be used to manage any relation",
"type": "silverstripe-vendormodule",
"require": {
"php": "^8.1",
"silverstripe/framework": "^5",
"silverstripe/admin": "^2",
"php": "^8.3",
"silverstripe/framework": "^6",
"silverstripe/admin": "^3",
"silverstripe/graphql": "6.0.0-beta1",
"league/uri": "^7.1",
"league/uri-components": "^7.1",
"maxime-rainville/silverstripe-react": "^0.1"
"maxime-rainville/silverstripe-react": "dev-feature/cms-6"
},
"require-dev": {
"silverstripe/recipe-testing": "^3",
"squizlabs/php_codesniffer": "^3",
"maxime-rainville/anyfield-tester": "dev-master"
"squizlabs/php_codesniffer": "^3.7"
},
"license": "BSD-3-Clause",
"authors": [
Expand All @@ -39,6 +39,12 @@
"SilverStripe\\AnyField\\Tests\\Behat\\Context\\": "tests/behat/src/"
}
},
"repositories": {
"maxime-rainville/silverstripe-react": {
"type": "git",
"url": "https://github.com/silverstripe-terraformers/silverstripe-react.git"
}
},
"config": {
"process-timeout": 600
},
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
},
"devDependencies": {
"@babel/runtime": "^7.20.0",
"@silverstripe/eslint-config": "^1.0.0-alpha6",
"@silverstripe/webpack-config": "^2.0.0-alpha9",
"@silverstripe/eslint-config": "^1.3.0",
"@silverstripe/webpack-config": "^3.0.0-alpha4",
"@testing-library/jest-dom": "^5.17.0",
"autoprefixer": "^10.4.14",
"babel-jest": "^29.2.2",
Expand All @@ -71,6 +71,7 @@
"bootstrap": "^4.6.2",
"classnames": "^2.2.5",
"core-js": "^3.26.0",
"graphql": "^16.8.1",
"prop-types": "^15.8.1",
"qs": "^6.11.0",
"react-dnd": "^5.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Extensions/LeftAndMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
class LeftAndMain extends Extension
{
public function init()
public function onInit()
{
Requirements::add_i18n_javascript('maxime-rainville/anyfield:client/lang', false, true);
Requirements::javascript('maxime-rainville/anyfield:client/dist/js/bundle.js', ['defer' => true]);
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/Sortable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HiddenField;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Core\Extension;

/**
* Utility extension that can be added to DataObject managed through a ManyAnyField to
* make it easy to sort
*/
class Sortable extends DataExtension
class Sortable extends Extension
{

private static array $db = [
Expand Down
2 changes: 1 addition & 1 deletion src/Form/JsonField.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function getComponent(): string

public function InputValue(): string
{
$value = $this->Value();
$value = $this->getValue();

if ($value instanceof DataObject) {
$value = AnyService::singleton()->map($value);
Expand Down
4 changes: 2 additions & 2 deletions src/Form/ManyAnyField.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use SilverStripe\Control\Controller;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataObjectInterface;
use SilverStripe\ORM\SS_List;
use SilverStripe\Model\List\SS_List;

/**
* Allows CMS users to edit a list of links.
Expand Down Expand Up @@ -241,7 +241,7 @@ private function guessBaseClass(?DataObjectInterface $record = null): ?string

public function InputValue(): string
{
$value = $this->Value();
$value = $this->getValue();

if ($value instanceof SS_List) {
$value = AnyService::singleton()->jsonSerializeList($value);
Expand Down
2 changes: 1 addition & 1 deletion src/Services/AnyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use SilverStripe\Forms\Form;
use SilverStripe\Forms\HiddenField;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\SS_List;
use SilverStripe\Model\List\SS_List;

/**
* Service for managing the class definitions for the AnyField.
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Extensions/ModalControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private function assertField(FieldList $fields, string $name, string $fieldClass
$field = $fields->dataFieldByName($name);
$this->assertNotNull($field, "Field $name exists");
$this->assertInstanceOf($fieldClass, $field, "Field $name is a $fieldClass");
$this->assertEquals($value, $field->Value(), "Field $name has value $value");
$this->assertEquals($value, $field->getValue(), "Field $name has value $value");
}

public function testBadKey()
Expand Down
2 changes: 1 addition & 1 deletion tests/php/Form/AnyFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testSetValue()

$this->assertEquals(
$expected,
$field->Value(),
$field->getValue(),
"Setting AnyField value from $key works"
);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/php/Form/AnyFieldTest/ForcePermissionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use SilverStripe\Dev\TestOnly;
use SilverStripe\ORM\Connect\MySQLSchemaManager;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Core\Extension;

class ForcePermissionExtension extends DataExtension implements TestOnly
class ForcePermissionExtension extends Extension implements TestOnly
{

public static array $forcePermissionCheck = [
Expand Down
10 changes: 5 additions & 5 deletions tests/php/Form/ManyAnyFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function testSetValueWithListInConstructor()

$this->assertEquals(
$expectedValue,
$field->Value(),
$field->getValue(),
'Value should be deduct from the list when no other data is provided'
);
}
Expand All @@ -99,7 +99,7 @@ public function testSetValueWithImplicitList()

$this->assertEquals(
$expectedValue,
$field->Value(),
$field->getValue(),
'Value should be deduct from the list matching the field name when the list is not explicitly set'
);
}
Expand All @@ -113,7 +113,7 @@ public function testSetValueWithJSONString()

$this->assertEquals(
$expectedValue,
$field->Value(),
$field->getValue(),
'When the value is explicitly set to a JSON string, we don\'t read it from the data list'
);
}
Expand All @@ -126,7 +126,7 @@ public function testSetValueWithEmptyJSONString()

$this->assertEquals(
[],
$field->Value(),
$field->getValue(),
'When the value is explicitly set to empty JSON string, we get an empty list'
);
}
Expand All @@ -141,7 +141,7 @@ public function testSetValueWithExplicitList()

$this->assertEquals(
$expectedValue,
$field->Value(),
$field->getValue(),
'Value should be deduct from the list when no other data is provided'
);
}
Expand Down