interface FieldHandlerInterface implements ViewsHandlerInterface (View source)

Base field handler that has no options and renders an unformatted field.

Methods

string
getPluginId()

Gets the plugin_id of the plugin instance.

array
getPluginDefinition()

Gets the definition of the plugin implementation.

string
getBaseId()

Gets the base_plugin_id of the plugin instance.

string|null
getDerivativeId()

Gets the derivative_id of the plugin instance.

string
getProvider()

Returns the plugin provider.

pluginTitle()

Return the human readable name of the display.

usesOptions()

Returns the usesOptions property.

filterByDefinedOptions(array $storage)

Filter out stored options depending on the defined options.

validateOptionsForm($form, FormStateInterface $form_state)

Validate the options form.

summaryTitle()

Returns the summary of the settings in the display.

static array
preRenderAddFieldsetMarkup(array $form)

Moves form elements into fieldsets for presentation purposes.

static 
create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)

{@inheritdoc}

init(ViewExecutable $view, DisplayPluginBase $display, array $options = NULL)

Initialize the plugin.

submitOptionsForm($form, FormStateInterface $form_state)

Handle any special handling on the validate form.

globalTokenForm(array $form, FormStateInterface $form_state)

Adds elements for available core tokens to a form.

array
getAvailableGlobalTokens(bool $prepared = FALSE, array $types = [])

Returns an array of available token replacements.

static array
preRenderFlattenData(array $form)

Flattens the structure of form elements.

string
globalTokenReplace(string $string = '', array $options = [])

Returns a string with any core tokens replaced.

destroy()

Clears a plugin.

An
validate()

Validate that the plugin is correct and can be saved.

query()

Add anything to the query that we might need to.

unpackOptions($storage, $options, $definition = NULL, $all = TRUE, $check = TRUE)

Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.

buildOptionsForm($form, FormStateInterface $form_state)

Provide a form to edit options for this plugin.

themeFunctions()

Provide a full list of possible theme templates used by this style.

preQuery()

Run before the view is built.

string
getEntityType()

Determines the entity type used by this handler.

broken()

Determines if the handler is considered 'broken', meaning it's a placeholder used when a handler can't be found.

ensureMyTable()

Ensure the main table for this handler is in the query. This is used a lot.

bool
access(AccountInterface $account)

Check whether given user has access to this handler.

getJoin()

Get the join object that should be used for this handler.

sanitizeValue($value, $type = NULL)

Sanitize the value for output.

static JoinPluginBase
getTableJoin(string $table, string $base_table)

Fetches a handler to join one table to a primary table from the data cache.

getField($field = NULL)

Shortcut to get a handler's raw field value.

postExecute($values)

Run after the view is executed, before the result is cached.

showExposeForm($form, FormStateInterface $form_state)

Shortcut to display the exposed options form.

setRelationship()

Called just prior to query(), this lets a handler set up any relationship it needs.

adminLabel($short = FALSE)

Return a string representing this handler's name in the UI.

static object
breakString(string $str, bool $force_int = FALSE)

Breaks x,y,z and x+y+z into an array.

adminSummary()

Provide text for the administrative summary.

clickSort(string $order)

Adds an ORDER BY clause to the query for click sort columns.

bool
clickSortable()

Determines if this field is click sortable.

label()

Gets this field's label.

elementType(bool $none_supported = FALSE, bool $default_empty = FALSE, bool $inline = FALSE)

Returns an HTML element based upon the field's element type.

elementLabelType(bool $none_supported = FALSE, bool $default_empty = FALSE)

Returns an HTML element for the label based upon the field's element type.

elementWrapperType(bool $none_supported = FALSE, bool $default_empty = FALSE)

Returns an HTML element for the wrapper based upon the field's element type.

getElements()

Provides a list of elements valid for field HTML.

elementClasses(bool $row_index = NULL)

Returns the class of the field.

tokenizeValue(string $value, bool $row_index = NULL)

Replaces a value with tokens from the last field.

elementLabelClasses(bool $row_index = NULL)

Returns the class of the field's label.

elementWrapperClasses(bool $row_index = NULL)

Returns the class of the field's wrapper.

getEntity(ResultRow $values)

Gets the entity matching the current row and relationship.

getValue(ResultRow $values, string $field = NULL)

Gets the value that's supposed to be rendered.

bool
useStringGroupBy()

Determines if this field will be available as an option to group the result by in the style settings.

preRender(ResultRow[] $values)

Runs before any fields are rendered.

render(ResultRow $values)

Renders the field.

string[]
postRender(ResultRow $row, $output)

Runs after every field has been rendered.

advancedRender(ResultRow $values)

Renders a field using advanced settings.

bool
isValueEmpty($value, bool $empty_zero, bool $no_skip_empty = TRUE)

Checks if a field value is empty.

renderText(array $alter)

Performs an advanced text render for the item.

array
getRenderTokens(mixed $item)

Gets the 'render' tokens to use for advanced rendering.

theme(ResultRow $values)

Renders row values using $this->themeFunctions() as #theme.

Details

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

string getBaseId()

Gets the base_plugin_id of the plugin instance.

Return Value

string

The base_plugin_id of the plugin instance.

string|null getDerivativeId()

Gets the derivative_id of the plugin instance.

Return Value

string|null

The derivative_id of the plugin instance NULL otherwise.

string getProvider()

Returns the plugin provider.

Return Value

string

pluginTitle()

Return the human readable name of the display.

This appears on the ui beside each plugin and beside the settings link.

usesOptions()

Returns the usesOptions property.

filterByDefinedOptions(array $storage)

Filter out stored options depending on the defined options.

Parameters

array $storage

The stored options.

validateOptionsForm($form, FormStateInterface $form_state)

Validate the options form.

Parameters

$form
FormStateInterface $form_state

summaryTitle()

Returns the summary of the settings in the display.

static array preRenderAddFieldsetMarkup(array $form)

Moves form elements into fieldsets for presentation purposes.

Many views forms use #tree = TRUE to keep their values in a hierarchy for easier storage. Moving the form elements into fieldsets during form building would break up that hierarchy. Therefore, we wait until the pre_render stage, where any changes we make affect presentation only and aren't reflected in $form_state->getValues().

Parameters

array $form

The form build array to alter.

Return Value

array

The form build array.

static create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition)

{@inheritdoc}

Parameters

ContainerInterface $container
array $configuration
$plugin_id
$plugin_definition

init(ViewExecutable $view, DisplayPluginBase $display, array $options = NULL)

Initialize the plugin.

Parameters

ViewExecutable $view

The view object.

DisplayPluginBase $display

The display handler.

array $options

The options configured for this plugin.

submitOptionsForm($form, FormStateInterface $form_state)

Handle any special handling on the validate form.

Parameters

$form
FormStateInterface $form_state

globalTokenForm(array $form, FormStateInterface $form_state)

Adds elements for available core tokens to a form.

Parameters

array $form

The form array to alter, passed by reference.

FormStateInterface $form_state

The current state of the form.

array getAvailableGlobalTokens(bool $prepared = FALSE, array $types = [])

Returns an array of available token replacements.

Parameters

bool $prepared

Whether to return the raw token info for each token or an array of prepared tokens for each type. E.g. "[view:name]".

array $types

An array of additional token types to return, defaults to 'site' and 'view'.

Return Value

array

An array of available token replacement info or tokens, grouped by type.

static array preRenderFlattenData(array $form)

Flattens the structure of form elements.

If a form element has #flatten = TRUE, then all of its children get moved to the same level as the element itself. So $form['to_be_flattened'][$key] becomes $form[$key], and $form['to_be_flattened'] gets unset.

Parameters

array $form

The form build array to alter.

Return Value

array

The form build array.

string globalTokenReplace(string $string = '', array $options = [])

Returns a string with any core tokens replaced.

Parameters

string $string

The string to preform the token replacement on.

array $options

An array of options, as passed to \Drupal\Core\Utility\Token::replace().

Return Value

string

The tokenized string.

destroy()

Clears a plugin.

An validate()

Validate that the plugin is correct and can be saved.

Return Value

An

