Skip to content
Snippets Groups Projects
Verified Commit d41f1a01 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3383449 by catch, Wim Leers, Kingdutch: Add Fibers support to Drupal\Core\Render\Renderer

parent 108150c6
No related branches found
No related tags found
40 merge requests!54479.5.x SF update,!5014Issue #3071143: Table Render Array Example Is Incorrect,!3878Removed unused condition head title for views,!38582585169-10.1.x,!3818Issue #2140179: $entity->original gets stale between updates,!3742Issue #3328429: Create item list field formatter for displaying ordered and unordered lists,!3731Claro: role=button on status report items,!3668Resolve #3347842 "Deprecate the trusted",!3651Issue #3347736: Create new SDC component for Olivero (header-search),!3546refactored dialog.pcss file,!3531Issue #3336994: StringFormatter always displays links to entity even if the user in context does not have access,!3502Issue #3335308: Confusing behavior with FormState::setFormState and FormState::setMethod,!3452Issue #3332701: Refactor Claro's tablesort-indicator stylesheet,!3451Issue #2410579: Allows setting the current language programmatically.,!3355Issue #3209129: Scrolling problems when adding a block via layout builder,!3226Issue #2987537: Custom menu link entity type should not declare "bundle" entity key,!3154Fixes #2987987 - CSRF token validation broken on routes with optional parameters.,!3147Issue #3328457: Replace most substr($a, $i) where $i is negative with str_ends_with(),!3146Issue #3328456: Replace substr($a, 0, $i) with str_starts_with(),!3133core/modules/system/css/components/hidden.module.css,!31312878513-10.1.x,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!2812Issue #3312049: [Followup] Fix Drupal.Commenting.FunctionComment.MissingReturnType returns for NULL,!2614Issue #2981326: Replace non-test usages of \Drupal::logger() with IoC injection,!2378Issue #2875033: Optimize joins and table selection in SQL entity query implementation,!2334Issue #3228209: Add hasRole() method to AccountInterface,!2062Issue #3246454: Add weekly granularity to views date sort,!1591Issue #3199697: Add JSON:API Translation experimental module,!1255Issue #3238922: Refactor (if feasible) uses of the jQuery serialize function to use vanillaJS,!1105Issue #3025039: New non translatable field on translatable content throws error,!1073issue #3191727: Focus states on mobile second level navigation items fixed,!10223132456: Fix issue where views instances are emptied before an ajax request is complete,!877Issue #2708101: Default value for link text is not saved,!844Resolve #3036010 "Updaters",!673Issue #3214208: FinishResponseSubscriber could create duplicate headers,!617Issue #3043725: Provide a Entity Handler for user cancelation,!579Issue #2230909: Simple decimals fail to pass validation,!560Move callback classRemove outside of the loop,!555Issue #3202493,!485Sets the autocomplete attribute for username/password input field on login form.
Pipeline #27427 failed
Pipeline: drupal

