silverstripe-elemental-linkify inserts a link type into TinyMCE where you can choose Elemental elements to link to. It also ships with a DBField that inserts a DropdownField into the CMS allowing you to choose both Page links or Elemental links.
- silverstripe/cms ^5
composer require zazama/silverstripe-elemental-linkify
Click on the link type "Element" which will open this window.
It will show a Dropdown with formatting: "[Pagename] Elementname"
<?php
use SilverStripe\ORM\DataObject;
use Zazama\ElementalLinkify\Fields\DBElementalLinkifyShortcode;
use Zazama\ElementalLinkify\Fields\ElementalLinkifyDropdownField;
class Teaser extends DataObject {
// ...
private static $db = [
'TeaserLink' => DBElementalLinkifyShortcode::class
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
// TeaserLink will be auto populated, but you can insert the dropdown yourself with
$fields->addFieldToTab('Root.Something', ElementalLinkifyDropdownField::create('TeaserLink', 'TeaserLink'));
return $fields;
}
}