HasOneSelector is a module that provides CMS field to manage data object defined in a has_one relation.
- SilverStripe CMS ^5.0
composer require moo/hasoneselector
use SilverStripe\ORM\DataObject;
use SilverStripe\CMS\Model\SiteTree;
use Moo\HasOneSelector\Form\Field;
class Resource extends DataObject
{
//...
}
class Page extends SiteTree
{
//...
private static $has_one = [
'Resource' => Resource::class,
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
$resource = Field::create('Resource', 'Resource', $this, Resource::class);
$fields->addFieldToTab('Root.Main', $resource);
return $fields;
}
//...
}
This module is under the MIT license. View the LICENSE file for the full copyright and license information.