Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ComponentElement.php

function ComponentElement::preRenderComponent

Expands a component into an inline template with an attachment.

Parameters

array $element: The element to process. See main class documentation for properties.

Return value

array The form element.

Throws

\Drupal\Core\Render\Component\Exception\InvalidComponentDataException

File

core/lib/Drupal/Core/Render/Element/ComponentElement.php, line 51

Class

ComponentElement
Provides a Single-Directory Component render element.

Namespace

Drupal\Core\Render\Element

Code

public function preRenderComponent(array $element) : array {
    $props = $element['#props'];
    $props_alter_callbacks = $element['#propsAlter'];
    // This callback can be used to prepare the context. For instance to replace
    // tokens in the props.
    $props = array_reduce($props_alter_callbacks, fn(array $carry, callable $callback) => $this->doTrustedCallback($callback, [
        $carry,
    ], '%s is not trusted'), $props);
    $inline_template = $this->generateComponentTemplate($element['#component'], $element['#slots'], $element['#slotsAlter'], $props);
    $element['inline-template'] = [
        '#type' => 'inline_template',
        '#template' => $inline_template,
        '#context' => $props,
    ];
    return $element;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal