Bolt\Controller\Frontend::taxonomy PHP Method

taxonomy() public method

The taxonomy listing page controller.
public taxonomy ( Request $request, string $taxonomytype, string $slug ) : TemplateResponse | false
$request Symfony\Component\HttpFoundation\Request The Symfony Request
$taxonomytype string The taxonomy type slug
$slug string The taxonomy slug
return Bolt\Response\TemplateResponse | false
    public function taxonomy(Request $request, $taxonomytype, $slug)
    {
        $taxonomy = $this->storage()->getTaxonomyType($taxonomytype);
        // No taxonomytype, no possible content.
        if (empty($taxonomy)) {
            return false;
        } else {
            $taxonomyslug = $taxonomy['slug'];
        }
        // First, get some content
        $context = $taxonomy['singular_slug'] . '_' . $slug;
        $page = $this->app['pager']->getCurrentPage($context);
        // Theme value takes precedence over default config @see https://github.com/bolt/bolt/issues/3951
        $amount = $this->getOption('theme/listing_records', false) ?: $this->getOption('general/listing_records');
        // Handle case where listing records has been override for specific taxonomy
        if (array_key_exists('listing_records', $taxonomy) && is_int($taxonomy['listing_records'])) {
            $amount = $taxonomy['listing_records'];
        }
        $order = $this->getOption('theme/listing_sort', false) ?: $this->getOption('general/listing_sort');
        $content = $this->storage()->getContentByTaxonomy($taxonomytype, $slug, ['limit' => $amount, 'order' => $order, 'page' => $page]);
        if (!$this->isTaxonomyValid($content, $slug, $taxonomy)) {
            $this->abort(Response::HTTP_NOT_FOUND, "No slug '{$slug}' in taxonomy '{$taxonomyslug}'");
            return;
        }
        $template = $this->templateChooser()->taxonomy($taxonomyslug);
        // Get a display value for slug. This should be moved from 'slug' context key to 'name' in v4.0.
        $name = $slug;
        if ($taxonomy['behaves_like'] !== 'tags' && isset($taxonomy['options'][$slug])) {
            $name = $taxonomy['options'][$slug];
        }
        $globals = ['records' => $content, 'slug' => $name, 'taxonomy' => $this->getOption('taxonomy/' . $taxonomyslug), 'taxonomytype' => $taxonomyslug];
        return $this->render($template, [], $globals);
    }