#27436

    Pipeline: drupal

    #27435

      Pipeline: drupal

      #27434

        +1
        ...@@ -162,22 +162,43 @@ public function renderPlain(&$elements) { ...@@ -162,22 +162,43 @@ public function renderPlain(&$elements) {
        } }
        /** /**
        * {@inheritdoc} * Renders a placeholder into markup.
        *
        * @param array $placeholder_element
        * The placeholder element by reference.
        *
        * @return \Drupal\Component\Render\MarkupInterface|string
        * The rendered HTML.
        */ */
        public function renderPlaceholder($placeholder, array $elements) { protected function doRenderPlaceholder(array &$placeholder_element): MarkupInterface|string {
        // Get the render array for the given placeholder
        $placeholder_elements = $elements['#attached']['placeholders'][$placeholder];
        // Prevent the render array from being auto-placeholdered again. // Prevent the render array from being auto-placeholdered again.
        $placeholder_elements['#create_placeholder'] = FALSE; $placeholder_element['#create_placeholder'] = FALSE;
        // Render the placeholder into markup. // Render the placeholder into markup.
        $markup = $this->renderPlain($placeholder_elements); $markup = $this->renderPlain($placeholder_element);
        return $markup;
        }
        /**
        * Replaces a placeholder with its markup.
        *
        * @param string $placeholder
        * The placeholder HTML.
        * @param \Drupal\Component\Render\MarkupInterface|string $markup
        * The markup to replace the placeholder with.
        * @param array $elements
        * The render array that the placeholder is from.
        * @param array $placeholder_element
        * The placeholder element render array.
        *
        * @return \Drupal\Component\Render\MarkupInterface|string
        * The rendered HTML.
        */
        protected function doReplacePlaceholder(string $placeholder, string|MarkupInterface $markup, array $elements, array $placeholder_element): array {
        // Replace the placeholder with its rendered markup, and merge its // Replace the placeholder with its rendered markup, and merge its
        // bubbleable metadata with the main elements'. // bubbleable metadata with the main elements'.
        $elements['#markup'] = Markup::create(str_replace($placeholder, $markup, $elements['#markup'])); $elements['#markup'] = Markup::create(str_replace($placeholder, $markup, $elements['#markup']));
        $elements = $this->mergeBubbleableMetadata($elements, $placeholder_elements); $elements = $this->mergeBubbleableMetadata($elements, $placeholder_element);
        // Remove the placeholder that we've just rendered. // Remove the placeholder that we've just rendered.
        unset($elements['#attached']['placeholders'][$placeholder]); unset($elements['#attached']['placeholders'][$placeholder]);
        ...@@ -185,6 +206,16 @@ public function renderPlaceholder($placeholder, array $elements) { ...@@ -185,6 +206,16 @@ public function renderPlaceholder($placeholder, array $elements) {
        return $elements; return $elements;
        } }
        /**
        * {@inheritdoc}
        */
        public function renderPlaceholder($placeholder, array $elements) {
        // Get the render array for the given placeholder
        $placeholder_element = $elements['#attached']['placeholders'][$placeholder];
        $markup = $this->doRenderPlaceholder($placeholder_element);
        return $this->doReplacePlaceholder($placeholder, $markup, $elements, $placeholder_element);
        }
        /** /**
        * {@inheritdoc} * {@inheritdoc}
        */ */
        ...@@ -665,13 +696,47 @@ protected function replacePlaceholders(array &$elements) { ...@@ -665,13 +696,47 @@ protected function replacePlaceholders(array &$elements) {
        // First render all placeholders except 'status messages' placeholders. // First render all placeholders except 'status messages' placeholders.
        $message_placeholders = []; $message_placeholders = [];
        $fibers = [];
        foreach ($elements['#attached']['placeholders'] as $placeholder => $placeholder_element) { foreach ($elements['#attached']['placeholders'] as $placeholder => $placeholder_element) {
        if (isset($placeholder_element['#lazy_builder']) && $placeholder_element['#lazy_builder'][0] === 'Drupal\Core\Render\Element\StatusMessages::renderMessages') { if (isset($placeholder_element['#lazy_builder']) && $placeholder_element['#lazy_builder'][0] === 'Drupal\Core\Render\Element\StatusMessages::renderMessages') {
        $message_placeholders[] = $placeholder; $message_placeholders[] = $placeholder;
        } }
        else { else {
        $elements = $this->renderPlaceholder($placeholder, $elements); // Get the render array for the given placeholder
        $fibers[$placeholder] = new \Fiber(function () use ($placeholder_element) {
        return [$this->doRenderPlaceholder($placeholder_element), $placeholder_element];
        });
        }
        }
        while (count($fibers) > 0) {
        $iterations = 0;
        foreach ($fibers as $placeholder => $fiber) {
        if (!$fiber->isStarted()) {
        $fiber->start();
        }
        elseif ($fiber->isSuspended()) {
        $fiber->resume();
        }
        // If the Fiber hasn't terminated by this point, move onto the next
        // placeholder, we'll resume this fiber again when we get back here.
        if (!$fiber->isTerminated()) {
        // If we've gone through the placeholders once already, and they're
        // still not finished, then start to allow code higher up the stack to
        // get on with something else.
        if ($iterations) {
        $fiber = \Fiber::getCurrent();
        if ($fiber !== NULL) {
        $fiber->suspend();
        }
        }
        continue;
        }
        [$markup, $placeholder_element] = $fiber->getReturn();
        $elements = $this->doReplacePlaceholder($placeholder, $markup, $elements, $placeholder_element);
        unset($fibers[$placeholder]);
        } }
        $iterations++;
        } }
        // Then render 'status messages' placeholders. // Then render 'status messages' placeholders.
        ......
        ...@@ -314,6 +314,11 @@ public static function callback($animal, $use_animal_as_array_key = FALSE) { ...@@ -314,6 +314,11 @@ public static function callback($animal, $use_animal_as_array_key = FALSE) {
        * A renderable array. * A renderable array.
        */ */
        public static function callbackPerUser($animal) { public static function callbackPerUser($animal) {
        // As well as adding the user cache context, additionally suspend the
        // current Fiber if there is one.
        if ($fiber = \Fiber::getCurrent()) {
        $fiber->suspend();
        }
        $build = static::callback($animal); $build = static::callback($animal);
        $build['#cache']['contexts'][] = 'user'; $build['#cache']['contexts'][] = 'user';
        return $build; return $build;
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment