class Utilities

Same name and namespace in other branches
  1. 10 core/modules/sdc/src/Utilities.php \Drupal\sdc\Utilities

Shared utilities for SDC.

@internal

Hierarchy

Expanded class hierarchy of Utilities

3 files declare their use of Utilities
ComponentElement.php in core/modules/sdc/src/Element/ComponentElement.php
ComponentValidator.php in core/modules/sdc/src/Component/ComponentValidator.php
UtilitiesTest.php in core/modules/sdc/tests/src/Unit/UtilitiesTest.php

File

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

Namespace

Drupal\sdc
View source
final class Utilities {
    
    /**
     * This class should not be instantiated.
     */
    private function __construct() {
    }
    
    /**
     * Checks if a candidate is a render array.
     *
     * @param mixed $candidate
     *   The candidate.
     *
     * @return bool
     *   TRUE if it's a render array. FALSE otherwise.
     *
     * @todo Move this to the \Drupal\Core\Render\Element class.
     * @see https://www.drupal.org/i/3352858
     */
    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;
    }

}

Members

Title Sort descending Modifiers Object type Summary
Utilities::isRenderArray public static function Checks if a candidate is a render array.
Utilities::__construct private function This class should not be instantiated.

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