Problem/Motivation

When using the Purge UI block, it purges the URL or path of the current page as expected. However, if the page has redirections, it does not automatically purge the corresponding content redirections. After saving a node title, this can result in a situation where it appears that the purge invalidation request to the CDN did not occur, whereas in reality, only the new URL was invalidated—not the original one.

Proposed resolution

We could add an option to the Purge UI block, or we could simply introduce a hook to allow additional expressions to be included in the invalidation request.

For example:

  protected function gatherInvalidationsData() {
    $request = $this->getRequest();
    $expressions = [];
    [...]

    \Drupal::moduleHandler()->alter('purge_ui_block_expressions', $expressions);
    return array_unique($expressions);
  }

And an example implementation:

/**
 * Implements hook_purge_ui_block_expressions_alter().
 */
function my_module_purge_ui_block_expressions_alter(array &$expressions) {
  if (\Drupal::routeMatch()->getRouteName() == 'entity.node.canonical'
    && $node = \Drupal::routeMatch()->getParameter('node')) {
    $nid = $node->id();

    $redirects = \Drupal::service('redirect.repository')
      ->findByDestinationUri(["internal:/node/$nid", "entity:node/$nid"]);
    foreach ($redirects as $redirect) {
      $expressions[] = \Drupal::request()
        ->getUriForPath($redirect->getSourceUrl());
    }
  }
}

A corresponding merge request will follow.

Remaining tasks

Provide feedback and review the merge request.

Issue fork purge-3523147

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

guillaumeg created an issue.