On this page
public function EntityController::addBundleTitle
public EntityController::addBundleTitle(RouteMatchInterface $route_match, $entity_type_id, $bundle_parameter)
Provides a generic add title callback for entities with bundles.
Parameters
\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match.
string $entity_type_id: The entity type ID.
string $bundle_parameter: The name of the route parameter that holds the bundle.
Return value
string The title for the entity add page, if the bundle was found.
File
- core/lib/Drupal/Core/Entity/Controller/EntityController.php, line 199
Class
- EntityController
- Provides the add-page and title callbacks for entities.
Namespace
Drupal\Core\Entity\ControllerCode
public function addBundleTitle(RouteMatchInterface $route_match, $entity_type_id, $bundle_parameter) {
$bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id);
// If the entity has bundle entities, the parameter might have been upcasted
// so fetch the raw parameter.
$bundle = $route_match->getRawParameter($bundle_parameter);
if ((count($bundles) > 1) && isset($bundles[$bundle])) {
return $this->t('Add @bundle', ['@bundle' => $bundles[$bundle]['label']]);
}
// If the entity supports bundles generally, but only has a single bundle,
// the bundle is probably something like 'Default' so that it preferable to
// use the entity type label.
else {
return $this->addTitle($entity_type_id);
}
}
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Controller!EntityController.php/function/EntityController::addBundleTitle/8.1.x