class RouteEnhancer in Automatic Entity Label 8.3
Same name and namespace in other branches
- 8 src/Routing/RouteEnhancer.php \Drupal\auto_entitylabel\Routing\RouteEnhancer
- 8.2 src/Routing/RouteEnhancer.php \Drupal\auto_entitylabel\Routing\RouteEnhancer
RouteEnhancer Class.
Enhances Auto Entity Label routes by adding proper information about the bundle name.
Hierarchy
- class \Drupal\auto_entitylabel\Routing\RouteEnhancer implements EnhancerInterface
Expanded class hierarchy of RouteEnhancer
1 string reference to 'RouteEnhancer'
1 service uses RouteEnhancer
File
- src/
Routing/ RouteEnhancer.php, line 17
Namespace
Drupal\auto_entitylabel\RoutingView source
class RouteEnhancer implements EnhancerInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a RouteEnhancer object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public function enhance(array $defaults, Request $request) {
if (!$this
->applies($defaults[RouteObjectInterface::ROUTE_OBJECT])) {
return $defaults;
}
if (($bundle = $this->entityTypeManager
->getDefinition($defaults['entity_type_id'])
->getBundleEntityType()) && isset($defaults[$bundle])) {
// Auto Entity Label forms only need the actual name of the bundle they're
// dealing with, not an upcasted entity object, so provide a simple way
// for them to get it.
$defaults['bundle'] = $defaults['_raw_variables']
->get($bundle);
}
return $defaults;
}
/**
* {@inheritdoc}
*/
public function applies(Route $route) {
return $route
->hasOption('auto_label');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RouteEnhancer:: |
protected | property | The entity type manager. | |
RouteEnhancer:: |
public | function | ||
RouteEnhancer:: |
public | function | Update the defaults based on its own data and the request. | |
RouteEnhancer:: |
public | function | Constructs a RouteEnhancer object. |