Serializer
class Serializer extends StylePluginBase implements CacheableDependencyInterface (View source)
The style plugin for serialized output formats.
Traits
Wrapper methods for \Drupal\Core\StringTranslation\TranslationInterface.
Provides dependency injection friendly methods for serialization.
Provides a trait for the messenger service.
Constants
| DERIVATIVE_SEPARATOR |
A string which is used to separate base plugin IDs from the derivative ID. |
| INCLUDE_NEGOTIATED |
Include negotiated languages when listing languages. |
| INCLUDE_ENTITY |
Include entity row languages when listing languages. |
| VIEWS_QUERY_LANGUAGE_SITE_DEFAULT |
Query string to indicate the site default language. |
Properties
| protected string | $pluginId | The plugin_id. |
from PluginBase |
| protected array | $pluginDefinition | The plugin implementation definition. |
from PluginBase |
| protected array | $configuration | Configuration information passed into the plugin. |
from PluginBase |
| protected TranslationInterface | $stringTranslation | The string translation service. |
from StringTranslationTrait |
| protected array | $_serviceIds | An array of service IDs keyed by property name used for serialization. |
from DependencySerializationTrait |
| protected array | $_entityStorages | An array of entity type IDs keyed by the property name of their storages. |
from DependencySerializationTrait |
| protected MessengerInterface | $messenger | The messenger. |
from MessengerTrait |
| array | $options | Options for this plugin will be held here. |
from PluginBase |
| ViewExecutable | $view | The top object of a view. |
from PluginBase |
| DisplayPluginBase | $displayHandler | The display object this plugin is for. |
from PluginBase |
| array | $definition | Plugins's definition |
from PluginBase |
| protected | $usesOptions | {@inheritdoc} | from StylePluginBase |
| protected RendererInterface | $renderer | Stores the render API renderer. |
from PluginBase |
| protected | $rowTokens | Store all available tokens row rows. |
from StylePluginBase |
| protected | $usesRowPlugin | {@inheritdoc} | |
| protected bool | $usesRowClass | Does the style plugin support custom css class for the rows. |
from StylePluginBase |
| protected | $usesGrouping | {@inheritdoc} | |
| protected bool | $usesFields | Does the style plugin for itself support to add fields to its output. |
from StylePluginBase |
| protected array|null | $rendered_fields | Stores the rendered field values, keyed by the row index and field name. |
from StylePluginBase |
| protected string | $groupingTheme | The theme function used to render the grouping set. |
from StylePluginBase |
| protected bool | $defaultFieldLabels | Should field labels be enabled by default. |
from StylePluginBase |
| protected Serializer | $serializer | The serializer which serializes the views result. |
|
| protected array | $formats | The available serialization formats. |
|
| protected string[] | $formatProviders | The serialization format providers, keyed by format. |
Methods
Constructs a Plugin object.
Translates a string to the current language or to a given language.
Formats a string containing a count of items.
Returns the number of plurals supported by a given language.
Gets the string translation service.
Creates an instance of the plugin.
Overrides \Drupal\views\Plugin\views\PluginBase::init().
Information about options for all kinds of purposes will be held here.
Fills up the options of the plugin with defaults.
Filter out stored options depending on the defined options.
Do the work to filter out stored options depending on the defined options.
Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
Provide a form to edit options for this plugin.
Lists the trusted callbacks provided by the implementing class.
Handle any special handling on the validate form.
Provide a full list of possible theme templates used by this style.
Returns a string with any core tokens replaced.
Replaces Views' tokens in a given string. The resulting string will be sanitized with Xss::filterAdmin.
Returns an array of available token replacements.
Adds elements for available core tokens to a form.
Moves form elements into fieldsets for presentation purposes.
Flattens the structure of form elements.
Calculates dependencies for the configured plugin.
Makes an array of languages, optionally including special languages.
Returns substitutions for Views queries for languages.
Return TRUE if this style enables field labels by default.
Return the token replaced row class for the specified row.
Take a value and apply token replacement logic to it.
Should the output of the style plugin be rendered even if it's a empty view.
Provide a form in the views wizard if this style is selected.
Alter the options of a display before they are added to the view.
Called by the view builder to see if this style handler wants to interfere with the sorts. If so it should build; if it returns any non-TRUE value, normal sorting will NOT be added to the query.
Called by the view builder to let the style build a second set of sorts that will come after any other sorts in the view.
Renders a group of rows of the grouped view.
Render the display in this style.
Group records as needed for rendering.
Renders all of the fields for a given style and store them on the object.
pre_render callback for view row field rendering.
Gets a rendered field.
Gets a list of all available formats that can be requested.
The maximum age for which this object may be cached.
The cache contexts associated with this object.
The cache tags associated with this object.
Returns an array of format options
Details
__construct(array $configuration, string $plugin_id, mixed $plugin_definition, SerializerInterface $serializer, array $serializer_formats, array $serializer_format_providers)
Constructs a Plugin object.
string
getPluginId()
Gets the plugin_id of the plugin instance.
string
getBaseId()
Gets the base_plugin_id of the plugin instance.
string|null
getDerivativeId()
Gets the derivative_id of the plugin instance.
array
getPluginDefinition()
Gets the definition of the plugin implementation.
bool
isConfigurable()
Determines if the plugin is configurable.
protected TranslatableMarkup
t(string $string, array $args = [], array $options = [])
Translates a string to the current language or to a given language.
See \Drupal\Core\StringTranslation\TranslatableMarkup::__construct() for important security information and usage guidelines.
In order for strings to be localized, make them available in one of the ways supported by the
protected
formatPlural($count, $singular, $plural, array $args = [], array $options = [])
Formats a string containing a count of items.
protected
getNumberOfPlurals($langcode = NULL)
Returns the number of plurals supported by a given language.
protected TranslationInterface
getStringTranslation()
Gets the string translation service.
$this
setStringTranslation(TranslationInterface $translation)
Sets the string translation service to use.
__sleep()
{@inheritdoc}
__wakeup()
{@inheritdoc}
setMessenger(MessengerInterface $messenger)
Sets the messenger.
MessengerInterface
messenger()
Gets the messenger.
static ContainerFactoryPluginInterface
create(ContainerInterface $container, array $configuration, string $plugin_id, mixed $plugin_definition)
Creates an instance of the plugin.
init(ViewExecutable $view, DisplayPluginBase $display, array $options = NULL)
Overrides \Drupal\views\Plugin\views\PluginBase::init().
The style options might come externally as the style can be sourced from at least two locations. If it's not included, look on the display.
protected array
defineOptions()
Information about options for all kinds of purposes will be held here.
protected
setOptionDefaults(array $storage, array $options)
Fills up the options of the plugin with defaults.
filterByDefinedOptions(array $storage)
Filter out stored options depending on the defined options.
protected
doFilterByDefinedOptions(array $storage, array $options)
Do the work to filter out stored options depending on the defined options.
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.
destroy()
Clears a plugin.
buildOptionsForm($form, FormStateInterface $form_state)
Provide a form to edit options for this plugin.
static string[]
trustedCallbacks()
Lists the trusted callbacks provided by the implementing class.
Trusted callbacks are public methods on the implementing class and can be invoked via \Drupal\Core\Security\DoTrustedCallbackTrait::doTrustedCallback().
validateOptionsForm($form, FormStateInterface $form_state)
Validate the options form.
submitOptionsForm($form, FormStateInterface $form_state)
Handle any special handling on the validate form.
query()
Add anything to the query that we might need to.
themeFunctions()
Provide a full list of possible theme templates used by this style.
An
validate()
Validate that the plugin is correct and can be saved.
summaryTitle()
Returns the summary of the settings in the display.
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.
string
globalTokenReplace(string $string = '', array $options = [])
Returns a string with any core tokens replaced.
protected string
viewsTokenReplace($text, $tokens)
Replaces Views' tokens in a given string. The resulting string will be sanitized with Xss::filterAdmin.
array
getAvailableGlobalTokens(bool $prepared = FALSE, array $types = [])
Returns an array of available token replacements.
globalTokenForm(array $form, FormStateInterface $form_state)
Adds elements for available core tokens to a form.
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().
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.
array
calculateDependencies()
Calculates dependencies for the configured plugin.
Dependencies are saved in the plugin's configuration entity and are used to determine configuration synchronization order. For example, if the plugin integrates with specific user roles, this method should return an array of dependencies listing the specified roles.
string
getProvider()
Returns the plugin provider.
protected array
listLanguages(int $flags = LanguageInterface::STATE_ALL, array $current_values = NULL)
Makes an array of languages, optionally including special languages.
static array
queryLanguageSubstitutions()
Returns substitutions for Views queries for languages.
This is needed so that the language options returned by PluginBase::listLanguages() are able to be used in queries. It is called by the Views module implementation of hook_views_query_substitutions() to get the language-related substitutions.
protected RendererInterface
getRenderer()
Returns the render API renderer.
bool
usesRowPlugin()
Returns the usesRowPlugin property.
bool
usesRowClass()
Returns the usesRowClass property.
bool
usesGrouping()
Returns the usesGrouping property.
bool
usesFields()
Return TRUE if this style also uses fields.
usesTokens()
Return TRUE if this style uses tokens.
Used to ensure we don't fetch tokens when not needed for performance.
bool
defaultFieldLabels()
Return TRUE if this style enables field labels by default.
getRowClass($row_index)
Return the token replaced row class for the specified row.
tokenizeValue($value, $row_index)
Take a value and apply token replacement logic to it.
evenEmpty()
Should the output of the style plugin be rendered even if it's a empty view.
wizardForm(array $form, FormStateInterface $form_state, string $type)
Provide a form in the views wizard if this style is selected.
wizardSubmit(array $form, FormStateInterface $form_state, WizardInterface $wizard, array $display_options, string $display_type)
Alter the options of a display before they are added to the view.
buildSort()
Called by the view builder to see if this style handler wants to interfere with the sorts. If so it should build; if it returns any non-TRUE value, normal sorting will NOT be added to the query.
buildSortPost()
Called by the view builder to let the style build a second set of sorts that will come after any other sorts in the view.
preRender($result)
Allow the style to do stuff before each row is rendered.
protected array
renderRowGroup(array $rows = [])
Renders a group of rows of the grouped view.
render()
Render the display in this style.
array
renderGroupingSets($sets)
Render the grouping sets.
Plugins may override this method if they wish some other way of handling grouping.
The
renderGrouping($records, $groupings = [], $group_rendered = NULL)
Group records as needed for rendering.
protected
renderFields(array $result)
Renders all of the fields for a given style and store them on the object.
array
elementPreRenderRow(array $data)
pre_render callback for view row field rendering.
MarkupInterface|null
getField(int $index, string $field)
Gets a rendered field.
getFieldValue($index, $field)
Get the raw field value.
array
getFormats()
Gets a list of all available formats that can be requested.
This will return the configured formats, or all formats if none have been selected.
int
getCacheMaxAge()
The maximum age for which this object may be cached.
string[]
getCacheContexts()
The cache contexts associated with this object.
These identify a specific variation/representation of the object.
Cache contexts are tokens: placeholders that are converted to cache keys by the @cache_contexts_manager service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.
string[]
getCacheTags()
The cache tags associated with this object.
When this object is modified, these cache tags will be invalidated.
protected string[]
getFormatOptions()
Returns an array of format options