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.
Events | Description |
onFatalException | You 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. |
onPluginsInitialized | It 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. |
onPageNotFound | If 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. |
onShutdown | This 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.
Events | Description |
onTwigTemplatePaths | The 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. |
onTwiglnitialized | It initialize the Twig templating engine. |
onTwigExtensions | It specifies the core twig extensions is ready to use. This event hook allows you to add your own Twig extension. |
onTwigPageVariables | This 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. |
onTwigSiteVariables | In 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
Events | Description |
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
Events | Description |
onBuildPagesInitialized | This 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.
|
onBlueprintCreated | This event helps in processing and managing forms. |
onPageContentRaw | In 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. |
onPageProcessed | Once 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. |
onPageContentProcessed | You 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. |
onFolderProcessed | Once 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