ElementHelper

Type
Class
Namespace
craft\helpers
Inherits
craft\helpers\ElementHelper
Since
3.0

Class ElementHelper

View source

Public Methods

MethodDescription
createSlug()Creates a slug based on a given string.
doesUriFormatHaveSlugTag()Returns whether a given URL format has a proper {slug} tag.
editableSiteIdsForElement()Returns the editable site IDs for a given element, taking user permissions into account.
findSource()Returns an element type's source definition based on a given source key/path and context.
isElementEditable()Returns whether the given element is editable by the current user, taking user permissions into account.
setNextPrevOnElements()Given an array of elements, will go through and set the appropriate "next" and "prev" elements on them.
setUniqueUri()Sets the URI on an element using a given URL format, tweaking its slug if necessary to ensure it's unique.
supportedSitesForElement()Returns a list of sites that a given element supports.

createSlug()

Creates a slug based on a given string.

View source

Arguments

Returns

string

Signature

public static string createSlug ( \craft\helpers\string $str )

doesUriFormatHaveSlugTag()

Returns whether a given URL format has a proper {slug} tag.

View source

Arguments

Returns

boolean

Signature

public static boolean doesUriFormatHaveSlugTag ( \craft\helpers\string $uriFormat )

editableSiteIdsForElement()

Returns the editable site IDs for a given element, taking user permissions into account.

View source

Arguments

Returns

array

Signature

public static array editableSiteIdsForElement ( craft\base\ElementInterface $element )

findSource()

Returns an element type's source definition based on a given source key/path and context.

View source

Arguments

  • $elementType (string) – The element type class
  • $sourceKey (string) – The source key/path
  • $context (string, null) – The context

Returns

array, null – The source definition, or null if it cannot be found

Signature

public static array, null findSource ( \craft\helpers\string $elementType, \craft\helpers\string $sourceKey, \craft\helpers\string $context = null )

isElementEditable()

Returns whether the given element is editable by the current user, taking user permissions into account.

View source

Arguments

Returns

boolean

Signature

public static boolean isElementEditable ( craft\base\ElementInterface $element )

setNextPrevOnElements()

Given an array of elements, will go through and set the appropriate "next" and "prev" elements on them.

View source

Arguments

Signature

public static void setNextPrevOnElements ( array $elements )

setUniqueUri()

Sets the URI on an element using a given URL format, tweaking its slug if necessary to ensure it's unique.

View source

Arguments

Throws

Signature

public static void setUniqueUri ( craft\base\ElementInterface $element )

supportedSitesForElement()

Returns a list of sites that a given element supports. Each site is represented as an array with 'siteId' and 'enabledByDefault' keys.

View source

Arguments

Returns

array

Throws

Signature

public static array supportedSitesForElement ( craft\base\ElementInterface $element )