GravityView_View
Source: includes/class-template.php:26
Details
- Kind:
class - Namespace:
(global) - Extends:
GV\Gamajo_Template_Loader
Properties
| Property | Type | Description |
|---|---|---|
$filter_prefix | string | Prefix for filter names. |
$theme_template_directory | string | Directory name where custom templates for this plugin should be found in the theme. |
$plugin_directory | string | Reference to the root directory path of this plugin. |
$located_templates | array | Store templates locations that have already been located |
$template_part_slug | string | The name of the template, like "list", "table", or "datatables" |
$template_part_name | string | The name of the file part, like "body" or "single" |
$form_id | int | Gravity Forms form ID |
$view_id | int | View ID |
$fields | array | Fields for the form |
$context | string | Current screen. Defaults to "directory" or "single" |
$post_id | int | null | If in embedded post or page, the ID of it |
$form | array | Gravity Forms form array at ID $form_id |
$atts | array | Configuration for the View |
$entries | array | Entries for the current result. Single item in array for single entry View |
$total_entries | int | Total entries count for the current result. |
$back_link_label | string | The label to display back links |
$paging | array | Array with offset and page_size keys |
$sorting | array | Array with sort_field and sort_direction keys |
$hide_until_searched | bool | Whether to hide the results until a search is performed |
$_current_entry | array | Current entry in the loop |
$_current_field | array | |
$field_data | The current field data. |
Methods
| Method | Description |
|---|---|
__construct() | Construct the view object |
getInstance() | |
getCurrentField() | |
setCurrentField() | |
getAtts() | |
setAtts() | |
getForm() | |
setForm() | |
getPostId() | |
setPostId() | |
getContext() | |
setContext() | |
getFields() | |
getContextFields() | Get the fields for a specific context |
setFields() | |
getField() | |
setField() | |
getViewId() | |
setViewId() | |
getFormId() | |
setFormId() | |
getEntries() | |
setEntries() | |
getTotalEntries() | |
setTotalEntries() | |
getPaging() | |
setPaging() | |
getPaginationCounts() | Get an array with pagination information |
getSorting() | |
setSorting() | |
getBackLinkLabel() | |
setBackLinkLabel() | |
isHideUntilSearched() | |
setHideUntilSearched() | |
getTemplatePartSlug() | |
setTemplatePartSlug() | |
getTemplatePartName() | |
setTemplatePartName() | |
getCurrentEntry() | Return the current entry. If in the loop, the current entry. If single entry, the currently viewed entry. |
setCurrentEntry() | |
clearCurrentEntry() | Clear the current entry after all entries in the loop have been displayed. |
renderZone() | Render an output zone, as configured in the Admin |
locate_template() | In order to improve lookup times, we store located templates in a local array. |
__get() | Magic Method: Instead of throwing an error when a variable isn't set, return null. |
build_legacy_field_context() | Wraps the singleton's legacy state into a modern \GV\Template_Context for a single field. |
add_id_specific_templates() | Enable overrides of GravityView templates on a granular basis |
render() | Render a template part |
render_widget_hooks() | Output the widgets on before/after hooks. |
_include() | Include a file inside this context. |
Method Reference
__construct()
function __construct( $atts=[] )
Construct the view object
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$atts | array | [] | Associative array to set the data of |
Source: includes/class-template.php:182
getInstance()
static function getInstance( $passed_post=null )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$passed_post | null | null |
Returns
Source: includes/class-template.php:231
getCurrentField()
public function getCurrentField( $key=null )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | null | null | The key to a specific attribute of the current field |
Returns
array|mixed|null— If $key is set and attribute exists at $key, return that. If not set, return NULL. Otherwise, return current field array
Source: includes/class-template.php:244
setCurrentField()
public function setCurrentField( $passed_field )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$passed_field | array |
Source: includes/class-template.php:276
getAtts()
public function getAtts( $key=null )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | null | null | The key to a specific field in the fields array |
Returns
array|mixed|null— If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
Source: includes/class-template.php:296
setAtts()
public function setAtts( $atts )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$atts | array |
Source: includes/class-template.php:311
getForm()
public function getForm()
Returns
array
Source: includes/class-template.php:318
setForm()
public function setForm( $form )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form | array |
Source: includes/class-template.php:325
getPostId()
public function getPostId()
Returns
int|null
Source: includes/class-template.php:332
setPostId()
public function setPostId( $post_id )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$post_id | int | null |
Source: includes/class-template.php:339
getContext()
public function getContext()
Returns
string
Source: includes/class-template.php:346
setContext()
public function setContext( $context )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$context | string |
Source: includes/class-template.php:353
getFields()
public function getFields( $key=null )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | null | null | The key to a specific field in the fields array |
Returns
array|mixed|null— If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
Source: includes/class-template.php:361
getContextFields()
public function getContextFields( $context='' )
Get the fields for a specific context
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$context | string | '' | [Optional] "directory", "single", or "edit" |
Returns
array— Array of GravityView field layout configurations
Since: 1.19.2
Source: includes/class-template.php:381
setFields()
public function setFields( $fields )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$fields | array |
Source: includes/class-template.php:405
getField()
public function getField( $key )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | The key to a specific field in the fields array |
Returns
array|mixed|null— If $key is set and field exists at $key, return that. If not set, return NULL. Otherwise, return array of fields.
Source: includes/class-template.php:413
setField()
public function setField( $key, $value )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$key | string | The key to a specific field in the fields array | |
$value | mixed | The value to set for the field |
Source: includes/class-template.php:428
getViewId()
public function getViewId()
Returns
int
Source: includes/class-template.php:435
setViewId()
public function setViewId( $view_id )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$view_id | int |
Source: includes/class-template.php:442
getFormId()
public function getFormId()
Returns
int
Source: includes/class-template.php:449
setFormId()
public function setFormId( $form_id )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$form_id | int |
Source: includes/class-template.php:456
getEntries()
public function getEntries()
Returns
array
Source: includes/class-template.php:463
setEntries()
public function setEntries( $entries )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$entries | array |
Source: includes/class-template.php:470
getTotalEntries()
public function getTotalEntries()
Returns
int
Source: includes/class-template.php:477
setTotalEntries()
public function setTotalEntries( $total_entries )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$total_entries | int |
Source: includes/class-template.php:484
getPaging()
public function getPaging()
Returns
array
Source: includes/class-template.php:491
setPaging()
public function setPaging( $paging )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$paging | array |
Source: includes/class-template.php:504
getPaginationCounts()
public function getPaginationCounts()
Get an array with pagination information
Returns
array— {
Since: 1.13
Source: includes/class-template.php:519
getSorting()
public function getSorting()
Returns
array
Source: includes/class-template.php:556
setSorting()
public function setSorting( $sorting )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$sorting | array |
Source: includes/class-template.php:570
getBackLinkLabel()
public function getBackLinkLabel( $do_replace=true )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$do_replace | boolean | true | Perform merge tag and shortcode processing on the label. Default: true. |
Returns
string
Since: 2.0
Deprecated: Use $template->get_back_label();
Source: includes/class-template.php:582
setBackLinkLabel()
public function setBackLinkLabel( $back_link_label )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$back_link_label | string |
Source: includes/class-template.php:594
isHideUntilSearched()
public function isHideUntilSearched()
Returns
boolean
Source: includes/class-template.php:601
setHideUntilSearched()
public function setHideUntilSearched( $hide_until_searched )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$hide_until_searched | boolean |
Source: includes/class-template.php:608
getTemplatePartSlug()
public function getTemplatePartSlug()
Returns
string
Source: includes/class-template.php:615
setTemplatePartSlug()
public function setTemplatePartSlug( $template_part_slug )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$template_part_slug | string |
Source: includes/class-template.php:622
getTemplatePartName()
public function getTemplatePartName()
Returns
string
Source: includes/class-template.php:629
setTemplatePartName()
public function setTemplatePartName( $template_part_name )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$template_part_name | string |
Source: includes/class-template.php:636
getCurrentEntry()
public function getCurrentEntry()
Return the current entry. If in the loop, the current entry. If single entry, the currently viewed entry.
Returns
array
Source: includes/class-template.php:645
setCurrentEntry()
public function setCurrentEntry( $current_entry )
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$current_entry | array |
Returns
void
Source: includes/class-template.php:666
clearCurrentEntry()
public function clearCurrentEntry()
Clear the current entry after all entries in the loop have been displayed.
Returns
void
Since: 1.7.3
Source: includes/class-template.php:676
renderZone()
public function renderZone( $zone='', $atts=[], $echo=true )
Render an output zone, as configured in the Admin
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$zone | string | '' | The zone name, like 'footer-left' |
$atts | array | [] | |
$echo | bool | true | Whether to print the output |
Returns
string|null
Since: 1.16.4 (Added $echo parameter)
Deprecated: This will never get called in new templates.
Source: includes/class-template.php:693
locate_template()
function locate_template( $template_names, $load=false, $require_once=true )
In order to improve lookup times, we store located templates in a local array.
This improves performance by up to 1/2 second on a 250 entry View with 7 columns showing
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$template_names | string | array | Template file(s) to search for, in order. | |
$load | bool | false | If true the template file will be loaded if it is found. |
$require_once | bool | true | Whether to require_once or require. Default true. Has no effect if $load is false. |
Returns
null|string— NULL: Template not found; String: path to template
See Also
\Gamajo_Template_Loader::locate_template()
Since: 1.0.0
Source: includes/class-template.php:793
__get()
public function __get( $name )
Magic Method: Instead of throwing an error when a variable isn't set, return null.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$name | string | Key for the data retrieval. |
Returns
mixed|null— The stored data.
Source: includes/class-template.php:822
build_legacy_field_context()
public function build_legacy_field_context( array $field, array $entry ): ?\GV\Template_Context
Wraps the singleton's legacy state into a modern \GV\Template_Context for a single field.
Used by the deprecated GravityView_View::renderZone() rendering path and the legacy list
templates so the new gravityview/template/field_output/context,
gravityview/field_output/context/{$tag}, gravityview/field_output/html, etc. filters
receive a usable context instead of null. Returns null when the legacy state cannot be
wrapped, in which case gravityview_field_output() falls back to its deprecated path.
Handles joined Views by resolving the field's source form via $field['form_id'] against
$gv_view->joins, mirroring \GV\View::get_source().
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$field | array | A GravityView field configuration array, with at least an id key. | |
$entry | array | The Gravity Forms entry array currently being rendered. |
Returns
- \GV\Template_Context |
null— The wrapped context, or null when wrapping isn't possible.
Since: 2.60.0
Source: includes/class-template.php:849
add_id_specific_templates()
function add_id_specific_templates( $templates, $slug, $name )
Enable overrides of GravityView templates on a granular basis
The loading order is:
- view-[View ID]-table-footer.php
- form-[Form ID]-table-footer.php
- page-[ID of post or page where view is embedded]-table-footer.php
- table-footer.php
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$templates | array | Existing list of templates. | |
$slug | string | Name of the template base, example: table, list, datatables, map | |
$name | string | Name of the template part, example: body, footer, head, single |
Returns
array— $templates Modified template array, merged with existing $templates values
See Also
\Gamajo_Template_Loader::get_template_file_names()Where the filter is
Source: includes/class-template.php:910
render()
public function render( $slug, $name, $require_once=true, $data=[] )
Render a template part
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$slug | string | The template slug (like "table"). | |
$name | string | The template part name (like "body"). | |
$require_once | bool | true | Whether to require_once the template file. Default: true. |
$data | array | [] | Data to pass to the template, available to the template as a $data global. Default: array(). |
Since: 2.42
Source: includes/class-template.php:946
render_widget_hooks()
public function render_widget_hooks( $view_id_or_context )
Output the widgets on before/after hooks.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$view_id_or_context | int | \GV\Template_Context | The View ID or the context. |
Returns
void
Source: includes/class-template.php:979
_include()
public function _include( $path )
Include a file inside this context.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$path | string | A path to the legacy template to include. |
Returns
void
Source: includes/class-template.php:1144