src/Twigpack.php
protected function installEventListeners()
    {
        // Remember the name of the currently rendering template
        // Handler: View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE
        Event::on(
            View::class,
            View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE,
            function (TemplateEvent $event) {
                self::$templateName = $event->template;
            }
        );
        // Handler: CraftVariable::EVENT_INIT
        Event::on(
            CraftVariable::class,
            CraftVariable::EVENT_INIT,
            function (Event $event) {
                /** @var CraftVariable $variable */
                $variable = $event->sender;
                $variable->set('twigpack', ManifestVariable::class);
            }
        );
        // Handler: TemplateCaches::EVENT_AFTER_DELETE_CACHES
        Event::on(
            TemplateCaches::class,
            TemplateCaches::EVENT_AFTER_DELETE_CACHES,
            function (DeleteTemplateCachesEvent $event) {
                // Invalidate the caches when template caches are deleted
                $this->clearAllCaches();
            }
        );
        // Handler: Plugins::EVENT_AFTER_INSTALL_PLUGIN
        Event::on(
            Plugins::class,
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
            function (PluginEvent $event) {
                if ($event->plugin === $this) {
                    // Invalidate our caches after we've been installed
                    $this->clearAllCaches();
                }
            }
        );
        // Handler: ClearCaches::EVENT_REGISTER_CACHE_OPTIONS
        Event::on(
            ClearCaches::class,
            ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
            function (RegisterCacheOptionsEvent $event) {
                Craft::debug(
                    'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS',
                    __METHOD__
                );
                // Register our caches for the Clear Cache Utility
                $event->options = array_merge(
                    $event->options,
                    $this->customAdminCpCacheOptions()
                );
            }
        );
        // delay attaching event handler to the view component after it is fully configured
        $app = Craft::$app;
        if ($app->getConfig()->getGeneral()->devMode) {
            $app->on(Application::EVENT_BEFORE_REQUEST, function () use ($app) {
                $app->getView()->on(View::EVENT_END_BODY, [$this, 'injectErrorEntry']);
            });
        }
    }
protected function installEventListeners()
    {
        // Remember the name of the currently rendering template
        // Handler: View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE
        Event::on(
            View::class,
            View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE,
            function (TemplateEvent $event) {
                self::$templateName = $event->template;
            }
        );
        // Handler: CraftVariable::EVENT_INIT
        Event::on(
            CraftVariable::class,
            CraftVariable::EVENT_INIT,
            function (Event $event) {
                /** @var CraftVariable $variable */
                $variable = $event->sender;
                $variable->set('twigpack', ManifestVariable::class);
            }
        );
        // Handler: TemplateCaches::EVENT_AFTER_DELETE_CACHES
        Event::on(
            TemplateCaches::class,
            TemplateCaches::EVENT_AFTER_DELETE_CACHES,
            function (DeleteTemplateCachesEvent $event) {
                // Invalidate the caches when template caches are deleted
                $this->clearAllCaches();
            }
        );
        // Handler: Plugins::EVENT_AFTER_INSTALL_PLUGIN
        Event::on(
            Plugins::class,
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
            function (PluginEvent $event) {
                if ($event->plugin === $this) {
                    // Invalidate our caches after we've been installed
                    $this->clearAllCaches();
                }
            }
        );
        // Handler: ClearCaches::EVENT_REGISTER_CACHE_OPTIONS
        Event::on(
            ClearCaches::class,
            ClearCaches::EVENT_REGISTER_CACHE_OPTIONS,
            function (RegisterCacheOptionsEvent $event) {
                Craft::debug(
                    'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS',
                    __METHOD__
                );
                // Register our caches for the Clear Cache Utility
                $event->options = array_merge(
                    $event->options,
                    $this->customAdminCpCacheOptions()
                );
            }
        );
        // delay attaching event handler to the view component after it is fully configured
        $app = Craft::$app;
        if ($app->getConfig()->getGeneral()->devMode) {
            $app->on(Application::EVENT_BEFORE_REQUEST, function () use ($app) {
                $app->getView()->on(View::EVENT_END_BODY, [$this, 'injectErrorEntry']);
            });
        }
    }
protected function installEventListeners ( ) { // Remember the name of the currently rendering template // Handler: View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE Event :: on ( View :: class , View :: EVENT_BEFORE_RENDER_PAGE_TEMPLATE , function ( TemplateEvent $ event ) { self :: $ templateName = $ event -> template ; } ) ; // Handler: CraftVariable::EVENT_INIT Event :: on ( CraftVariable :: class , CraftVariable :: EVENT_INIT , function ( Event $ event ) { /** @var CraftVariable $variable */ $ variable = $ event -> sender ; $ variable -> set ( 'twigpack' , ManifestVariable :: class ) ; } ) ; // Handler: TemplateCaches::EVENT_AFTER_DELETE_CACHES Event :: on ( TemplateCaches :: class , TemplateCaches :: EVENT_AFTER_DELETE_CACHES , function ( DeleteTemplateCachesEvent $ event ) { // Invalidate the caches when template caches are deleted $ this -> clearAllCaches ( ) ; } ) ; // Handler: Plugins::EVENT_AFTER_INSTALL_PLUGIN Event :: on ( Plugins :: class , Plugins :: EVENT_AFTER_INSTALL_PLUGIN , function ( PluginEvent $ event ) { if ( $ event -> plugin === $ this ) { // Invalidate our caches after we've been installed $ this -> clearAllCaches ( ) ; } } ) ; // Handler: ClearCaches::EVENT_REGISTER_CACHE_OPTIONS Event :: on ( ClearCaches :: class , ClearCaches :: EVENT_REGISTER_CACHE_OPTIONS , function ( RegisterCacheOptionsEvent $ event ) { Craft :: debug ( 'ClearCaches::EVENT_REGISTER_CACHE_OPTIONS' , __METHOD__ ) ; // Register our caches for the Clear Cache Utility $ event -> options = array_merge ( $ event -> options , $ this -> customAdminCpCacheOptions ( ) ) ; } ) ; // delay attaching event handler to the view component after it is fully configured $ app = Craft :: $ app ; if ( $ app -> getConfig ( ) -> getGeneral ( ) -> devMode ) { $ app -> on ( Application :: EVENT_BEFORE_REQUEST , function ( ) use ( $ app ) { $ app -> getView ( ) -> on ( View :: EVENT_END_BODY , [ $ this , 'injectErrorEntry' ] ) ; } ) ; } }
Install our event listeners.
Install our event listeners .