You are here

private function MappedObjectController::getEntity in Salesforce Suite 8.3

Helper function to get entity from router path.

@TODO find a more specific exception class

Parameters

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

Return value

\Drupal\Core\Entity\EntityInterface The Drupal entity mapped by the given mapped object.

Throws

\Exception If an EntityInterface is not found at the given route.

1 call to MappedObjectController::getEntity()
MappedObjectController::listing in modules/salesforce_mapping/src/Controller/MappedObjectController.php
List mapped objects for the entity along the current route.

File

modules/salesforce_mapping/src/Controller/MappedObjectController.php, line 55

Class

MappedObjectController
Returns responses for devel module routes.

Namespace

Drupal\salesforce_mapping\Controller

Code

private function getEntity(RouteMatchInterface $route_match) {
  $parameter_name = $route_match
    ->getRouteObject()
    ->getOption('_salesforce_entity_type_id');
  if (empty($parameter_name)) {
    throw new \Exception('Entity type paramater not found.');
  }
  $entity = $route_match
    ->getParameter($parameter_name);
  if (!$entity || !$entity instanceof EntityInterface) {
    throw new \Exception('Entity is not of type EntityInterface');
  }
  return $entity;
}