diff --git a/_config/linktracking.yml b/_config/linktracking.yml index a08daf78..12065ad9 100644 --- a/_config/linktracking.yml +++ b/_config/linktracking.yml @@ -4,3 +4,8 @@ Name: cmslinktracking SilverStripe\ORM\DataObject: extensions: - SilverStripe\CMS\Model\SiteTreeLinkTracking +--- +Name: cmslinktrackingvisibility +--- +SilverStripe\Security\Member: + show_sitetree_link_tracking: true diff --git a/code/Model/SiteTreeLinkTracking.php b/code/Model/SiteTreeLinkTracking.php index d6e1d483..c3c2111d 100644 --- a/code/Model/SiteTreeLinkTracking.php +++ b/code/Model/SiteTreeLinkTracking.php @@ -4,6 +4,8 @@ namespace SilverStripe\CMS\Model; use DOMElement; use SilverStripe\Assets\Shortcodes\FileLinkTracking; +use SilverStripe\Forms\FieldList; +use SilverStripe\Forms\FormScaffolder; use SilverStripe\ORM\DataExtension; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\FieldType\DBHTMLText; @@ -52,6 +54,15 @@ class SiteTreeLinkTracking extends DataExtension ], ]; + /** + * Controls visibility of the Link Tracking tab + * + * @config + * @see linktracking.yml + * @var boolean + */ + private static $show_sitetree_link_tracking = false; + /** * Parser for link tracking * @@ -194,4 +205,13 @@ class SiteTreeLinkTracking extends DataExtension $domReference->removeAttribute('class'); } } + + public function updateCMSFields(FieldList $fields) + { + if (!$this->owner->config()->get('show_sitetree_link_tracking')) { + $fields->removeByName('LinkTracking'); + } elseif ($this->owner->ID && !$this->owner->getField('LinkTracking')) { + FormScaffolder::addManyManyRelationshipFields($fields, 'LinkTracking', null, true, $this->owner); + } + } }