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\Controller

Code

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);
  }
}
doc_Drupal
2016-10-29 09:04:50
Comments
Leave a Comment

Please login to continue.