function EntityTypeInfo::entityTypeAlter
Same name in other branches
- 8.x-1.x src/EntityTypeInfo.php \Drupal\devel\EntityTypeInfo::entityTypeAlter()
- 4.x src/EntityTypeInfo.php \Drupal\devel\EntityTypeInfo::entityTypeAlter()
Adds devel links to appropriate entity types.
This is an alter hook bridge.
Parameters
\Drupal\Core\Entity\EntityTypeInterface[] $entity_types: The master entity type list to alter.
See also
File
-
src/
EntityTypeInfo.php, line 48
Class
- EntityTypeInfo
- Manipulates entity type information.
Namespace
Drupal\develCode
public function entityTypeAlter(array &$entity_types) : void {
foreach ($entity_types as $entity_type_id => $entity_type) {
// Make devel-load and devel-load-with-references subtasks. The edit-form
// template is used to extract and set additional parameters dynamically.
// If there is no 'edit-form' template then still create the link using
// 'entity_type_id/{entity_type_id}' as the link. This allows devel info
// to be viewed for any entity, even if the url has to be typed manually.
// @see https://gitlab.com/drupalspoons/devel/-/issues/377
$entity_link = $entity_type->getLinkTemplate('edit-form') ?: $entity_type_id . sprintf('/{%s}', $entity_type_id);
$this->setEntityTypeLinkTemplate($entity_type, $entity_link, 'devel-load', '/devel/' . $entity_type_id);
$this->setEntityTypeLinkTemplate($entity_type, $entity_link, 'devel-load-with-references', '/devel/load-with-references/' . $entity_type_id);
$this->setEntityTypeLinkTemplate($entity_type, $entity_link, 'devel-path-alias', '/devel/path-alias/' . $entity_type_id);
// Create the devel-render subtask.
if ($entity_type->hasViewBuilderClass() && $entity_type->hasLinkTemplate('canonical')) {
// We use canonical template to extract and set additional parameters
// dynamically.
$entity_link = $entity_type->getLinkTemplate('canonical');
$this->setEntityTypeLinkTemplate($entity_type, $entity_link, 'devel-render', '/devel/render/' . $entity_type_id);
}
// Create the devel-definition subtask.
if ($entity_type->hasLinkTemplate('devel-render') || $entity_type->hasLinkTemplate('devel-load')) {
// We use canonical or edit-form template to extract and set additional
// parameters dynamically.
$entity_link = $entity_type->getLinkTemplate('edit-form');
if (empty($entity_link)) {
$entity_link = $entity_type->getLinkTemplate('canonical');
}
$this->setEntityTypeLinkTemplate($entity_type, $entity_link, 'devel-definition', '/devel/definition/' . $entity_type_id);
}
}
}