You are here

private function EntityFormModeBase::getEntityBundle in Form mode manager 8

Get EntityStorage of entity.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The current route match.

Return value

\Drupal\Core\Entity\EntityStorageInterface|\Drupal\Core\Entity\EntityInterface The storage of current entity or EntityInterface.

1 call to EntityFormModeBase::getEntityBundle()
EntityFormModeBase::pageTitle in src/Controller/EntityFormModeBase.php
The _title_callback for the entity.add routes.

File

src/Controller/EntityFormModeBase.php, line 355

Class

EntityFormModeBase
Controller for entity form mode support.

Namespace

Drupal\form_mode_manager\Controller

Code

private function getEntityBundle(RouteMatchInterface $route_match) {

  /* @var \Drupal\Core\Entity\EntityInterface $entity */
  $entity = $this
    ->getEntityFromRouteMatch($route_match);
  if (empty($entity)) {
    $route_entity_type_info = $this
      ->getEntityTypeFromRouteMatch($route_match);

    /* @var \Drupal\Core\Entity\EntityTypeInterface $bundle */
    $bundle = $this->entityTypeManager
      ->getStorage($route_entity_type_info['bundle_entity_type'])
      ->load($route_entity_type_info['bundle']);
  }
  else {

    /* @var \Drupal\Core\Entity\EntityTypeInterface $bundle */
    $bundle = $this->entityTypeManager
      ->getStorage($route_match
      ->getRouteObject()
      ->getOption('_form_mode_manager_bundle_entity_type_id'))
      ->load($entity
      ->bundle());
  }
  if (empty($bundle)) {

    /* @var \Drupal\Core\Entity\EntityStorageInterface $bundle */
    $bundle = $this->entityTypeManager
      ->getStorage($route_match
      ->getRouteObject()
      ->getOption('_form_mode_manager_bundle_entity_type_id'));
  }
  return $bundle;
}