Skip to content

Commit

Permalink
NEW Add models for testing elemental searchable fields
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 18, 2024
1 parent b541c6f commit b203c66
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
41 changes: 41 additions & 0 deletions code/elemental/ElementalSearchableFieldsBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace SilverStripe\FrameworkTest\Elemental\Model;

use DNADesign\Elemental\Models\BaseElement;
use SilverStripe\Forms\SearchableDropdownField;
use SilverStripe\Forms\SearchableMultiDropdownField;

class ElementalSearchableFieldsBlock extends BaseElement
{
private static $table_name = 'ElementalSearchableFieldsBlock';

private static $has_one = [
'ElementalSearchableFieldsObject' => ElementalSearchableFieldsObject::class,
];

private static $has_many = [
'ElementalSearchableFieldsObjects' => ElementalSearchableFieldsObject::class,
];

public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->removeByName('ElementalSearchableFieldsObjectID');
$fields->addFieldToTab('Root.Main', SearchableDropdownField::create(
'ElementalSearchableFieldsObjectID',
'ElementalSearchableFieldsObject',
ElementalSearchableFieldsObject::get()
)
->setIsLazyLoaded(true)
);
$fields->addFieldToTab('Root.Main', SearchableMultiDropdownField::create(
'ElementalSearchableFieldsObjects',
'ElementalSearchableFieldsObjects',
ElementalSearchableFieldsObject::get()
)
->setIsLazyLoaded(true)
);
return $fields;
}
}
18 changes: 18 additions & 0 deletions code/elemental/ElementalSearchableFieldsObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace SilverStripe\FrameworkTest\Elemental\Model;

use SilverStripe\ORM\DataObject;

class ElementalSearchableFieldsObject extends DataObject
{
private static $db = [
'Title' => 'Varchar',
];

private static $table_name = 'ElementalSearchableFieldsObject';

private static $has_one = [
'ElementalSearchableFieldsBlock' => ElementalSearchableFieldsBlock::class,
];
}

0 comments on commit b203c66

Please sign in to comment.