array of error strings to tell the user what is wrong with this plugin.

query()

Add anything to the query that we might need to.

unpackOptions($storage, $options, $definition = NULL, $all = TRUE, $check = TRUE)

Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.

Parameters

$storage
$options
$definition
$all
$check

buildOptionsForm($form, FormStateInterface $form_state)

Provide a form to edit options for this plugin.

Parameters

$form
FormStateInterface $form_state

themeFunctions()

Provide a full list of possible theme templates used by this style.

preQuery()

Run before the view is built.

This gives all the handlers some time to set up before any handler has been fully run.

string getEntityType()

Determines the entity type used by this handler.

If this handler uses a relationship, the base class of the relationship is taken into account.

Return Value

string

The machine name of the entity type.

broken()

Determines if the handler is considered 'broken', meaning it's a placeholder used when a handler can't be found.

ensureMyTable()

Ensure the main table for this handler is in the query. This is used a lot.

bool access(AccountInterface $account)

Check whether given user has access to this handler.

Parameters

AccountInterface $account

The user account to check.

Return Value

bool

TRUE if the user has access to the handler, FALSE otherwise.

getJoin()

Get the join object that should be used for this handler.

This method isn't used a great deal, but it's very handy for easily getting the join if it is necessary to make some changes to it, such as adding an 'extra'.

ViewsRenderPipelineMarkup sanitizeValue($value, $type = NULL)

Sanitize the value for output.

Parameters

$value

The value being rendered.

$type

The type of sanitization needed. If not provided, \Drupal\Component\Utility\Html::escape() is used.

Return Value

ViewsRenderPipelineMarkup

Returns the safe value.

static JoinPluginBase getTableJoin(string $table, string $base_table)

Fetches a handler to join one table to a primary table from the data cache.

Parameters

string $table

The table to join from.

string $base_table

The table to join to.

Return Value

JoinPluginBase

getField($field = NULL)

Shortcut to get a handler's raw field value.

This should be overridden for handlers with formulae or other non-standard fields. Because this takes an argument, fields overriding this can just call return parent::getField($formula)

Parameters

$field

postExecute($values)

Run after the view is executed, before the result is cached.

This gives all the handlers some time to modify values. This is primarily used so that handlers that pull up secondary data can put it in the $values so that the raw data can be used externally.

Parameters

$values

showExposeForm($form, FormStateInterface $form_state)

Shortcut to display the exposed options form.

Parameters

$form
FormStateInterface $form_state

setRelationship()

Called just prior to query(), this lets a handler set up any relationship it needs.

adminLabel($short = FALSE)

Return a string representing this handler's name in the UI.

Parameters

$short

static object breakString(string $str, bool $force_int = FALSE)

Breaks x,y,z and x+y+z into an array.

Parameters

string $str

The string to split.

bool $force_int

Enforce a numeric check.

Return Value

object

A stdClass object containing value and operator properties.

adminSummary()

Provide text for the administrative summary.

clickSort(string $order)

Adds an ORDER BY clause to the query for click sort columns.

Parameters

string $order

Either ASC or DESC

bool clickSortable()

Determines if this field is click sortable.

Return Value

bool

The value of 'click sortable' from the plugin definition, this defaults to TRUE if not set.

label()

Gets this field's label.

elementType(bool $none_supported = FALSE, bool $default_empty = FALSE, bool $inline = FALSE)

Returns an HTML element based upon the field's element type.

Parameters

bool $none_supported

Whether or not this HTML element is supported.

bool $default_empty

Whether or not this HTML element is empty by default.

bool $inline

Whether or not this HTML element is inline.

elementLabelType(bool $none_supported = FALSE, bool $default_empty = FALSE)

Returns an HTML element for the label based upon the field's element type.

Parameters

bool $none_supported

Whether or not this HTML element is supported.

bool $default_empty

Whether or not this HTML element is empty by default.

elementWrapperType(bool $none_supported = FALSE, bool $default_empty = FALSE)

Returns an HTML element for the wrapper based upon the field's element type.

Parameters

bool $none_supported

Whether or not this HTML element is supported.

bool $default_empty

Whether or not this HTML element is empty by default.

