Merge pull request #2247 from open-sausages/pulls/4.2/2227-show-link-tracking

API: Add `show_link_tracking` config to `SiteTreeLinkTracking` extension
This commit is contained in:
Luke Edwards 2018-09-13 14:23:54 +12:00 committed by GitHub
commit aa3760ed66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -4,3 +4,8 @@ Name: cmslinktracking
SilverStripe\ORM\DataObject: SilverStripe\ORM\DataObject:
extensions: extensions:
- SilverStripe\CMS\Model\SiteTreeLinkTracking - 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 DOMElement;
use SilverStripe\Assets\Shortcodes\FileLinkTracking; use SilverStripe\Assets\Shortcodes\FileLinkTracking;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\FormScaffolder;
use SilverStripe\ORM\DataExtension; use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBHTMLText; 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 * Parser for link tracking
* *
@ -194,4 +205,13 @@ class SiteTreeLinkTracking extends DataExtension
$domReference->removeAttribute('class'); $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);
}
}
} }