Last active
January 31, 2018 04:30
-
-
Save zanderwar/73ba907fe56b18f183bccc87cfbb4014 to your computer and use it in GitHub Desktop.
Just in case someone else wants to use HTMLText in DataObjects and be able to publish the images that clients can upload into TinyMCE - SilverStripe 4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Vulcan\Common\Traits; | |
use SilverStripe\Assets\File; | |
use SilverStripe\Forms\FieldList; | |
use SilverStripe\ORM\HasManyList; | |
/** | |
* Trait DataObjectLinkTracking | |
* @package Vulcan\Common\Traits | |
* | |
* @method void augmentSyncLinkTracking | |
* @method HasManyList|File[] ImageTracking | |
*/ | |
trait DataObjectLinkTracking | |
{ | |
/** | |
* Remove fields added by SiteTreeLinkTracking | |
* | |
* @param FieldList $fields | |
*/ | |
public function removeTrackingFields(FieldList $fields) | |
{ | |
$fields->removeByName(['LinkTracking', 'ImageTracking', 'BackLinkTracking', 'HasBrokenFile', 'HasBrokenLink']); | |
} | |
/** | |
* Call in onBeforeWrite of parent | |
*/ | |
public function trackDataObjectLinks() | |
{ | |
$this->augmentSyncLinkTracking(); | |
} | |
/** | |
* Call in onAfterWrite of parent | |
*/ | |
public function publishTrackedImages() | |
{ | |
foreach ($this->ImageTracking() as $image) { | |
if (!$image->isPublished()) { | |
$image->publishSingle(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add to the
DataObject
: