Monday, February 20, 2017

Grav - Event Hooks

In this chapter, we will study about Event Hooks in Grav. In Plugins chapter you will see, the logic of plugin was included in two methods. The methods are onPluginsInitialized and onPageInitialized which is similar to event hooks.
To know more and control the power of Grav plugins, you need to check the availability of event hooks. The event hooks have a direct relationship with Grav from beginning to end. You must be aware of the order in which the hooks are called and what is usable at the time of these calls.
Following are the core Grav event hooks, that are activated during the processing of a page.
EventsDescription
onFatalExceptionYou can fire this event at any moment, if PHP gives a fatal exception. The Problem plugin uses this to manage displaying a list of full explanation, for why the grav delivers the fatal error.
onPluginsInitializedIt is the first plugin event that is usable in grav. The following objects have been introduced as mentioned below.
  • Uri
  • Config
  • Debugger
  • Cache
  • Plugins
onAssetsInitialized It specifies the assets manager is loaded and ready to use and manage.
onPageNotFoundIf you found an unexpected page, you can dismiss this event. Presently, the error plugin is used to specify a 404 error page.
onPageInitialized It specifies the requested page by a URL which is loaded into the Page object.
onOutputGenerated It specifies the output process by the Twig templating engine. Presently, it is just a string of HTML.
onOutputRendered This is an output process, which is sent to the display.
onShutdownThis is a new and very powerful event that allows you to perform actions. This is done after Grav has completed processing and the connection to the client is closed. This individual action does not require any interaction with the user, in result can effect the performance. It includes the user tracking and jobs processing.
onBeforeDownload It's a new event which passes into event object that contains a file. It allows the users to perform logging, grant and ignore permission to download mentioned file.


Twig Event Hooks

Twig has its own collection of event hooks to use as mentioned below.
EventsDescription
onTwigTemplatePathsThe template path's base location is set on the Twig object. This event is used to add other locations where Twig will search for template paths.
onTwiglnitializedIt initialize the Twig templating engine.
onTwigExtensionsIt specifies the core twig extensions is ready to use. This event hook allows you to add your own Twig extension.
onTwigPageVariablesThis Twig process permits you a page directly, i.e. you can locate process:twig:tru in a page of YAML headers. Here you can add any variables to Twig and should accessible to twig during this process.
onTwigSiteVariablesIn this process, you will see the full site template in order wise by Twig methods. Further, you can add any variable to Twig during this process.

Collection Event Hooks

Below mentioned is a collection of event hooks
EventsDescription
onCollectionProcessed In this section, once the process is completed you can control a collection.

Page Event Hooks

Following are the collections of page event hooks
EventsDescription
onBuildPagesInitializedThis event is useful for plugins to control the content and cache the results. Once this event is activated the pages will be recycled. This occurs, when the cache has expired or needs refreshing.
onBlueprintCreatedThis event helps in processing and managing forms.
onPageContentRawIn this process, when a page is found, headers are fixed, but content will not be fixed. You will see every page is fired in the Grav system. If you have cleared the cache or clearing the cache this event occurs.
onPageProcessedOnce a page is tested and fixed, every page is dismissed in the Grav system. Performance doesn't matter in this case, since it will not play on a cached page.
onPageContentProcessedYou can see this event is dismissed, once the page's content() technique has fixed the page content. This event is useful in case, you want to perform actions on the post-fixed content but make sure that the results are cached.
onFolderProcessedOnce a folder is tested and fixed, every folder is dismissed in the Grav system. Performance doesn't matter in this case, since it will not play on a cached page.

No comments:

Post a Comment