-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added token support in Next Entity Type additional urls
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
modules/stanford_decoupled/src/Plugin/Next/Revalidator/Path.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Drupal\stanford_decoupled\Plugin\Next\Revalidator; | ||
|
||
use Drupal\Core\Entity\ContentEntityInterface; | ||
use Drupal\next\Event\EntityActionEvent; | ||
use Drupal\next\Plugin\Next\Revalidator\Path as NextPath; | ||
|
||
/** | ||
* Overridden next module path plugin to support tokens in the additional paths. | ||
* | ||
* @codeCoverageIgnore | ||
*/ | ||
class Path extends NextPath { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function revalidate(EntityActionEvent $event): bool { | ||
$this->configuration['additional_paths'] = self::adjustAdditionalPaths($this->configuration['additional_paths'], $event->getEntity()); | ||
return parent::revalidate($event); | ||
} | ||
|
||
/** | ||
* Convert tokens in the additional paths. | ||
* | ||
* @param string $paths | ||
* Additional paths config. | ||
* @param \Drupal\Core\Entity\ContentEntityInterface $entity | ||
* Entity being revalidated. | ||
* | ||
* @return string | ||
* Adjusted paths. | ||
*/ | ||
protected static function adjustAdditionalPaths(string $paths, ContentEntityInterface $entity) { | ||
return \Drupal::token() | ||
->replace($paths, [$entity->getEntityTypeId() => $entity], ['clear' => TRUE]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters