Skip to main content

GravityKit\GravityView\View\View

Source: src/View/View.php:42

Details

  • Kind: class

  • Namespace: GravityKit\GravityView\View

  • Implements: ArrayAccess

Properties

PropertyTypeDescription
$settings\GV\View_SettingsThe settings.
$widgets\GV\Widget_CollectionThe widgets attached here.
$form\GV\GF_Form | \GV\FormThe backing form for this view. Contains the form that is sourced for entries in this view.
$fields\GV\Field_CollectionThe fields for this view. Contains all the fields that are attached to this view.
$styles\GravityKit\GravityView\Settings\ViewStylesThe design-token registry adapter for this View. Provides token discovery, sanitisation, and CSS emission for the View's saved palette / typography / spacing / effects overrides. Backed by static methods; the property is a thin namespace handle so callers can write $view->styles->emit_css_declarations( ... ) (see also scoped_selector(), sticky_header_css(), and prefers_contrast_css() for the per-View emission helpers).
$joins\GV\Join[]The joins for all sources in this view.
$unions\GV\Field[][]The unions for all sources in this view. An array of fields grouped by form_id keyed by main field_id: array( $form_id => array( $field_id => $field, $field_id => $field, ) )

Methods

MethodDescription
__construct()The constructor.
add_rewrite_endpoint()Add extra rewrite endpoints.
content()A renderer filter for the View post type content.
can_render()Checks whether this view can be accessed or not.
get_form_ids()The IDs of every form this View spans: its own form plus any joined or unioned forms.
get_joins()Get joins associated with a view
get_joined_forms()Get joined forms associated with a view
get_unions()Get unions associated with a view
maybe_union_field()Resolves a configured field to its unioned counterpart, if the form has a union mapping.
from_post()Construct a \GV\View instance from a \WP_Post.
by_id()Construct a \GV\View instance from a post ID.
get_source()Gets the source of the field.
exists()Determines if a view exists to begin with.
get_entries()Retrieve the entries for the current view and request.
template_redirect()Last chance to configure the output.
get_query_class()Return the query class for this View.
restrict()Restrict View access to specific capabilities.
set_anchor_id()Sets the anchor ID of a View, without the prefix.
get_anchor_id()Returns the anchor ID to be used in the View container HTML id attribute.
__get()Magic getter forwarded to the backing \WP_Post.
get_post()Return associated WP post
get_validation_secret()Calculates and returns the View's validation secret.
get_validation_secret_by_id()Calculates and returns a View's validation secret without hydrating the View.
maybe_establish_secret_key_boundary()Establishes the per-site secret-key boundary on this site's first run.
validate_secret()Returns whether the provided secret validates for this View.
get_shortcode()Returns the shortcode for this View.

Method Reference

__construct()

public function __construct()

The constructor.

Source: src/View/View.php:184

add_rewrite_endpoint()

public static function add_rewrite_endpoint()

Add extra rewrite endpoints.

Returns

  • void

Source: src/View/View.php:326

content()

public static function content( $content )

A renderer filter for the View post type content.

Parameters

NameTypeDefaultDescription
$contentstringShould be empty, as we don't store anything there.

Returns

  • string — $content The view content as output by the renderers.

Source: src/View/View.php:359

can_render()

public function can_render( $context=null, $request=null )

Checks whether this view can be accessed or not.

Parameters

NameTypeDefaultDescription
$contextstring[]nullThe context we're asking for access from. Can any and as many of one of: edit An edit context. single A single context. cpt The custom post type single page accessed. shortcode Embedded as a shortcode. lightbox Rendered inside a GravityView entry lightbox. oembed Embedded as an oEmbed. rest A REST call. csv A CSV export.
$request\GV\RequestnullThe request.

Returns

  • bool | \WP_Error — An error if this View shouldn't be rendered here.

Source: src/View/View.php:487

get_form_ids()

public function get_form_ids(): array

The IDs of every form this View spans: its own form plus any joined or unioned forms.

Returns

  • int[]

Since:

  • 3.0.1
  • 3.2.0 (Includes unioned forms.)

Source: src/View/View.php:603

get_joins()

public static function get_joins( $post )

Get joins associated with a view

Parameters

NameTypeDefaultDescription
$post\WP_PostGravityView CPT to get joins for.

Returns

  • \GV\Join[] — Array of \GV\Join instances

Since: 2.0.11

Source: src/View/View.php:661

get_joined_forms()

public static function get_joined_forms( $post_id )

Get joined forms associated with a view

In no particular order.

Parameters

NameTypeDefaultDescription
$post_idintID of the View.

Returns

  • \GV\GF_Form[] — Array of \GV\GF_Form instances

Since:

  • 2.0.11
  • 2.0

Source: src/View/View.php:713

get_unions()

public static function get_unions( $post )

Get unions associated with a view

Parameters

NameTypeDefaultDescription
$post\WP_PostGravityView CPT to get unions for.

Returns

  • \GV\Field[][] — Array of unions (see self::$unions)

Since: 2.2.2

Source: src/View/View.php:771

maybe_union_field()

public function maybe_union_field( $field, $form_id )

Resolves a configured field to its unioned counterpart, if the form has a union mapping.

The slot's display configuration (position, label, visibility, class, and link settings) is carried over so the unioned field is presented exactly as the slot it replaces; only the value comes from the unioned form.

Parameters

NameTypeDefaultDescription
$field\GV\FieldThe configured field from the primary form.
$form_idint | stringThe form ID of the entry being rendered.

Returns

  • \GV\Field — The unioned field for the form, or the original field when there is no mapping.

Since: 3.2.0

Source: src/View/View.php:835

from_post()

public static function from_post( $post )

