Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By dawehner on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Introduced in version:
8.0-ALPHA7
Description:
Previously, Drupal provided several procedural utility functions for manipulating elements within renderable arrays.
These element_* functions are now deprecated; Instead, use \Drupal\Core\Render\Element
class methods.
Overview
Drupal 7 | Drupal 8 |
---|---|
element_children($elements) |
Element::children($elements) |
element_property |
Element::property() |
element_properties($element) |
Element::properties($element) |
element_child($element_name) |
Element::child($element_name); |
element_get_visible_children($elements) |
Element::getVisibleChildren($elements) |
element_set_attributes($element, array $attributes) |
Element::setAttributes($element, array $attributes); |
Code sample
Drupal 7
$elements = array();
$elements['foo'] = array(
'#markup' => 'Hello',
);
element_children($elements);
element_property('#markup');
element_properties($elements['foo']);
element_child('foo');
element_get_visible_children($elements);
element_set_attributes($elements['foo'], array('#title' => 'Custom title'));
Drupal 8
use Drupal\Core\Render\Element;
$elements = array();
$elements['foo'] = array(
'#markup' => 'Hello',
);
Element::children($elements);
Element::property('#markup');
Element::properties($elements['foo']);
Element::child('foo');
Element::getVisibleChildren($elements);
Element::setAttributes($elements['foo'], array('#title' => 'Custom title'));
Impacts:
Module developers