Decide whether to improve "WidgetProviderBase->build()"

Created on 24 June 2021, almost 4 years ago
Updated 23 May 2025, 20 days ago

Problem/Motivation

Decide whether to improve "WidgetProviderBase->build()":

  /**
   * {@inheritdoc}
   */
  public function build() {
    $buildContent = $this->buildContent();
    if (is_array($buildContent)) {
      // The result was a Drupal render array, we have to render it, otherwise
      // it would be output in site context (template):
      // @todo LATER think about how we could inject the response here and how
      // to configure the expected response type (with or without theme...)
      // @see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21HtmlResponse.php/class/HtmlResponse/8.2.x
      // Render in bare page without template around:
      $attachments = \Drupal::service('html_response.attachments_processor');
      $renderer = \Drupal::service('renderer');
      $bareHtmlPageRenderer = new BareHtmlPageRenderer($renderer, $attachments);
      // @see https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21BareHtmlPageRendererInterface.php/interface/BareHtmlPageRendererInterface/8.2.x
      $response = $bareHtmlPageRenderer->renderBarePage($buildContent, $this->label(), 'markup');
      // @todo This still contains CSS from theme. We have to decide what we really want here and how to control:
      // ALTERNATIVE WITHOUT ANY WRAPPING HTML:
      // $response = new HtmlResponse();
      // // Render RenderArray as response:
      // $response->setContent($buildContent);
      return $response;
    }
    else {
      return $buildContent;
    }
    // }
    throw new WidgetValidationUnallowedReferrerException('You are not allowed to see this Widget!');
  }

Steps to reproduce

Proposed resolution

Discuss, whether to improve this.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇩🇪Germany Grevil

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024