Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow StaticPublishingTrigger to be added in DataExtensions #211

Open
4 tasks done
tiller1010 opened this issue Nov 12, 2024 · 1 comment
Open
4 tasks done

Allow StaticPublishingTrigger to be added in DataExtensions #211

tiller1010 opened this issue Nov 12, 2024 · 1 comment

Comments

@tiller1010
Copy link

tiller1010 commented Nov 12, 2024

Description

I would like to add StaticPublishingTrigger to a DataObject through a DataExtension, but StaticPublishingTrigger checks if the original DataObject implements StaticPublishingTrigger.

// I want the Resource DataObject to queue an update to its own URL when changed.
class ResourceExtension extends DataExtension implements StaticallyPublishable, StaticPublishingTrigger
{
  public function urlsToCache()
  {
    return [$this->owner->getDetailPageAbsoluteLink() => 0];
  }

  public function objectsToUpdate($context)
  {
    return $this->owner;
  }
}

What if there was a loop over extensions that checked for this interface?

$extensionImplementsInterface = false;
foreach ($siteTree->get_extensions() as $extension) {
    if (new $extension instanceof StaticPublishingTrigger) {
        $extensionImplementsInterface = true;
        break;
    }
}

// The page does not include the required extension, and it doesn't implement a Trigger
if (!$siteTree->hasExtension(PublishableSiteTree::class) && !($siteTree instanceof StaticPublishingTrigger) && !$extensionImplementsInterface) {
    return;
}

Additional context or points of discussion

This is how I have the extensions applied

---
Name: add_static_publishing_methods_to_resource
---
VendorName\ResourcePackage\Resources\Resource:
  extensions:
    - App\Resources\ResourceExtension

---
Name: update_resource_detail_on_change
After: add_static_publishing_methods_to_resource
---
VendorName\ResourcePackage\Resources\Resource:
  extensions:
    - SilverStripe\StaticPublishQueue\Extension\Engine\SiteTreePublishingEngine

Validations

  • You intend to implement the feature yourself
  • You have read the contributing guide
  • You strongly believe this feature should be in core, rather than being its own community module
  • You have checked for existing issues or pull requests related to this feature (and didn't find any)
@GuySartorelli
Copy link
Member

GuySartorelli commented Nov 14, 2024

What if there was a loop over extensions that checked for this interface?

Not neecssary - you can do $record->hasExtension(StaticPublishingTrigger::class) which will check for extensions that implement that interface.

Assuming implementing the interface on an extension class actually works, I see no reason not to allow this. Feel free to submit a PR including unit tests that validate triggers work as expected when provided through an extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants