You are here

public function EntityController::addBundleTitle in Drupal 10

Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Entity/Controller/EntityController.php \Drupal\Core\Entity\Controller\EntityController::addBundleTitle()
  2. 9 core/lib/Drupal/Core/Entity/Controller/EntityController.php \Drupal\Core\Entity\Controller\EntityController::addBundleTitle()

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 221

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'],
    ]);
  }
  else {
    return $this
      ->addTitle($entity_type_id);
  }
}