moo/hasoneselector

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

Installs: 21 446

Dependents: 1

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 5

Open Issues: 0

Type:silverstripe-vendormodule

3.0.0 2022-07-10 01:48 UTC

README

Build Status Code Coverage 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 ^5.0

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.