Issue #2645036 by chx: Performance: system_path_* doesn't pass the source
parent
2ecea88243
commit
6badeae83c
|
@ -1404,22 +1404,24 @@ function system_block_view_system_main_block_alter(array &$build, BlockPluginInt
|
|||
/**
|
||||
* Implements hook_path_update().
|
||||
*/
|
||||
function system_path_update() {
|
||||
\Drupal::service('path.alias_manager')->cacheClear();
|
||||
function system_path_update($path) {
|
||||
$alias_manager = \Drupal::service('path.alias_manager');
|
||||
$alias_manager->cacheClear($path['source']);
|
||||
$alias_manager->cacheClear($path['original']['source']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_path_insert().
|
||||
*/
|
||||
function system_path_insert() {
|
||||
\Drupal::service('path.alias_manager')->cacheClear();
|
||||
function system_path_insert($path) {
|
||||
\Drupal::service('path.alias_manager')->cacheClear($path['source']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_path_delete().
|
||||
*/
|
||||
function system_path_delete($path) {
|
||||
\Drupal::service('path.alias_manager')->cacheClear();
|
||||
\Drupal::service('path.alias_manager')->cacheClear($path['source']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\system\Kernel\PathHooksTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\system\Kernel;
|
||||
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Path\AliasManagerInterface;
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @group Drupal
|
||||
*/
|
||||
class PathHooksTest extends KernelTestBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static public $modules = ['system'];
|
||||
|
||||
/**
|
||||
* Test system_path_*() correctly clears caches.
|
||||
*/
|
||||
public function testPathHooks() {
|
||||
$this->installSchema('system', ['url_alias']);
|
||||
|
||||
$source = '/' . $this->randomMachineName();
|
||||
$alias = '/' . $this->randomMachineName();
|
||||
|
||||
// Check system_path_insert();
|
||||
$alias_manager = $this->prophesize(AliasManagerInterface::class);
|
||||
$alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(1);
|
||||
$alias_manager->cacheClear($source)->shouldBeCalledTimes(1);
|
||||
\Drupal::getContainer()->set('path.alias_manager', $alias_manager->reveal());
|
||||
$alias_storage = \Drupal::service('path.alias_storage');
|
||||
$alias_storage->save($source, $alias);
|
||||
|
||||
$new_source = '/' . $this->randomMachineName();
|
||||
$path = $alias_storage->load(['source' => $source]);
|
||||
|
||||
// Check system_path_update();
|
||||
$alias_manager = $this->prophesize(AliasManagerInterface::class);
|
||||
$alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(2);
|
||||
$alias_manager->cacheClear($source)->shouldBeCalledTimes(1);
|
||||
$alias_manager->cacheClear($new_source)->shouldBeCalledTimes(1);
|
||||
\Drupal::getContainer()->set('path.alias_manager', $alias_manager->reveal());
|
||||
$alias_storage->save($new_source, $alias, LanguageInterface::LANGCODE_NOT_SPECIFIED, $path['pid']);
|
||||
|
||||
// Check system_path_delete();
|
||||
$alias_manager = $this->prophesize(AliasManagerInterface::class);
|
||||
$alias_manager->cacheClear(Argument::any())->shouldBeCalledTimes(1);
|
||||
$alias_manager->cacheClear($new_source)->shouldBeCalledTimes(1);
|
||||
\Drupal::getContainer()->set('path.alias_manager', $alias_manager->reveal());
|
||||
$alias_storage->delete(['pid' => $path['pid']]);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue