From e0c9517cf1a72472fbaa0306bce1f28564b286cd Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Sun, 20 Jan 2019 12:35:25 -0600 Subject: [PATCH 1/2] add support for Elemental 4 --- README.md | 4 ++-- composer.json | 10 +++++----- src/Elements/ElementSponsor.php | 34 ++++++++++++++++++++++++++++----- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8c98811..ffcbd94 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ Sponsors element for the [SilverStripe Elemental](https://github.com/dnadesign/s ## Requirements -- SilverStripe ^4.0 -- SilverStripe Elemental ^2.0 +* silverstripe/recipe-cms: ^4@dev +* dnadesign/silverstripe-elemental: ^4@dev ## Installation diff --git a/composer.json b/composer.json index abae769..23bad4f 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "dynamic/silverstripe-elemental-sponsors", "type": "silverstripe-vendormodule", - "description": "A sponsors element for the SilverStripe Elemental module", + "description": "Display a list of sponsor logos with links.", "keywords": [ "silverstripe", "sponsors", @@ -16,9 +16,9 @@ } ], "require": { - "dnadesign/silverstripe-elemental": "^2@dev || ^3@dev", - "dynamic/silverstripe-elemental-baseobject": "^1@dev", - "silverstripe/recipe-cms": "^1@dev || ^4@dev", + "dnadesign/silverstripe-elemental": "^4@dev", + "dynamic/silverstripe-elemental-baseobject": "^2@dev", + "silverstripe/recipe-cms": "^4@dev", "silverstripe/vendor-plugin": "^1@dev", "symbiote/silverstripe-gridfieldextensions": "^3@dev" }, @@ -31,7 +31,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0.x-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { diff --git a/src/Elements/ElementSponsor.php b/src/Elements/ElementSponsor.php index c4d2174..09a2185 100644 --- a/src/Elements/ElementSponsor.php +++ b/src/Elements/ElementSponsor.php @@ -23,7 +23,7 @@ class ElementSponsor extends BaseElement /** * @var string */ - private static $icon = 'vendor/dnadesign/silverstripe-elemental/images/base.svg'; + private static $icon = 'font-icon-external-link'; /** * @var string @@ -73,11 +73,35 @@ class ElementSponsor extends BaseElement ); /** - * @return \SilverStripe\ORM\FieldType\DBHTMLText + * Set to false to prevent an in-line edit form from showing in an elemental area. Instead the element will be + * clickable and a GridFieldDetailForm will be used. + * + * @config + * @var bool */ - public function ElementSummary() + private static $inline_editable = false; + + /** + * @return string + */ + public function getSummary() + { + if ($this->Sponsors()->count() == 1) { + $label = ' sponsor'; + } else { + $label = ' sponsors'; + } + return DBField::create_field('HTMLText', $this->Sponsors()->count() . $label)->Summary(20); + } + + /** + * @return array + */ + protected function provideBlockSchema() { - return DBField::create_field('HTMLText', $this->Content)->Summary(20); + $blockSchema = parent::provideBlockSchema(); + $blockSchema['content'] = $this->getSummary(); + return $blockSchema; } /** @@ -99,7 +123,7 @@ function (FieldList $fields) { ->setRows(8); $fields->dataFieldByName('Limit') - ->setTitle('Sponsors to show') + ->setTitle('Number of sponsors to show') ->setDescription('0 will show all sponsors'); if ($this->exists()) { From 6a90a718c0c84ca92dc829cd697589178d893777 Mon Sep 17 00:00:00 2001 From: Jason Irish Date: Sun, 20 Jan 2019 12:46:00 -0600 Subject: [PATCH 2/2] test bugfix --- tests/Elements/ElementSponsorTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Elements/ElementSponsorTest.php b/tests/Elements/ElementSponsorTest.php index dcaab40..e674096 100644 --- a/tests/Elements/ElementSponsorTest.php +++ b/tests/Elements/ElementSponsorTest.php @@ -22,10 +22,10 @@ class ElementSponsorTest extends SapphireTest /** * */ - public function testElementSummary() + public function testGetSummary() { $element = $this->objFromFixture(ElementSponsor::class, 'one'); - $this->assertEquals($element->dbObject('Content')->Summary(20), $element->ElementSummary()); + $this->assertEquals('4 sponsors', $element->getSummary()); } /**