function Element::isRenderArray

Same name and namespace in other branches
  1. 11.x core/lib/Drupal/Core/Render/Element.php \Drupal\Core\Render\Element::isRenderArray()

Checks if a candidate is a render array.

Parameters

mixed $candidate: The candidate.

Return value

bool TRUE if it's a render array. FALSE otherwise.

3 calls to Element::isRenderArray()
ComponentElement::generateComponentTemplate in core/lib/Drupal/Core/Render/Element/ComponentElement.php
Generates the template to render the component.
ComponentValidator::validateProps in core/lib/Drupal/Core/Theme/Component/ComponentValidator.php
Validates that the props provided to the component.
ElementTest::testIsRenderArray in core/tests/Drupal/Tests/Core/Render/ElementTest.php
@covers ::isRenderArray[[api-linebreak]] @dataProvider dataProviderIsRenderArray

File

core/lib/Drupal/Core/Render/Element.php, line 211

Class

Element
Provides helper methods for Drupal render elements.

Namespace

Drupal\Core\Render

Code

public static function isRenderArray($candidate) : bool {
  if (!is_array($candidate)) {
    return FALSE;
  }
  if (empty($candidate)) {
    return FALSE;
  }
  foreach ($candidate as $key => $value) {
    if (!is_int($key) && $key !== '' && $key[0] === '#') {
      continue;
    }
    if (!is_array($value)) {
      return FALSE;
    }
    if (!static::isRenderArray($value)) {
      return FALSE;
    }
  }
  return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.