Prismic.io PHP kit  3.0.0
Public Member Functions | Static Public Member Functions | List of all members
Prismic\WithFragments Class Reference
Inheritance diagram for Prismic\WithFragments:
Prismic\Document Prismic\Fragment\GroupDoc Prismic\Fragment\Link\DocumentLink

Public Member Functions

 __construct (array $fragments)
 
 getFragments ()
 
 get ($field)
 
 has ($field)
 
 getAll ($field)
 
 getText ($field)
 
 getNumber ($field, $pattern=null)
 
 getGeoPoint ($field)
 
 getBoolean ($field)
 
 getDate ($field, $pattern=null)
 
 getTimestamp ($field)
 
 getHtml ($field, $linkResolver=null)
 
 getImage ($field)
 
 getAllImages ($field)
 
 getImageView ($field, $view=null)
 
 getAllImageViews ($field, $view)
 
 getStructuredText ($field)
 
 getLink ($field)
 
 getGroup ($field)
 
 getSliceZone ($field)
 
 getEmbed ($field)
 
 getColor ($field)
 
 asHtml ($linkResolver=null)
 

Static Public Member Functions

static parseFragment ($json)
 
static parseFragments ($json)
 

Constructor & Destructor Documentation

§ __construct()

Prismic\WithFragments::__construct ( array  $fragments)
Parameters
array$fragments

Member Function Documentation

§ asHtml()

Prismic\WithFragments::asHtml (   $linkResolver = null)

Returns an HTML serialization for the whole document at once, by serializing all fragments in order.

This is a basic serialization, if you want to template your document better, you will need to serialize at the fragment level; for instance: $doc->get('product.description')->asHtml($linkResolver);

Parameters
Prismic::LinkResolver$linkResolveran extension of the Prismic::LinkResolver class that you taught how to turn a prismic.io document in to a URL in your application
Returns
string the directly usable HTML code

§ get()

Prismic\WithFragments::get (   $field)

Accesses a fragment of the document. For instance, if the document is of the type "product" and the name of the fragment is "description", then you can access the fragment like this: document->get('product.description').

If you prefer a more type-safe access, that only works if the fragment is of the right type, you can use the getStructuredText, getColor, getDate, etc. methods.

Parameters
string$fieldname of the fragment, with the document's type, like "product.description"
Returns
Prismic::Fragment::FragmentInterface the fragment as an object

§ getAll()

Prismic\WithFragments::getAll (   $field)

Returns all fragments of the name given

Deprecated:
deprecated as it was meant to be used with an old concept called "multiples"; prefer to use Group fragments now, that are more powerful.
Parameters
string$fieldname of the fragments
Returns
array the list of fragments that exist

§ getAllImages()

Prismic\WithFragments::getAllImages (   $field)

Returns all the usable Image fragments in the given StructuredText fragment, ready to be manipulated. This function also works on Image fragments, but only was useful in that case before Group fragments existed.

Parameters
string$fieldname of the fragment, with the document's type, like "product.picture"
Returns
array an array of all the Prismic::Fragment::Image objects found

§ getAllImageViews()

Prismic\WithFragments::getAllImageViews (   $field,
  $view 
)

Get all given views of all images for a given fragment name.

Parameters
string$fieldname of the fragments, with the document's type, like "product.picture"
string$viewname of the view, like "small"
Returns
array all views of the image
Deprecated:
deprecated because this only made sense when Group fragments didn't exist yet.

§ getBoolean()

Prismic\WithFragments::getBoolean (   $field)

Returns a boolean for any type of fragment that extends Prismic::Fragment::Text, if the text is either 'yes' or 'true', or null of the fragment is of the wrong type, or if it doesn't exist.

This works well with Select fragment for instance, where you set your values to "true" or "false".

Parameters
string$fieldname of the fragment, with the document's type, like "product.withchocolate"
Returns
boolean|null the directly usable boolean, or null if the fragment is of the wrong type or unset

§ getColor()

Prismic\WithFragments::getColor (   $field)

Returns the Color fragment as a manipulable object, and null of the fragment is of the wrong type, or if it doesn't exist.

Parameters
string$fieldname of the fragment, with the document's type, like "product.video"
Returns
Prismic::Fragment::Color the directly usable object, or null if the fragment is of the wrong type or unset

§ getDate()

Prismic\WithFragments::getDate (   $field,
  $pattern = null 
)

Returns the string for a Date fragment, potentially matching a given pattern, and null of the fragment is of the wrong type, or if it doesn't exist.

Parameters
string$fieldname of the fragment, with the document's type, like "product.publishedAt"
string$patternwith the syntax expected by the date function; null if not used
Returns
string|null the directly usable string, or null if the fragment is of the wrong type or unset

§ getEmbed()

Prismic\WithFragments::getEmbed (   $field)

Returns the Embed fragment as a manipulable object, and null of the fragment is of the wrong type, or if it doesn't exist.

Parameters
string$fieldname of the fragment, with the document's type, like "product.video"
Returns
Prismic::Fragment::Embed the directly usable object, or null if the fragment is of the wrong type or unset

§ getFragments()

Prismic\WithFragments::getFragments ( )

Returns the list of fragments of the document. You shouldn't have a reason to use this, as you can access fragments with get functions.

