From 1513d51a42f853dd67b5677d8e982e3eaa1d8457 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 20 Jun 2024 11:31:43 +1200 Subject: [PATCH 1/2] NEW Add models for testing elemental searchable fields --- .../ElementalSearchableFieldsBlock.php | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 code/elemental/ElementalSearchableFieldsBlock.php diff --git a/code/elemental/ElementalSearchableFieldsBlock.php b/code/elemental/ElementalSearchableFieldsBlock.php new file mode 100644 index 0000000..60943ba --- /dev/null +++ b/code/elemental/ElementalSearchableFieldsBlock.php @@ -0,0 +1,48 @@ + Company::class, + ]; + + private static $many_many = [ + 'Companys' => Company::class, + ]; + + public function getCMSFields() + { + $fields = parent::getCMSFields(); + $fields->removeByName('CompanyID'); + $fields->addFieldToTab('Root.Main', SearchableDropdownField::create( + 'CompanyID', + 'Company', + Company::get() + ) + ->setLabelField('Name') + ->setIsLazyLoaded(true) + ); + $fields->addFieldToTab('Root.Main', SearchableMultiDropdownField::create( + 'Companys', + 'Companys', + Company::get() + ) + ->setLabelField('Name') + ->setIsLazyLoaded(true) + ); + return $fields; + } +} From b63af3c79e359287d754bf292cd2acc4a87661b0 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Fri, 21 Jun 2024 17:28:27 +1200 Subject: [PATCH 2/2] FIX Check that elemental is installed --- code/elemental/ElementalSearchableFieldsBlock.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/code/elemental/ElementalSearchableFieldsBlock.php b/code/elemental/ElementalSearchableFieldsBlock.php index 60943ba..00e518e 100644 --- a/code/elemental/ElementalSearchableFieldsBlock.php +++ b/code/elemental/ElementalSearchableFieldsBlock.php @@ -7,6 +7,10 @@ use SilverStripe\Forms\SearchableDropdownField; use SilverStripe\Forms\SearchableMultiDropdownField; use SilverStripe\FrameworkTest\Model\Company; +if (!class_exists(BaseElement::class)) { + return; +} + class ElementalSearchableFieldsBlock extends BaseElement { private static $table_name = 'ElementalSearchableFieldsBlock';