getElements()

Provides a list of elements valid for field HTML.

This function can be overridden by fields that want more or fewer elements available, though this seems like it would be an incredibly rare occurrence.

elementClasses(bool $row_index = NULL)

Returns the class of the field.

Parameters

bool $row_index

The index of current row.

tokenizeValue(string $value, bool $row_index = NULL)

Replaces a value with tokens from the last field.

This function actually figures out which field was last and uses its tokens so they will all be available.

Parameters

string $value

The raw string.

bool $row_index

The index of current row.

elementLabelClasses(bool $row_index = NULL)

Returns the class of the field's label.

Parameters

bool $row_index

The index of current row.

elementWrapperClasses(bool $row_index = NULL)

Returns the class of the field's wrapper.

Parameters

bool $row_index

The index of current row.

EntityInterface|null getEntity(ResultRow $values)

Gets the entity matching the current row and relationship.

Parameters

ResultRow $values

An object containing all retrieved values.

Return Value

EntityInterface|null

Returns the entity matching the values or NULL if there is no matching entity.

getValue(ResultRow $values, string $field = NULL)

Gets the value that's supposed to be rendered.

This api exists so that other modules can easy set the values of the field without having the need to change the render method as well.

Parameters

ResultRow $values

An object containing all retrieved values.

string $field

Optional name of the field where the value is stored.

bool useStringGroupBy()

Determines if this field will be available as an option to group the result by in the style settings.

Return Value

bool

TRUE if this field handler is groupable, otherwise FALSE.

preRender(ResultRow[] $values)

Runs before any fields are rendered.

This gives the handlers some time to set up before any handler has been rendered.

Parameters

ResultRow[] $values

An array of all ResultRow objects returned from the query.

string|MarkupInterface render(ResultRow $values)

Renders the field.

Parameters

ResultRow $values

The values retrieved from a single row of a view's query result.

Return Value

string|MarkupInterface

The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

string[] postRender(ResultRow $row, $output)

Runs after every field has been rendered.

This is meant to be used mainly to deal with field handlers whose output cannot be cached at row level but can be cached at display level. The typical example is the row counter. For completely uncacheable field output placeholders should be used.

Parameters

ResultRow $row

An array of all ResultRow objects returned from the query.

$output

The field rendered output.

Return Value

string[]

An associative array of post-render token values keyed by placeholder.

See also

UncacheableFieldHandlerTrait

string|MarkupInterface advancedRender(ResultRow $values)

Renders a field using advanced settings.

This renders a field normally, then decides if render-as-link and text-replacement rendering is necessary.

Parameters

ResultRow $values

The values retrieved from a single row of a view's query result.

Return Value

string|MarkupInterface

The advanced rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

bool isValueEmpty($value, bool $empty_zero, bool $no_skip_empty = TRUE)

Checks if a field value is empty.

Parameters

$value

The field value.

bool $empty_zero

Whether or not this field is configured to consider 0 as empty.

bool $no_skip_empty

Whether or not to use empty() to check the value.

Return Value

bool

TRUE if the value is considered empty, FALSE otherwise.

string|MarkupInterface renderText(array $alter)

Performs an advanced text render for the item.

This is separated out as some fields may render lists, and this allows each item to be handled individually.

Parameters

array $alter

The alter array of options to use.

  • max_length: Maximum length of the string, the rest gets truncated.
  • word_boundary: Trim only on a word boundary.
  • ellipsis: Show an ellipsis (…) at the end of the trimmed string.
  • html: Make sure that the html is correct.

Return Value

string|MarkupInterface

The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

array getRenderTokens(mixed $item)

Gets the 'render' tokens to use for advanced rendering.

This runs through all of the fields and arguments that are available and gets their values. This will then be used in one giant str_replace().

Parameters

mixed $item

The item to render.

Return Value

array

An array of available tokens

string|MarkupInterface theme(ResultRow $values)

Renders row values using $this->themeFunctions() as #theme.

Parameters

ResultRow $values

Holds single row of a view's result set.

Return Value

string|MarkupInterface

Returns rendered output of the given theme implementation. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.