protected BigPipeStrategy::doProcessPlaceholders(array $placeholders)
Transforms placeholders to BigPipe placeholders, either no-JS or JS.
Parameters
array $placeholders: The placeholders to process.
Return value
array The BigPipe placeholders.
File
- core/modules/big_pipe/src/Render/Placeholder/BigPipeStrategy.php, line 136
Class
- BigPipeStrategy
- Defines the BigPipe placeholder strategy, to send HTML in chunks.
Namespace
Drupal\big_pipe\Render\Placeholder
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | protected function doProcessPlaceholders( array $placeholders ) { $overridden_placeholders = []; foreach ( $placeholders as $placeholder => $placeholder_elements ) { // BigPipe uses JavaScript and the DOM to find the placeholder to replace. // This means finding the placeholder to replace must be efficient. Most // placeholders are HTML, which we can find efficiently thanks to the // querySelector API. But some placeholders are HTML attribute values or // parts thereof, and potentially even plain text in DOM text nodes. For // BigPipe's JavaScript to find those placeholders, it would need to // iterate over all DOM text nodes. This is highly inefficient. Therefore, // the BigPipe placeholder strategy only converts HTML placeholders into // BigPipe placeholders. The other placeholders need to be replaced on the // server, not via BigPipe. // @see \Drupal\Core\Access\RouteProcessorCsrf::renderPlaceholderCsrfToken() // @see \Drupal\Core\Form\FormBuilder::renderFormTokenPlaceholder() // @see \Drupal\Core\Form\FormBuilder::renderPlaceholderFormAction() if ( $placeholder [0] !== '<' || $placeholder !== Html::normalize( $placeholder )) { $overridden_placeholders [ $placeholder ] = static ::createBigPipeNoJsPlaceholder( $placeholder , $placeholder_elements , TRUE); } else { // If the current request/session doesn't have JavaScript, fall back to // no-JS BigPipe. if ( $this ->requestStack->getCurrentRequest()->cookies->has( static ::NOJS_COOKIE)) { $overridden_placeholders [ $placeholder ] = static ::createBigPipeNoJsPlaceholder( $placeholder , $placeholder_elements , FALSE); } else { $overridden_placeholders [ $placeholder ] = static ::createBigPipeJsPlaceholder( $placeholder , $placeholder_elements ); } $overridden_placeholders [ $placeholder ][ '#cache' ][ 'contexts' ][] = 'cookies:' . static ::NOJS_COOKIE; } } return $overridden_placeholders ; } |
Please login to continue.