Commit 6badeae8 authored by alexpott's avatar alexpott
Browse files

Issue #2645036 by chx: Performance: system_path_* doesn't pass the source

parent 2ecea882
...@@ -1404,22 +1404,24 @@ function system_block_view_system_main_block_alter(array &$build, BlockPluginInt ...@@ -1404,22 +1404,24 @@ function system_block_view_system_main_block_alter(array &$build, BlockPluginInt
/** /**
* Implements hook_path_update(). * Implements hook_path_update().
*/ */
function system_path_update() { function system_path_update($path) {
\Drupal::service('path.alias_manager')->cacheClear(); $alias_manager = \Drupal::service('path.alias_manager');
$alias_manager->cacheClear($path['source']);
$alias_manager->cacheClear($path['original']['source']);
} }
/** /**
* Implements hook_path_insert(). * Implements hook_path_insert().
*/ */
function system_path_insert() { function system_path_insert($path) {
\Drupal::service('path.alias_manager')->cacheClear(); \Drupal::service('path.alias_manager')->cacheClear($path['source']);
} }
/** /**
* Implements hook_path_delete(). * Implements hook_path_delete().
*/ */
function system_path_delete($path) { function system_path_delete($path) {
\Drupal::service('path.alias_manager')->cacheClear(); \Drupal::service('path.alias_manager')->cacheClear($path['source']);
} }
/** /**
......
<?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']]);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment