function EntityController::addBundleTitle

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Controller/EntityController.php \Drupal\Core\Entity\Controller\EntityController::addBundleTitle()
  2. 8.9.x core/lib/Drupal/Core/Entity/Controller/EntityController.php \Drupal\Core\Entity\Controller\EntityController::addBundleTitle()
  3. 10 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 237

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);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.