Skip to content

Commit

Permalink
Merge pull request #157 from creative-commoners/pulls/4/used-on
Browse files Browse the repository at this point in the history
ENH Used on table extension
  • Loading branch information
GuySartorelli authored Jan 9, 2024
2 parents 02ed5e5 + 0ea34be commit 3f90aeb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ Name: linkfield
SilverStripe\Admin\LeftAndMain:
extensions:
- SilverStripe\LinkField\Extensions\LeftAndMainExtension
SilverStripe\Admin\Forms\UsedOnTable:
extensions:
- SilverStripe\LinkField\Extensions\UsedOnTableExtension
32 changes: 32 additions & 0 deletions src/Extensions/UsedOnTableExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace SilverStripe\LinkField\Extensions;

use DNADesign\Elemental\Models\BaseElement;
use DNADesign\Elemental\TopPage\DataExtension as TopPageExtension;
use SilverStripe\Core\Extension;
use SilverStripe\LinkField\Models\FileLink;
use SilverStripe\ORM\DataObject;

class UsedOnTableExtension extends Extension
{
public function updateUsageAncestorDataObjects(array &$ancestorDataObjects, DataObject $dataObject): void
{
if (!is_a($dataObject, FileLink::class)) {
return;
}
$owner = $dataObject->Owner();
if (!$owner?->exists()) {
return;
}
$ancestorDataObjects[] = $owner;
if (!class_exists(BaseElement::class) || !is_a($owner, BaseElement::class)) {
return;
}
$page = $owner->hasExtension(TopPageExtension::class) ? $owner->getTopPage() : $owner->getPage();
if (!$page?->exists()) {
return;
}
$ancestorDataObjects[] = $page;
}
}

0 comments on commit 3f90aeb

Please sign in to comment.