moo/hasoneselector

This module provides CMS field to manage data object defined in a has_one relation.

2.0.0 2018-07-11 10:25 UTC

README

SensioLabsInsight Code Coverage Build Status Scrutinizer Code Quality Latest Stable Version License

HasOneSelector is a module that provides CMS field to manage data object defined in a has_one relation.

Requirements

  • SilverStripe CMS ^4.1

For a SilverStripe 3.x compatible version, please see the 3.x branch, or 1.x releases.

Installation via Composer

composer require moo/hasoneselector

Usage


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;
    }

    //...
}

License

This module is under the MIT license. View the LICENSE file for the full copyright and license information.