public function PathautoGenerator::getPatternByEntity in Pathauto 8
Load an alias pattern entity by entity, bundle, and language.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: An entity.
Return value
\Drupal\pathauto\PathautoPatternInterface|null
Overrides PathautoGeneratorInterface::getPatternByEntity
2 calls to PathautoGenerator::getPatternByEntity()
- PathautoGenerator::createEntityAlias in src/
PathautoGenerator.php - Apply patterns to create an alias.
- PathautoGenerator::updateEntityAlias in src/
PathautoGenerator.php - Creates or updates an alias for the given entity.
File
- src/
PathautoGenerator.php, line 316
Class
- PathautoGenerator
- Provides methods for generating path aliases.
Namespace
Drupal\pathautoCode
public function getPatternByEntity(EntityInterface $entity) {
$langcode = $entity
->language()
->getId();
if (!isset($this->patterns[$entity
->getEntityTypeId()][$entity
->id()][$langcode])) {
foreach ($this
->getPatternByEntityType($entity
->getEntityTypeId()) as $pattern) {
if ($pattern
->applies($entity)) {
$this->patterns[$entity
->getEntityTypeId()][$entity
->id()][$langcode] = $pattern;
break;
}
}
// If still not set.
if (!isset($this->patterns[$entity
->getEntityTypeId()][$entity
->id()][$langcode])) {
$this->patterns[$entity
->getEntityTypeId()][$entity
->id()][$langcode] = NULL;
}
}
return $this->patterns[$entity
->getEntityTypeId()][$entity
->id()][$langcode];
}