From f1f20f608e4f15d835e12869a5ae61a3da1de4d4 Mon Sep 17 00:00:00 2001 From: Grant Heggie Date: Thu, 23 May 2019 20:21:43 +1000 Subject: [PATCH 1/5] ADD: filter callback to ensure list items can be rendered (prevents an error when a child of a List Page is a Panel) --- src/Extensions/Lists/ListSourceExtension.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Extensions/Lists/ListSourceExtension.php b/src/Extensions/Lists/ListSourceExtension.php index 6566bcd..29d2b67 100644 --- a/src/Extensions/Lists/ListSourceExtension.php +++ b/src/Extensions/Lists/ListSourceExtension.php @@ -278,6 +278,13 @@ public function getListItems() $items = $items->reverse(); } + + // Ensure items can be rendered correctly + + $items = $items->filterByCallback(function ($item) { + return $item->hasMethod('setRenderer'); + }); + // Limit Items (if applicable): if ($limit = $this->owner->NumberOfItems) { From 0047d19f2d1a4726c98c8fc1090662ab38638bdb Mon Sep 17 00:00:00 2001 From: Grant Heggie Date: Thu, 14 Nov 2019 20:39:37 +1000 Subject: [PATCH 2/5] ADD: pass class ancestry to ContentComponent::renderWith() to allow subclass templates --- src/Components/ContentComponent.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/ContentComponent.php b/src/Components/ContentComponent.php index baaa9d0..0ae0fbf 100644 --- a/src/Components/ContentComponent.php +++ b/src/Components/ContentComponent.php @@ -307,7 +307,7 @@ public function getTitleLinked() */ public function renderSelf($layout = null, $title = null) { - return $this->getController()->renderWith(self::class); + return $this->getController()->renderWith(get_class($this)); } /** From 38d74680da3ed62f9881de35ba17f9ff85444771 Mon Sep 17 00:00:00 2001 From: Grant Heggie Date: Fri, 15 Nov 2019 08:34:34 +1000 Subject: [PATCH 3/5] FIX: generate ancestry correctly for template rendering --- src/Components/ContentComponent.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Components/ContentComponent.php b/src/Components/ContentComponent.php index 0ae0fbf..74b1815 100644 --- a/src/Components/ContentComponent.php +++ b/src/Components/ContentComponent.php @@ -307,7 +307,8 @@ public function getTitleLinked() */ public function renderSelf($layout = null, $title = null) { - return $this->getController()->renderWith(get_class($this)); + $ancestry = $this->getComponentAncestry(); + return $this->getController()->renderWith($ancestry); } /** From 75d274b5f6db76755cee3a3547fcefae1d092046 Mon Sep 17 00:00:00 2001 From: Grant Heggie Date: Fri, 13 Dec 2019 10:57:48 +1000 Subject: [PATCH 4/5] UPDATE: change getCMSFields generation to allow extensions to hook into fields --- src/Components/BaseListComponent.php | 286 +++++++++++++-------------- 1 file changed, 142 insertions(+), 144 deletions(-) diff --git a/src/Components/BaseListComponent.php b/src/Components/BaseListComponent.php index 22184a8..d70f72a 100644 --- a/src/Components/BaseListComponent.php +++ b/src/Components/BaseListComponent.php @@ -187,152 +187,150 @@ class BaseListComponent extends BaseComponent */ public function getCMSFields() { - // Obtain Field Objects (from parent): - $fields = parent::getCMSFields(); - - // Define Placeholders: - - $placeholderDefault = _t(__CLASS__ . '.DROPDOWNDEFAULT', '(default)'); - - // Create Style Fields: - - $fields->addFieldsToTab( - 'Root.Style', - [ - FieldSection::create( - 'ListStyle', - $this->fieldLabel('ListStyle'), - [ - DropdownField::create( - 'HeadingLevel', - $this->fieldLabel('HeadingLevel'), - $this->getTitleLevelOptions() - )->setEmptyString(' ')->setAttribute('data-placeholder', $placeholderDefault), - DropdownField::create( - 'ImageAlign', - $this->fieldLabel('ImageAlign'), - $this->getImageAlignOptions() - )->setEmptyString(' ')->setAttribute('data-placeholder', $placeholderDefault), - ColorField::create( - 'OverlayBackground', - $this->fieldLabel('OverlayBackground') - ), - ColorField::create( - 'OverlayForeground', - $this->fieldLabel('OverlayForeground') - ), - FontIconField::create( - 'OverlayIcon', - $this->fieldLabel('OverlayIcon') - ), - ColorField::create( - 'OverlayIconColor', - $this->fieldLabel('OverlayIconColor') - ), - FontIconField::create( - 'ButtonIcon', - $this->fieldLabel('ButtonIcon') - ) - ] - ) - ] - ); - - // Add List Style Fields: - - $fields->addFieldsToTab('Root.Style', $this->getListStyleFields()); - - // Create Options Fields: - - $fields->addFieldsToTab( - 'Root.Options', - [ - FieldSection::create( - 'ListOptions', - $this->fieldLabel('ListOptions'), - [ - DropdownField::create( - 'ShowImage', - $this->fieldLabel('ShowImage'), - $this->getShowOptions() - ), - DropdownField::create( - 'ShowHeader', - $this->fieldLabel('ShowHeader'), - $this->getShowOptions() - ), - DropdownField::create( - 'ShowDetails', - $this->fieldLabel('ShowDetails'), - $this->getShowOptions() - ), - DropdownField::create( - 'ShowSummary', - $this->fieldLabel('ShowSummary'), - $this->getShowOptions() - ), - DropdownField::create( - 'ShowContent', - $this->fieldLabel('ShowContent'), - $this->getShowOptions() - ), - DropdownField::create( - 'ShowFooter', - $this->fieldLabel('ShowFooter'), - $this->getShowOptions() - ), - TextField::create( - 'ButtonLabel', - $this->fieldLabel('ButtonLabel') - ), - CheckboxField::create( - 'ButtonLink', - $this->fieldLabel('ButtonLink') - ), - CheckboxField::create( - 'LinkTitles', - $this->fieldLabel('LinkTitles') - ), - CheckboxField::create( - 'HideNoDataMessage', - $this->fieldLabel('HideNoDataMessage') - ) - ] - ), - FieldSection::create( - 'ListImageOptions', - $this->fieldLabel('ListImageOptions'), - [ - DropdownField::create( - 'ImageLinksTo', - $this->fieldLabel('ImageLinksTo'), - $this->getImageLinksToOptions() - ), - CheckboxField::create( - 'OverlayImages', - $this->fieldLabel('OverlayImages') - ), - CheckboxField::create( - 'OverlayTitle', - $this->fieldLabel('OverlayTitle') - ), - CheckboxField::create( - 'LinkImages', - $this->fieldLabel('LinkImages') - ) - ] - ) - ] - ); - - // Add List Option Fields: - - $fields->addFieldsToTab('Root.Options', $this->getListOptionFields()); - - // Answer Field Objects: + $this->beforeUpdateCMSFields(function (FieldList $fields) { + + // Define Placeholders: + + $placeholderDefault = _t(__CLASS__ . '.DROPDOWNDEFAULT', '(default)'); + + // Create Style Fields: + + $fields->addFieldsToTab( + 'Root.Style', + [ + FieldSection::create( + 'ListStyle', + $this->fieldLabel('ListStyle'), + [ + DropdownField::create( + 'HeadingLevel', + $this->fieldLabel('HeadingLevel'), + $this->getTitleLevelOptions() + )->setEmptyString(' ')->setAttribute('data-placeholder', $placeholderDefault), + DropdownField::create( + 'ImageAlign', + $this->fieldLabel('ImageAlign'), + $this->getImageAlignOptions() + )->setEmptyString(' ')->setAttribute('data-placeholder', $placeholderDefault), + ColorField::create( + 'OverlayBackground', + $this->fieldLabel('OverlayBackground') + ), + ColorField::create( + 'OverlayForeground', + $this->fieldLabel('OverlayForeground') + ), + FontIconField::create( + 'OverlayIcon', + $this->fieldLabel('OverlayIcon') + ), + ColorField::create( + 'OverlayIconColor', + $this->fieldLabel('OverlayIconColor') + ), + FontIconField::create( + 'ButtonIcon', + $this->fieldLabel('ButtonIcon') + ) + ] + ) + ] + ); + + // Add List Style Fields: + + $fields->addFieldsToTab('Root.Style', $this->getListStyleFields()); + + // Create Options Fields: + + $fields->addFieldsToTab( + 'Root.Options', + [ + FieldSection::create( + 'ListOptions', + $this->fieldLabel('ListOptions'), + [ + DropdownField::create( + 'ShowImage', + $this->fieldLabel('ShowImage'), + $this->getShowOptions() + ), + DropdownField::create( + 'ShowHeader', + $this->fieldLabel('ShowHeader'), + $this->getShowOptions() + ), + DropdownField::create( + 'ShowDetails', + $this->fieldLabel('ShowDetails'), + $this->getShowOptions() + ), + DropdownField::create( + 'ShowSummary', + $this->fieldLabel('ShowSummary'), + $this->getShowOptions() + ), + DropdownField::create( + 'ShowContent', + $this->fieldLabel('ShowContent'), + $this->getShowOptions() + ), + DropdownField::create( + 'ShowFooter', + $this->fieldLabel('ShowFooter'), + $this->getShowOptions() + ), + TextField::create( + 'ButtonLabel', + $this->fieldLabel('ButtonLabel') + ), + CheckboxField::create( + 'ButtonLink', + $this->fieldLabel('ButtonLink') + ), + CheckboxField::create( + 'LinkTitles', + $this->fieldLabel('LinkTitles') + ), + CheckboxField::create( + 'HideNoDataMessage', + $this->fieldLabel('HideNoDataMessage') + ) + ] + ), + FieldSection::create( + 'ListImageOptions', + $this->fieldLabel('ListImageOptions'), + [ + DropdownField::create( + 'ImageLinksTo', + $this->fieldLabel('ImageLinksTo'), + $this->getImageLinksToOptions() + ), + CheckboxField::create( + 'OverlayImages', + $this->fieldLabel('OverlayImages') + ), + CheckboxField::create( + 'OverlayTitle', + $this->fieldLabel('OverlayTitle') + ), + CheckboxField::create( + 'LinkImages', + $this->fieldLabel('LinkImages') + ) + ] + ) + ] + ); + + // Add List Option Fields: + + $fields->addFieldsToTab('Root.Options', $this->getListOptionFields()); + }); - return $fields; + return parent::getCMSFields();; } /** From 1d30ebf0c2df296e6df8bba8b475c7fe9c67efff Mon Sep 17 00:00:00 2001 From: Grant Heggie Date: Thu, 9 Jan 2020 11:46:43 +1000 Subject: [PATCH 5/5] UPDATE: change getCMSFields so extension updates are done after the base fields are added --- src/Components/BaseComponent.php | 91 +++++++++++++--------------- src/Components/BaseListComponent.php | 5 -- 2 files changed, 43 insertions(+), 53 deletions(-) diff --git a/src/Components/BaseComponent.php b/src/Components/BaseComponent.php index 4dde343..d975b5e 100644 --- a/src/Components/BaseComponent.php +++ b/src/Components/BaseComponent.php @@ -19,6 +19,7 @@ use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\DropdownField; +use SilverStripe\Forms\FieldList; use SilverWare\Forms\FieldSection; use SilverWare\Model\Component; @@ -126,54 +127,48 @@ class BaseComponent extends Component */ public function getCMSFields() { - // Obtain Field Objects (from parent): - - $fields = parent::getCMSFields(); - - // Define Placeholder: - - $placeholder = _t(__CLASS__ . '.DROPDOWNDEFAULT', '(default)'); - - // Create Style Fields: - - $fields->addFieldsToTab( - 'Root.Style', - [ - FieldSection::create( - 'TitleStyle', - $this->fieldLabel('TitleStyle'), - [ - DropdownField::create( - 'TitleLevel', - $this->fieldLabel('TitleLevel'), - $this->getTitleLevelOptions() - )->setEmptyString(' ')->setAttribute('data-placeholder', $placeholder) - ] - ) - ] - ); - - // Create Options Fields: - - $fields->addFieldsToTab( - 'Root.Options', - [ - FieldSection::create( - 'TitleOptions', - $this->fieldLabel('TitleOptions'), - [ - CheckboxField::create( - 'HideTitle', - $this->fieldLabel('HideTitle') - ) - ] - ) - ] - ); - - // Answer Field Objects: - - return $fields; + $this->beforeUpdateCMSFields(function (FieldList $fields) { + + $placeholder = _t(__CLASS__ . '.DROPDOWNDEFAULT', '(default)'); + + // Create Style Fields: + $fields->addFieldsToTab( + 'Root.Style', + [ + FieldSection::create( + 'TitleStyle', + $this->fieldLabel('TitleStyle'), + [ + DropdownField::create( + 'TitleLevel', + $this->fieldLabel('TitleLevel'), + $this->getTitleLevelOptions() + )->setEmptyString(' ')->setAttribute('data-placeholder', $placeholder) + ] + ) + ] + ); + + // Create Options Fields: + $fields->addFieldsToTab( + 'Root.Options', + [ + FieldSection::create( + 'TitleOptions', + $this->fieldLabel('TitleOptions'), + [ + CheckboxField::create( + 'HideTitle', + $this->fieldLabel('HideTitle') + ) + ] + ) + ] + ); + + }); + + return parent::getCMSFields();; } /** diff --git a/src/Components/BaseListComponent.php b/src/Components/BaseListComponent.php index d70f72a..77d6494 100644 --- a/src/Components/BaseListComponent.php +++ b/src/Components/BaseListComponent.php @@ -191,11 +191,9 @@ public function getCMSFields() $this->beforeUpdateCMSFields(function (FieldList $fields) { // Define Placeholders: - $placeholderDefault = _t(__CLASS__ . '.DROPDOWNDEFAULT', '(default)'); // Create Style Fields: - $fields->addFieldsToTab( 'Root.Style', [ @@ -239,11 +237,9 @@ public function getCMSFields() ); // Add List Style Fields: - $fields->addFieldsToTab('Root.Style', $this->getListStyleFields()); // Create Options Fields: - $fields->addFieldsToTab( 'Root.Options', [ @@ -326,7 +322,6 @@ public function getCMSFields() ); // Add List Option Fields: - $fields->addFieldsToTab('Root.Options', $this->getListOptionFields()); });