Source of file HasOnePickerField.php
Size: 1,624 Bytes - Last Modified: 2021-12-23T10:51:29+00:00
/var/www/docs.ssmods.com/process/src/code/HasOnePickerField.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344 | <?php namespace TheWebmen\PickerField\Controllers; use SilverStripe\Forms\GridField\GridFieldPaginator; use SilverStripe\ORM\DataObject; class HasOnePickerField extends PickerField { public $isHaveOne = true; public $childObject; /** * Usage [e.g. in getCMSFields] * $field = new HasOnePickerField($this, 'DamID', 'Selected Dam', $this->Dam(), 'Select a Dam'); * * @param DataObject $childObject - The DataObject we are manipulating with this field: typically $this via getCMSFields * @param string $name - Field Name of has_one relationship (e.g. DamID, SireID, etc.): ensure 'ID' suffix * @param string $title - GridField Title * @param Object $currentHasOne - Result of the current has_one relationship method (E.g. $this->HasOneMethod()) * @param string $linkExistingTitle - AddExisting Button Title */ public function __construct(DataObject $childObject, $name, $title = null, $currentHasOne, $linkExistingTitle = null, $searchContext = null) { $modelClass = $childObject->getRelationClass(str_replace('ID', '', $name)); if(!$modelClass) { $modelClass = $currentHasOne->className; } $this->setModelClass($modelClass); $this->childObject = $childObject; // convert the has_one relation getter to a DataList / SS_List $dataList = $modelClass::get()->filter(array('ID' => $currentHasOne->ID)); // construct the PickerField parent::__construct($name, $title, $dataList, $linkExistingTitle); // remove components non-applicable to has_one relationships $this->getConfig()->removeComponentsByType(GridFieldPaginator::class); } } |