You are here

function hide in Drupal 10

Same name and namespace in other branches
  1. 8 core/includes/common.inc \hide()
  2. 7 includes/common.inc \hide()
  3. 9 core/includes/common.inc \hide()

Hides an element from later rendering.

The first time render() or RenderInterface::render() is called on an element tree, as each element in the tree is rendered, it is marked with a #printed flag and the rendered children of the element are cached. Subsequent calls to render() or RenderInterface::render() will not traverse the child tree of this element again: they will just use the cached children. So if you want to hide an element, be sure to call hide() on the element before its parent tree is rendered for the first time, as it will have no effect on subsequent renderings of the parent tree.

Parameters

$element: The element to be hidden.

Return value

The element.

See also

\Drupal\Core\Render\RendererInterface

render()

show()

1 call to hide()
template_preprocess_file_widget_multiple in core/modules/file/file.field.inc
Prepares variables for multi file form widget templates.
5 string references to 'hide'
BookBreadcrumbTest::testBreadcrumbAccessUpdates in core/modules/book/tests/src/Functional/BookBreadcrumbTest.php
Tests that the breadcrumb is updated when book access changes.
book_breadcrumb_test_node_access in core/modules/book/tests/modules/book_breadcrumb_test/book_breadcrumb_test.module
Implements hook_node_access().
bootstrap.inc in core/includes/bootstrap.inc
Functions that need to be loaded on every Drupal request.
system.logging.yml in core/modules/system/config/install/system.logging.yml
core/modules/system/config/install/system.logging.yml
system_logging.yml in core/modules/system/migrations/system_logging.yml
core/modules/system/migrations/system_logging.yml

File

core/includes/common.inc, line 370
Common functions that many Drupal modules will need to reference.

Code

function hide(&$element) {
  $element['#printed'] = TRUE;
  return $element;
}