Update to Drupal 8.1.5. For more information, see https://www.drupal.org/project/drupal/releases/8.1.5
This commit is contained in:
parent
13b6ca7cc2
commit
38ba7c357d
342 changed files with 7814 additions and 1534 deletions
|
@ -226,6 +226,13 @@ class BigPipe implements BigPipeInterface {
|
|||
$preg_placeholder_strings = array_map($prepare_for_preg_split, array_keys($no_js_placeholders));
|
||||
$fragments = preg_split('/' . implode('|', $preg_placeholder_strings) . '/', $html, NULL, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
|
||||
|
||||
// Determine how many occurrences there are of each no-JS placeholder.
|
||||
$placeholder_occurrences = array_count_values(array_intersect($fragments, array_keys($no_js_placeholders)));
|
||||
|
||||
// Set up a variable to store the content of placeholders that have multiple
|
||||
// occurrences.
|
||||
$multi_occurrence_placeholders_content = [];
|
||||
|
||||
foreach ($fragments as $fragment) {
|
||||
// If the fragment isn't one of the no-JS placeholders, it is the HTML in
|
||||
// between placeholders and it must be printed & flushed immediately. The
|
||||
|
@ -236,6 +243,15 @@ class BigPipe implements BigPipeInterface {
|
|||
continue;
|
||||
}
|
||||
|
||||
// If there are multiple occurrences of this particular placeholder, and
|
||||
// this is the second occurrence, we can skip all calculations and just
|
||||
// send the same content.
|
||||
if ($placeholder_occurrences[$fragment] > 1 && isset($multi_occurrence_placeholders_content[$fragment])) {
|
||||
print $multi_occurrence_placeholders_content[$fragment];
|
||||
flush();
|
||||
continue;
|
||||
}
|
||||
|
||||
$placeholder = $fragment;
|
||||
assert('isset($no_js_placeholders[$placeholder])');
|
||||
$token = Crypt::randomBytesBase64(55);
|
||||
|
@ -310,6 +326,13 @@ class BigPipe implements BigPipeInterface {
|
|||
// they can be sent in ::sendPreBody().
|
||||
$cumulative_assets->setAlreadyLoadedLibraries(array_merge($cumulative_assets->getAlreadyLoadedLibraries(), $html_response->getAttachments()['library']));
|
||||
$cumulative_assets->setSettings($html_response->getAttachments()['drupalSettings']);
|
||||
|
||||
// If there are multiple occurrences of this particular placeholder, track
|
||||
// the content that was sent, so we can skip all calculations for the next
|
||||
// occurrence.
|
||||
if ($placeholder_occurrences[$fragment] > 1) {
|
||||
$multi_occurrence_placeholders_content[$fragment] = $html_response->getContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -508,7 +531,9 @@ EOF;
|
|||
*
|
||||
* @return array
|
||||
* Indexed array; the order in which the BigPipe placeholders must be sent.
|
||||
* Values are the BigPipe placeholder IDs.
|
||||
* Values are the BigPipe placeholder IDs. Note that only unique
|
||||
* placeholders are kept: if the same placeholder occurs multiple times, we
|
||||
* only keep the first occurrence.
|
||||
*/
|
||||
protected function getPlaceholderOrder($html) {
|
||||
$fragments = explode('<div data-big-pipe-placeholder-id="', $html);
|
||||
|
@ -521,7 +546,7 @@ EOF;
|
|||
$order[] = $placeholder;
|
||||
}
|
||||
|
||||
return $order;
|
||||
return array_unique($order);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -269,6 +269,42 @@ class BigPipeTest extends WebTestBase {
|
|||
unlink(\Drupal::root() . '/' . $this->siteDirectory . '/error.log');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests BigPipe with a multi-occurrence placeholder.
|
||||
*/
|
||||
public function testBigPipeMultiOccurrencePlaceholders() {
|
||||
$this->drupalLogin($this->rootUser);
|
||||
$this->assertSessionCookieExists(TRUE);
|
||||
$this->assertBigPipeNoJsCookieExists(FALSE);
|
||||
|
||||
// By not calling performMetaRefresh() here, we simulate JavaScript being
|
||||
// enabled, because as far as the BigPipe module is concerned, JavaScript is
|
||||
// enabled in the browser as long as the BigPipe no-JS cookie is *not* set.
|
||||
// @see setUp()
|
||||
// @see performMetaRefresh()
|
||||
|
||||
$this->drupalGet(Url::fromRoute('big_pipe_test_multi_occurrence'));
|
||||
$big_pipe_placeholder_id = 'callback=Drupal%5CCore%5CRender%5CElement%5CStatusMessages%3A%3ArenderMessages&args[0]&token=a8c34b5e';
|
||||
$expected_placeholder_replacement = '<script type="application/vnd.drupal-ajax" data-big-pipe-replacement-for-placeholder-with-id="' . $big_pipe_placeholder_id . '">';
|
||||
$this->assertRaw('The count is 1.');
|
||||
$this->assertNoRaw('The count is 2.');
|
||||
$this->assertNoRaw('The count is 3.');
|
||||
$raw_content = $this->getRawContent();
|
||||
$this->assertTrue(substr_count($raw_content, $expected_placeholder_replacement) == 1, 'Only one placeholder replacement was found for the duplicate #lazy_builder arrays.');
|
||||
|
||||
// By calling performMetaRefresh() here, we simulate JavaScript being
|
||||
// disabled, because as far as the BigPipe module is concerned, it is
|
||||
// enabled in the browser when the BigPipe no-JS cookie is set.
|
||||
// @see setUp()
|
||||
// @see performMetaRefresh()
|
||||
$this->performMetaRefresh();
|
||||
$this->assertBigPipeNoJsCookieExists(TRUE);
|
||||
$this->drupalGet(Url::fromRoute('big_pipe_test_multi_occurrence'));
|
||||
$this->assertRaw('The count is 1.');
|
||||
$this->assertNoRaw('The count is 2.');
|
||||
$this->assertNoRaw('The count is 3.');
|
||||
}
|
||||
|
||||
protected function assertBigPipeResponseHeadersPresent() {
|
||||
$this->pass('Verifying BigPipe response headers…', 'Debug');
|
||||
$this->assertTrue(FALSE !== strpos($this->drupalGetHeader('Cache-Control'), 'private'), 'Cache-Control header set to "private".');
|
||||
|
|
Reference in a new issue