function ElementInfoManager::buildInfo

Same name in other branches
  1. 9 core/lib/Drupal/Core/Render/ElementInfoManager.php \Drupal\Core\Render\ElementInfoManager::buildInfo()
  2. 8.9.x core/lib/Drupal/Core/Render/ElementInfoManager.php \Drupal\Core\Render\ElementInfoManager::buildInfo()
  3. 11.x core/lib/Drupal/Core/Render/ElementInfoManager.php \Drupal\Core\Render\ElementInfoManager::buildInfo()

Builds up all element information.

Parameters

string $theme_name: The theme name.

Return value

array

1 call to ElementInfoManager::buildInfo()
ElementInfoManager::getInfo in core/lib/Drupal/Core/Render/ElementInfoManager.php

File

core/lib/Drupal/Core/Render/ElementInfoManager.php, line 116

Class

ElementInfoManager
Provides a plugin manager for element plugins.

Namespace

Drupal\Core\Render

Code

protected function buildInfo($theme_name) {
    // Get cached definitions.
    $cid = $this->getCid($theme_name);
    if ($cache = $this->cacheBackend
        ->get($cid)) {
        return $cache->data;
    }
    // Otherwise, rebuild and cache.
    $info = [];
    $previous_error_handler = set_error_handler(function ($severity, $message, $file, $line) use (&$previous_error_handler) {
        // Ignore deprecations while building element information.
        if ($severity === E_USER_DEPRECATED) {
            // Don't execute PHP internal error handler.
            return TRUE;
        }
        if ($previous_error_handler) {
            return $previous_error_handler($severity, $message, $file, $line);
        }
    });
    foreach ($this->getDefinitions() as $element_type => $definition) {
        $element = $this->createInstance($element_type);
        $element_info = $element->getInfo();
        // If this is element is to be used exclusively in a form, denote that it
        // will receive input, and assign the value callback.
        if ($element instanceof FormElementInterface) {
            $element_info['#input'] = TRUE;
            $element_info['#value_callback'] = [
                $definition['class'],
                'valueCallback',
            ];
        }
        $info[$element_type] = $element_info;
    }
    restore_error_handler();
    foreach ($info as $element_type => $element) {
        $info[$element_type]['#type'] = $element_type;
    }
    // Allow modules to alter the element type defaults.
    $this->moduleHandler
        ->alter('element_info', $info);
    $this->themeManager
        ->alter('element_info', $info);
    $this->cacheBackend
        ->set($cid, $info);
    return $info;
}

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