function Utilities::isRenderArray

Same name in other branches
  1. 10 core/modules/sdc/src/Utilities.php \Drupal\sdc\Utilities::isRenderArray()

Checks if a candidate is a render array.

@todo Move this to the \Drupal\Core\Render\Element class.

Parameters

mixed $candidate: The candidate.

Return value

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

See also

https://www.drupal.org/i/3352858

3 calls to Utilities::isRenderArray()
ComponentElement::generateComponentTemplate in core/modules/sdc/src/Element/ComponentElement.php
Generates the template to render the component.
ComponentValidator::validateProps in core/modules/sdc/src/Component/ComponentValidator.php
Validates that the props provided to the component.
UtilitiesTest::testIsRenderArray in core/modules/sdc/tests/src/Unit/UtilitiesTest.php
@covers ::isRenderArray @dataProvider dataProviderIsRenderArray

File

core/modules/sdc/src/Utilities.php, line 30

Class

Utilities
Shared utilities for SDC.

Namespace

Drupal\sdc

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.