Skip to content

Commit

Permalink
Move method from action into class
Browse files Browse the repository at this point in the history
  • Loading branch information
aerni committed Jun 22, 2024
1 parent 102ef5c commit 17e1864
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 41 deletions.
39 changes: 0 additions & 39 deletions src/Actions/ShouldProcessViewCascade.php

This file was deleted.

34 changes: 32 additions & 2 deletions src/View/CascadeComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Statamic\Tags\Context;
use Statamic\Facades\Cascade;
use Illuminate\Contracts\View\View;
use Aerni\AdvancedSeo\Actions\ShouldProcessViewCascade;
use Aerni\AdvancedSeo\Support\Helpers;

class CascadeComposer
{
Expand All @@ -17,7 +17,7 @@ public function compose(View $view): void
$context = $this->getContextFromCascade($context);
}

if (! ShouldProcessViewCascade::handle($context)) {
if (! $this->shouldProcessCascade($context)) {
return;
}

Expand All @@ -38,4 +38,34 @@ protected function getContextFromCascade(Context $context): Context

return $context->merge($cascade->toArray());
}

protected function shouldProcessCascade(Context $context): bool
{
// Don't process the cascade if it has been processed before.
if ($context->has('seo')) {
return false;
}

// Don't process the cascade for collections that are excluded in the config.
if ($context->has('is_entry') && in_array($context->get('collection')->raw()->handle(), config('advanced-seo.disabled.collections', []))) {
return false;
}

// Don't process the cascade for taxonomy terms that are excluded in the config.
if ($context->has('is_term') && in_array($context->get('taxonomy')->raw()->handle(), config('advanced-seo.disabled.taxonomies', []))) {
return false;
}

// Don't process the cascade for taxonomies that are excluded in the config.
if ($context->has('terms') && in_array($context->get('handle')->raw(), config('advanced-seo.disabled.taxonomies', []))) {
return false;
}

// Don't process the cascade for any custom route that doesn't explicitly want to use Advanced SEO.
if (Helpers::isCustomRoute() && ! $context->bool('seo_enabled')) {
return false;
}

return true;
}
}

0 comments on commit 17e1864

Please sign in to comment.