Construct a \GV\View instance from a \WP_Post.

Parameters

NameTypeDefaultDescription
$post\WP_PostThe \WP_Post instance to wrap.

Returns

  • \GV\View | null — An instance around this \WP_Post if valid, null otherwise.

Since: 2.0

Source: src/View/View.php:913

by_id()

public static function by_id( $post_id )

Construct a \GV\View instance from a post ID.

Parameters

NameTypeDefaultDescription
$post_idint | stringThe post ID.

Returns

  • \GV\View | null — An instance around this \WP_Post or null if not found.

Since: 2.0

Source: src/View/View.php:1056

get_source()

public static function get_source( $field, $view )

Gets the source of the field.

Parameters

NameTypeDefaultDescription
$field\GV\FieldThe field.
$view\GV\ViewThe view.

Returns

  • \GV\GF_Form | \GV\Internal_Source

Since: 2.33

Source: src/View/View.php:1080

exists()

public static function exists( $view )

Determines if a view exists to begin with.

Parameters

NameTypeDefaultDescription
$viewint | \WP_Post | nullThe WordPress post ID, a \WP_Post object or null for global $post.

Returns

  • bool — Whether the post exists or not.

Since: 2.0

Source: src/View/View.php:1112

get_entries()

public function get_entries( $request=null )

Retrieve the entries for the current view and request.

Parameters

NameTypeDefaultDescription
$request\GV\RequestnullThe request.

Returns

  • \GV\Entry_Collection — The entries.

Source: src/View/View.php:1393

template_redirect()

public static function template_redirect()

Last chance to configure the output.

Used for CSV output, for example.

Returns

  • void

Source: src/View/View.php:1924

get_query_class()

public function get_query_class()

Return the query class for this View.

Returns

  • string — The class name.

Source: src/View/View.php:2056

restrict()

public static function restrict( $caps, $cap, $user_id, $args )

Restrict View access to specific capabilities.

Hooked into map_meta_cap WordPress filter.

Parameters

NameTypeDefaultDescription
$capsarrayThe output capabilities.
$capstringThe cap that is being checked.
$user_idintThe User ID.
$argsarrayAdditional arguments to the capability.

Returns

  • array — The resulting capabilities.

Since: 3.0.0

Source: src/View/View.php:2080

set_anchor_id()

public function set_anchor_id( $counter=1 )

Sets the anchor ID of a View, without the prefix.

Parameters

NameTypeDefaultDescription
$counterint1An incremental counter reflecting how many times this View has been rendered.

Returns

  • void

Since: 2.15

Source: src/View/View.php:2125

get_anchor_id()

public function get_anchor_id()

Returns the anchor ID to be used in the View container HTML id attribute.

Returns

  • string — Unsanitized anchor ID.

Since: 2.15

Source: src/View/View.php:2136

__get()

public function __get( $key )

Magic getter forwarded to the backing \WP_Post.

Parameters

NameTypeDefaultDescription
$keystringThe property name.

Returns

  • mixed — The property value, or null if not set.

Source: src/View/View.php:2154

get_post()

public function get_post()

Return associated WP post

Returns

  • \WP_Post | null

Since: 2.13.2

Source: src/View/View.php:2169

get_validation_secret()

final public function get_validation_secret( bool $is_forced=false ): ?string

Calculates and returns the View's validation secret.

Parameters

NameTypeDefaultDescription
$is_forcedboolfalseWhether to compute the secret for non-secure Views too.

Returns

  • string | null — The View's secret.

Since: 2.21

Source: src/View/View.php:2238

get_validation_secret_by_id()

public static function get_validation_secret_by_id( int $view_id, bool $is_forced=false ): ?string

Calculates and returns a View's validation secret without hydrating the View.

Bulk callers (e.g. the block editor View picker) use this so listing thousands of Views does not pay full View hydration per row.

Parameters

NameTypeDefaultDescription
$view_idintThe View ID.
$is_forcedboolfalseWhether to compute the secret for non-secure Views too.

Returns

  • string | null — The View's secret.

Since:

  • 3.0.0
  • 3.1.0 (The secret is derived from a per-site random key stored in the gravityview_view_secret_key option. Embeds of Views that predate the per-site key keep working because validate_secret() still accepts the previous secret for them.)

Source: src/View/View.php:2259

maybe_establish_secret_key_boundary()

public static function maybe_establish_secret_key_boundary(): int

Establishes the per-site secret-key boundary on this site's first run.

Hooked to gravityview/loaded (an early, every-request action), so the stored GMT timestamp is the moment this site first ran the per-site-key code: activation time on a fresh install, first request after the update on an upgrade. Writes once and returns the same boundary thereafter.

Returns

  • int — The boundary as a GMT Unix timestamp, or 0 if it cannot be persisted.

Since: 3.1.0

Source: src/View/View.php:2391

validate_secret()

final public function validate_secret( string $secret ): bool

Returns whether the provided secret validates for this View.

Parameters

NameTypeDefaultDescription
$secretstringThe provided secret.

Returns

  • bool

Since:

  • 2.21
  • 3.1.0 (The current secret is derived from a per-site key. The previous secret is accepted only for Views that predate the per-site key, so existing embeds keep working while newly created Views use only the per-site secret. Override with the gk/gravityview/view/secret/allow-legacy filter.)

Source: src/View/View.php:2453

get_shortcode()

final public function get_shortcode( array $atts=[] ): string

Returns the shortcode for this View.

Parameters

NameTypeDefaultDescription
$attsarray[]Additional attributes for the shortcode.

Returns

  • string

Since:

  • 2.21
  • 2.22 (Added $atts parameter.)

Source: src/View/View.php:2511