API: Add show_sitetree_link_tracking config to SiteTreeLinkTracking extension to control visibility of the Link Tracking tab

This commit is contained in:
bergice 2018-08-31 14:57:17 +12:00
parent 4c8a76f21e
commit 115ed92e0a
2 changed files with 25 additions and 0 deletions

View File

@ -4,3 +4,8 @@ Name: cmslinktracking
SilverStripe\ORM\DataObject:
extensions:
- SilverStripe\CMS\Model\SiteTreeLinkTracking
---
Name: cmslinktrackingvisibility
---
SilverStripe\Security\Member:
show_sitetree_link_tracking: true

View File

@ -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);
}
}
}