/Drupal 8

abstract class RenderElement

Provides a base class for render element plugins.

Render elements are referenced in render arrays; see the Render API topic for an overview of render arrays and render elements.

The elements of render arrays are divided up into properties (whose keys start with #) and children (whose keys do not start with #). The properties provide data or settings that are used in rendering. Some properties are specific to a particular type of render element, some are available for any render element, and some are available for any form input element. A list of the properties that are available for all render elements follows; the properties that are for all form elements are documented on \Drupal\Core\Render\Element\FormElement, and properties specific to a particular element are documented on that element's class. See the Render API topic for a list of the most commonly-used properties.

Many of the properties are strings that are displayed to users. These strings, if they are literals provided by your module, should be internationalized and translated; see the Internationalization topic for more information. Note that although in the properies list that follows, they are designated to be of type string, they would generally end up being \Drupal\Core\StringTranslation\TranslatableMarkup objects instead.

Here is the list of the properties used during the rendering of all render elements:

  • #access: (bool) Whether the element is accessible or not. When FALSE, the element is not rendered and user-submitted values are not taken into consideration.
  • #access_callback: A callable or function name to call to check access. Argument: element.
  • #allowed_tags: (array) Array of allowed HTML tags for XSS filtering of #markup, #prefix, #suffix, etc.
  • #attached: (array) Array of attachments associated with the element. See the "Attaching libraries in render arrays" section of the Render API topic for an overview, and \Drupal\Core\Render\AttachmentsResponseProcessorInterface::processAttachments for a list of what this can contain. Besides this list, it may also contain a 'placeholders' element; see the Placeholders section of the Render API topic for an overview.
  • #attributes: (array) HTML attributes for the element. The first-level keys are the attribute names, such as 'class', and the attributes are usually given as an array of string values to apply to that attribute (the rendering system will concatenate them together into a string in the HTML output).
  • #cache: (array) Cache information. See the Caching section of the Render API topic for more information.
  • #children: (array, internal) Array of child elements of this element. Set and used during the rendering process.
  • #create_placeholder: (bool) TRUE if the element has placeholders that are generated by #lazy_builder callbacks. Set internally during rendering in some cases. See also #attached.
  • #defaults_loaded: (bool) Set to TRUE during rendering when the defaults for the element #type have been added to the element.
  • #id: (string) The HTML ID on the element. This is automatically set for form elements, but not for all render elements; you can override the default value or add an ID by setting this property.
  • #lazy_builder: (array) Array whose first element is a lazy building callback (callable), and whose second is an array of scalar arguments to the callback. To use lazy building, the element array must be very simple: no properties except #lazy_builder, #cache, #weight, and #create_placeholder, and no children. A lazy builder callback typically generates #markup and/or placeholders; see the Placeholders section of the Render API topic for information about placeholders.
  • #markup: (string) During rendering, this will be set to the HTML markup output. It can also be set on input, as a fallback if there is no theming for the element. This will be filtered for XSS problems during rendering; see also #plain_text and #allowed_tags.
  • #plain_text: (string) Elements can set this instead of #markup. All HTML tags will be escaped in this text, and if both #plain_text and #markup are provided, #plain_text is used.
  • #post_render: (array) Array of callables or function names, which are called after the element is rendered. Arguments: rendered element string, children.
  • #pre_render: (array) Array of callables or function names, which are called just before the element is rendered. Argument: $element. Return value: an altered $element.
  • #prefix: (string) Text to render before the entire element output. See also #suffix. If it is not already wrapped in a safe markup object, will be filtered for XSS safety.
  • #printed: (bool, internal) Set to TRUE when an element and its children have been rendered.
  • #render_children: (bool, internal) Set to FALSE by the rendering process if the #theme call should be bypassed (normally, the theme is used to render the children). Set to TRUE by the rendering process if the children should be rendered by rendering each one separately and concatenating.
  • #suffix: (string) Text to render after the entire element output. See also #prefix. If it is not already wrapped in a safe markup object, will be filtered for XSS safety.
  • #theme: (string) Name of the theme hook to use to render the element. A default is generally set for elements; users of the element can override this (typically by adding __suggestion suffixes).
  • #theme_wrappers: (array) Array of theme hooks, which are invoked after the element and children are rendered, and before #post_render functions.
  • #type: (string) The machine name of the type of render/form element.
  • #weight: (float) The sort order for rendering, with lower numbers coming before higher numbers. Default if not provided is zero; elements with the same weight are rendered in the order they appear in the render array.


See also




Plugin API

Related topics

Render API overview
Overview of the Theme system and Render API.


core/lib/Drupal/Core/Render/Element/RenderElement.php, line 124




Name Modifiers Type Description
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function
DependencySerializationTrait::__wakeup public function
ElementInterface::getInfo public function Returns the element properties for this element.
PluginBase::$configuration protected property Configuration information passed into the plugin.
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object.
RenderElement::preRenderAjaxForm public static function Adds Ajax information about an element to communicate with JavaScript.
RenderElement::preRenderGroup public static function Adds members of this group as actual elements for rendering.
RenderElement::processAjaxForm public static function Form element processing handler for the #ajax form property.
RenderElement::processGroup public static function Arranges elements into groups.
RenderElement::setAttributes public static function Sets a form element's class attribute. Overrides ElementInterface::setAttributes
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use.
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.