public function onBeforeAddMicrodata(object &$json, bool $includeVAPViewContents $handler) : void

Fires while including the microdata within the head of the document.


Description

Microdata is used to nest metadata within existing content on web pages. Search engines and web crawlers can extract and process microdata from a web page and use it to provide a richer browsing experience for users. Google and other major search engines support the Schema.org vocabulary for structured data.

This hook can be used to allow the plugins to manipulate the JSON object that will be used by search engines.


Parameters

&$json

(object)  The JSON object including the microdata. An empty object by default.

&$include

(bool)  Whether to include the microdata or not.

$handler

(VAPViewContents)  The handler instance used to manipulate the page contents.

Return Value

None.


Example

The example below explains how to always force the microdata to include the phone number of an employee, even if it should be hidden.

/**
 * Trigger event to allow the plugins to manipulate the JSON object
 * that will be used by search engines.
 *
 * @param   object           &$json     The JSON object.
 * @param   boolean          &$include  True whether the JSON object should be included into the document.
 * @param   VAPViewContents  $handler   The page content handler.
 *
 * @return  void
 */
public function onBeforeAddMicrodata(&$json, &$include, $handler)
{
    // get current plugin page
    $page = $handler->page;

    // make sure we are within the details page of an employee
    if (!preg_match("/^VikAppointmentsViewemployeesearch$/i", get_class($page)))
    {
        // do not go ahead.
        return;
    }

    // turn flag OFF if you wish to exlude microdata
    // $include = false;

    // get employee object
    $employee = $page->employee;
	
    if (!isset($json->telephone))
    {
        $json->telephone = $employee->get('phone');
    }
}

Changelog

VersionDescription
1.6 Introduced.
Last Update: 2021-10-08 13:59
Helpful?