Sha256: 9cb61616f93d28e89169f2cf1f7c3c6b52dec090bc92c4946e412bae6d10f3c7

Contents?: true

Size: 1.56 KB

Versions: 13

Compression:

Stored size: 1.56 KB

Contents

<?php
namespace Grav\Plugin;

use Grav\Common\Plugin;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
use Grav\Common\Page\Pages;
use Grav\Common\Page\Types;
use RocketTheme\Toolbox\Event\Event;

class ErrorPlugin extends Plugin
{
    /**
     * @return array
     */
    public static function getSubscribedEvents()
    {
        return [
            'onPageNotFound' => ['onPageNotFound', 0],
            'onGetPageTemplates' => ['onGetPageTemplates', 0],
            'onTwigTemplatePaths' => ['onTwigTemplatePaths', -10]
        ];
    }

    /**
     * Display error page if no page was found for the current route.
     *
     * @param Event $event
     */
    public function onPageNotFound(Event $event)
    {
        /** @var Pages $pages */
        $pages = $this->grav['pages'];

        // Try to load user error page.
        $page = $pages->dispatch($this->config->get('plugins.error.routes.404', '/error'), true);

        if (!$page) {
            // If none provided use built in error page.
            $page = new Page;
            $page->init(new \SplFileInfo(__DIR__ . '/pages/error.md'));
        }

        $event->page = $page;
        $event->stopPropagation();
    }

    /**
     * Add page template types.
     */
    public function onGetPageTemplates(Event $event)
    {
        /** @var Types $types */
        $types = $event->types;
        $types->register('error');
    }

    /**
     * Add current directory to twig lookup paths.
     */
    public function onTwigTemplatePaths()
    {
        $this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
    }
}

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
card-mod-bootstrap-0.18.1 vendor/select2/docs/plugins/error/error.php
card-mod-bootstrap-0.18.0 vendor/select2/docs/plugins/error/error.php
card-mod-bootstrap-0.17.0 vendor/select2/docs/plugins/error/error.php
card-mod-bootstrap-0.16.0 vendor/select2/docs/plugins/error/error.php
card-mod-bootstrap-0.15.6 vendor/select2/docs/plugins/error/error.php
card-mod-bootstrap-0.15.5 vendor/select2/docs/plugins/error/error.php
card-mod-bootstrap-0.15.4 vendor/select2/docs/plugins/error/error.php
card-mod-bootstrap-0.15.3 vendor/select2/docs/plugins/error/error.php
card-mod-bootstrap-0.15.1.2 vendor/select2/docs/plugins/error/error.php
card-mod-bootstrap-0.15.2.pre1 vendor/select2/docs/plugins/error/error.php
card-mod-bootstrap-0.15.1.1 vendor/select2/docs/plugins/error/error.php
card-mod-bootstrap-0.15.1 vendor/select2/docs/plugins/error/error.php
card-mod-bootstrap-0.15.0 vendor/select2/docs/plugins/error/error.php