Source of file FrontEndEditHasOne.php
Size: 1,646 Bytes - Last Modified: 2021-12-23T10:41:44+00:00
/var/www/docs.ssmods.com/process/src/code/forms/fields/FrontEndEditHasOne.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 | <?php /** * creates an edit or add * field for an has one relation. * * */ class FrontEndEditHasOne extends FormField { private $hasOneRelationRecord = null; private $originatingRecord = null; public function __construct($fieldName, $title, $originatingRecord, $hasOneRelationRecord) { $this->hasOneRelationRecord = $hasOneRelationRecord; $this->originatingRecord = $originatingRecord; return parent::__construct($fieldName, $title); } public function Field($properties = []) { $Link = ""; $title = ""; if ($this->hasOneRelationRecord && $this->hasOneRelationRecord->exists()) { if ($this->hasOneRelationRecord->canEdit()) { $link = $this->hasOneRelationRecord->FrontEndEditLink(); if ($this->hasOneRelationRecord instanceof FrontEndEditable) { $title = $this->hasOneRelationRecord->FrontEndShortTitle(); } else { $title = "edit ".$this->hasOneRelationRecord->getTitle(); } } } else { $hasOneFields = $this->originatingRecord->hasOne(); $model = $hasOneFields[$this->getName()]; $this->hasOneRelationRecord = Injector::inst()->create($model); if ($this->hasOneRelationRecord->canCreate()) { $link = $this->hasOneRelationRecord->FrontEndEditLink(); $title = "add "; } } if ($link && $title) { return "<p><a href=\"".$link."\">".$title."</a></p>"; } else { return ""; } } } |