Skip to content

Commit

Permalink
Merge pull request silverstripe#2247 from open-sausages/pulls/4.2/222…
Browse files Browse the repository at this point in the history
…7-show-link-tracking

API: Add `show_link_tracking` config to `SiteTreeLinkTracking` extension
  • Loading branch information
Luke Edwards authored Sep 13, 2018
2 parents c75c629 + 115ed92 commit aa3760e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions _config/linktracking.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ Name: cmslinktracking
SilverStripe\ORM\DataObject:
extensions:
- SilverStripe\CMS\Model\SiteTreeLinkTracking
---
Name: cmslinktrackingvisibility
---
SilverStripe\Security\Member:
show_sitetree_link_tracking: true
20 changes: 20 additions & 0 deletions code/Model/SiteTreeLinkTracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

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;
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -194,4 +205,13 @@ protected function toggleElementClass(DOMElement $domReference, $class, $toggle)
$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);
}
}
}

0 comments on commit aa3760e

Please sign in to comment.