Skip to main content

GravityKit\GravityView\View\ViewCollection

A collection of View objects.

Since:

  • 2.0
  • 3.0.0 (Migrated to GravityKit\GravityView\View namespace.)

Source: src/View/ViewCollection.php:23

Details​

  • Kind: class
  • Namespace: GravityKit\GravityView\View
  • Extends: GV\Collection

Methods​

MethodDescription
all()Returns all the objects in this collection as an an array.
add()Add a View to this collection.
get()Get a View from this list.
contains()Check whether \GV\View with an ID is already here.
from_post()Get a list of View objects inside the supplied \WP_Post.
from_post_detailed()Returns the Views found in a post alongside the strings they were found in.
from_content()Get a list of detected View objects inside the supplied content.

Method Reference​

all()​

public function all()

Returns all the objects in this collection as an an array.

Returns​

  • View[]

Since: 2.0

Source: src/View/ViewCollection.php:36

add()​

public function add( $view )

Add a View to this collection.

Parameters​

NameTypeDefaultDescription
$viewViewThe view to add to the internal array.

Returns​

  • void

Since: 2.0

Source: src/View/ViewCollection.php:49

get()​

public function get( $view_id )

Get a View from this list.

Parameters​

NameTypeDefaultDescription
$view_idintThe ID of the view to get.

Returns​

  • \GV\View | null — The \GV\View with the $view_id as the ID, or null if not found.

Since: 2.0

Source: src/View/ViewCollection.php:69

contains()​

public function contains( $view_id )

Check whether \GV\View with an ID is already here.

Parameters​

NameTypeDefaultDescription
$view_idintThe ID of the view to check.

Returns​

  • boolean — Whether it exists or not.

Since: 2.0

Source: src/View/ViewCollection.php:88

from_post()​

public static function from_post( \WP_Post $post )

Get a list of View objects inside the supplied \WP_Post.

The post can be a gravityview post, which is the simplest case. The post can contain gravityview shortcodes as well. The post meta can contain gravityview shortcodes.

Parameters​

NameTypeDefaultDescription
$post\WP_PostThe \WP_Post object to look into.

Returns​

  • ViewCollection — A ViewCollection instance containing the views inside the supplied \WP_Post.

Since: 2.0

Source: src/View/ViewCollection.php:105

from_post_detailed()​

public static function from_post_detailed( \WP_Post $post ): array

Returns the Views found in a post alongside the strings they were found in.

Callers that must decide whether an embed would actually render need the exact text this parse looked at. Re-deriving it against a second parser lets the two drift, and an embed only one of them sees is an embed nobody validates.

Parameters​

NameTypeDefaultDescription
$post\WP_PostThe post to look into.

Returns​

  • array{views:ViewCollection, — authored:ViewCollection, sources:string} authored holds the Views found in the post's own content and meta, before server-side declarations are filtered in.

Since: 3.2.0

Source: src/View/ViewCollection.php:124

from_content()​

public static function from_content( $content, $post=null )

Get a list of detected View objects inside the supplied content.

The content can have a shortcode, this is the simplest case.

Parameters​

NameTypeDefaultDescription
$contentstringThe content to look into.
$postWP_Post | nullnullOptional. The post holding the content; its merge tags resolve against it.

Returns​

  • ViewCollection — A ViewCollection instance containing the views inside the supplied \WP_Post.

Since:

  • 2.0
  • 3.7.0 (Added the $post parameter.)

Source: src/View/ViewCollection.php:278