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

Fix taxonomy listing_template inconsistency. Fix the canonical for slug and singular_slug #2407

Merged
merged 1 commit into from
Feb 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/Controller/Frontend/TaxonomyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Bolt\Controller\Frontend;

use Bolt\Configuration\Content\TaxonomyType;
use Bolt\Controller\TwigAwareController;
use Bolt\Entity\Content;
use Bolt\Repository\ContentRepository;
Expand Down Expand Up @@ -31,12 +32,21 @@ public function listing(ContentRepository $contentRepository, string $taxonomysl
$page = (int) $this->getFromRequest('page', '1');
$amountPerPage = $this->config->get('general/listing_records');

$taxonomy = $this->config->getTaxonomy($taxonomyslug);
$taxonomy = TaxonomyType::factory($taxonomyslug, $this->config->get('taxonomies'));

/** @var Content[] $records */
$records = $contentRepository->findForTaxonomy($page, $taxonomy, $slug, $amountPerPage);

$templates = $this->templateChooser->forTaxonomy($taxonomyslug);
$this->canonical->setPath(
'taxonomy_locale',
[
'taxonomyslug' => $taxonomy->get('slug'),
'_locale' => $this->request->getLocale(),
'slug' => $slug,
]
);

$templates = $this->templateChooser->forTaxonomy($taxonomy);

$twigVars = [
'records' => $records,
Expand Down
4 changes: 2 additions & 2 deletions src/TemplateChooser.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public function forListing(ContentType $contentType): array
return $templates->unique()->filter()->toArray();
}

public function forTaxonomy(string $taxonomyslug): array
public function forTaxonomy(Collection $taxonomy): array
{
$templates = new Collection();

// First candidate: defined specifically in the taxonomy
$templates->push($this->config->get('taxonomies/' . $taxonomyslug . '/listing_template'));
$templates->push($taxonomy->get('listing_template', null));

// Second candidate: Theme-specific config.yml file.
$templates->push($this->config->get('theme/listing_template'));
Expand Down