English (United Kingdom)
Knowledge Base  >  Vik Restaurants  >  Hooks  >  System  >  Visualization  >  Display Management Page

apply_filters( 'vikrestaurants_display_view_{$page}', mixed $forms, JView $view )

Fires while displaying the management page of a record.


Description

This hook is triggered within the management pages of certain sections of the plugin. It is possible to use this hook to include additional pieces of code within specific positions of the related page, such as to support new parameters.

The dynamic portion of the hook name, $page, refers to the name of the page calling the hook. This means that, for example, the managereservation page will trigger an hook called vikrestaurants_display_view_managereservation. In case the page name starts with "manage", "new" or "edit", the system will trigger an additional hook without specifying that string, such as: vikrestaurants_display_view_reservation.

In addition to the mentioned arguments, some hooks might report other arguments that may result helpful to the developers.

IMPORTANT NOTE: not all the pages trigger this hook. Before to start coding a plugin, you should make sure that the page supports that hook, by checking whether the onDisplayView() or onDisplayManageView() methods are used. This can be done by accessing the page at the path:

/wp-content/plugins/vikrestaurants/admin/views/{$page}/tmpl/default.php
(back-end pages)

Parameters

$forms

(array|null)  An associative array containing the HTML to include. By adding the HTML within a reserved key of the page, the plugin will display the entered string within the position assigned to that key. In case of an unknown key, the HTML will be appended within specific custom form fields/tabs.

At the first hook execution, the argument may be a null value.

$page

(JView)  The page instance holding the record details.


Example

The example below displays a custom field within the management page of a restaurant reservation.

/**
 * Trigger filter to allow the plugins to include custom HTML within the page. 
 *
 * @param  mixed  $forms  An associative array of forms.
 * @param  mixed  $view   The current page instance.
 */
add_filter('vikrestaurants_display_view_reservation', function($forms, $view)
{
    if (!$forms) {
        $forms = [];
    }

    // load previoulsy selected value or take the default one
    $custom_value = $view->reservation->custom_value ?? '';

    // create HTML of the field
    $html = $view->formFactory->createField()
        ->type('text')
        ->name('custom_value')
        ->value($custom_value)
        ->label(__('Custom Setting', 'myplugin'));

    // add field at the end of the "Booking" fieldset, on the right side
    $forms['bookin'] = $html;

    return $forms;
}, 10, 2);

Changelog

Version Description
1.2.3 Introduced.
Last Update: 2023-12-15
Helpful?
This site uses cookies. By continuing to browse you accept their use. Further information