Returns
array the list of fragments in the document.

§ getGeoPoint()

Prismic\WithFragments::getGeoPoint (   $field)

Returns a GeoPoint fragment or null if the fragment is of the wrong type, or if it doesn't exist.

Parameters
string$fieldname of the fragment
Returns
GeoPoint Fragment

§ getGroup()

Prismic\WithFragments::getGroup (   $field)

Returns the Group fragment as a manipulable object, and null of the fragment is of the wrong type, or if it doesn't exist. This is the point of entry to then loop or search through the elements inside the Group fragment.

Parameters
string$fieldname of the fragment, with the document's type, like "product.gallery"
Returns
Prismic::Fragment::Group the directly usable object, or null if the fragment is of the wrong type or unset

§ getHtml()

Prismic\WithFragments::getHtml (   $field,
  $linkResolver = null 
)

Returns an HTML serialization for any kind of fragment. This is simply a faster way to write $doc->get($field)->asHtml($linkResolver).

Parameters
string$fieldname of the fragment, with the document's type, like "product.description"
\Prismic\LinkResolver$linkResolveran extension of the Prismic::LinkResolver class that you taught how to turn a prismic.io document in to a URL in your application
Returns
string the directly usable HTML code, or null if the fragment is unset

§ getImage()

Prismic\WithFragments::getImage (   $field)

Returns the usable Image fragment as an object, ready to be manipulated. This function also works on StructuredText fragment, and returns the first image in the fragment.

Parameters
string$fieldname of the fragment, with the document's type, like "product.picture"
Returns
Prismic::Fragment::Image the directly usable HTML code, or null if the fragment is unset

§ getImageView()

Prismic\WithFragments::getImageView (   $field,
  $view = null 
)

Returns the proper view of the given Image fragment, ready to be manipulated. This function also works on StructuredText fragments, to return the first Image, if the view is set to "main".

Parameters
string$fieldname of the fragment, with the document's type, like "product.picture"
string$viewname of the view, like "small"
Returns
Prismic::Fragment::ImageView the directly usable object symbolizing the view

§ getLink()

Prismic\WithFragments::getLink (   $field)

Returns the Link fragment as a manipulable object, and null of the fragment is of the wrong type, or if it doesn't exist.

Parameters
string$fieldname of the fragment, with the document's type, like "product.gallery"
Returns
Prismic::Fragment::Link::LinkInterface the directly usable object, or null if the fragment is of the wrong type or unset

§ getNumber()

Prismic\WithFragments::getNumber (   $field,
  $pattern = null 
)

Returns the string for a Number fragment, potentially matching a given pattern, and null of the fragment is of the wrong type, or if it doesn't exist.

Parameters
string$fieldname of the fragment, with the document's type, like "product.price"
string$patternwith the syntax expected by sprintf; null if not used
Returns
string|null the Number fragment, the string representation if $pattern was set, or null if the fragment is of the wrong type or unset

§ getSliceZone()

Prismic\WithFragments::getSliceZone (   $field)

Returns the SliceZone fragment as a manipulable object, and null of the fragment is of the wrong type, or if it doesn't exist. This is the point of entry to then loop or search through the elements inside the Group fragment.

Parameters
string$fieldname of the fragment, with the document's type, like "product.gallery"
Returns
Prismic::Fragment::SliceZone the directly usable object, or null if the fragment is of the wrong type or unset

§ getStructuredText()

Prismic\WithFragments::getStructuredText (   $field)

Returns the StructuredText fragment as a manipulable object, and null of the fragment is of the wrong type, or if it doesn't exist.

Parameters
string$fieldname of the fragment, with the document's type, like "product.description"
Returns
Prismic::Fragment::StructuredText the directly usable object, or null if the fragment is of the wrong type or unset

§ getText()

Prismic\WithFragments::getText (   $field)

For any fragment type that makes sense to return as a text value, returns the text value.

Works with: StructuredText, Number, Color, Text and Date fragments. If fragment is of the wrong type or doesn't exist, returns an empty string.

Parameters
string$fieldname of the fragment, with the document's type, like "product.description"
Returns
string the directly usable string

§ getTimestamp()

Prismic\WithFragments::getTimestamp (   $field)

Returns the usable Timestamp fragment as an object, ready to be manipulated.

Parameters
string$fieldname of the fragment, with the document's type, like "product.publishedAt"
Returns
Prismic::Fragment::Timestamp|null the directly usable Timestamp, or null if the fragment is of the wrong type or unset

§ has()

Prismic\WithFragments::has (   $field)

Checks if a given fragment exists in the document.

Parameters
string$fieldname of the fragment, with the document's type, like "product.description"
Returns
boolean true if the fragment exists, false otherwise

§ parseFragment()

static Prismic\WithFragments::parseFragment (   $json)
static

Parses a given fragment. For internal usage.

Parameters
$jsonthe json bit retrieved from the API that represents any fragment.
Returns
Prismic::Fragment::FragmentInterface the manipulable object for that fragment.

§ parseFragments()

static Prismic\WithFragments::parseFragments (   $json)
static

Parse fragments from a json document. For internal usage.

Parameters
array$json
Returns
array

The documentation for this class was generated from the following file: