| Conditions | 6 |
| Paths | 6 |
| Total Lines | 20 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | public static function add_link(FormField $field, DataObject $object) |
||
| 12 | { |
||
| 13 | $dbFieldNameWithID = $field->getName(); |
||
| 14 | $dbFieldName = substr((string) $dbFieldNameWithID, 0, -2); |
||
| 15 | $options = $object->config()->get('has_one'); |
||
| 16 | $className = $options[$dbFieldName] ?? ''; |
||
| 17 | if ($className) { |
||
| 18 | $linkedObject = $object->{$dbFieldName}(); |
||
| 19 | if ($linkedObject->canEdit()) { |
||
| 20 | $link = ''; |
||
| 21 | $linkAsHtml = ''; |
||
| 22 | //@TODO: add other methods... see Sunnysideup\CmsEditLinkField\Forms\Fields\CMSEditLinkField |
||
| 23 | if ($linkedObject->exists() && $linkedObject->hasMethod('CMSEditLink')) { |
||
| 24 | $link = $linkedObject->CMSEditLink(); |
||
| 25 | $linkAsHtml = ' |
||
| 26 | <a href="' . $link . '" style="text-decoration: none!important;">✎ edit ' . $linkedObject->getTitle() . '</a><br />'; |
||
| 27 | } |
||
| 28 | |||
| 29 | if ($link) { |
||
| 30 | $field->setRightTitle(DBHTMLVarchar::create_field(DBHTMLVarchar::class, $linkAsHtml)); |
||
| 31 | } |
||
| 36 |