render

render(&$element)

Renders an element.

This function renders an element. The top level element is shown with show() before rendering, so it will always be rendered even if hide() had been previously used on it.

Parameters

$element: The element to be rendered.

Return value

The rendered element.

See also

\Drupal\Core\Render\RendererInterface

show()

hide()

File

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

Code

function render(&$element) {
  if (!$element && $element !== 0) {
    return NULL;
  }
  if (is_array($element)) {
    // Early return if this element was pre-rendered (no need to re-render).
    if (isset($element['#printed']) && $element['#printed'] == TRUE && isset($element['#markup']) && strlen($element['#markup']) > 0) {
      return $element['#markup'];
    }
    show($element);
    return \Drupal::service('renderer')->render($element);
  }
  else {
    // Safe-guard for inappropriate use of render() on flat variables: return
    // the variable as-is.
    return $element;
  }
}
doc_Drupal
2016-10-29 09:37:24
Comments
Leave a Comment

Please login to continue.