Drupal 8  8.0.2
EntityConverter Class Reference
Inheritance diagram for EntityConverter:

Public Member Functions

 __construct (EntityManagerInterface $entity_manager)
 
 convert ($value, $definition, $name, array $defaults)
 
 applies ($definition, $name, Route $route)
 

Protected Member Functions

 getEntityTypeFromDefaults ($definition, $name, array $defaults)
 

Protected Attributes

 $entityManager
 

Detailed Description

Parameter converter for upcasting entity IDs to full objects.

This is useful in cases where the dynamic elements of the path can't be auto-determined; for example, if your path refers to multiple of the same type of entity ("example/{node1}/foo/{node2}") or if the path can act on any entity type ("example/{entity_type}/{entity}/foo").

In order to use it you should specify some additional options in your route:

example.route:
path: foo/{example}
options:
parameters:
example:
type: entity:node

If you want to have the entity type itself dynamic in the url you can specify it like the following:

example.route:
path: foo/{entity_type}/{example}
options:
parameters:
example:
type: entity:{entity_type}

Constructor & Destructor Documentation

__construct ( EntityManagerInterface  $entity_manager)

Constructs a new EntityConverter.

Parameters
\Drupal\Core\Entity\EntityManagerInterface$entity_managerThe entity manager.

References Drupal\entityManager().

Here is the call graph for this function:

Member Function Documentation

applies (   $definition,
  $name,
Route  $route 
)

{Determines if the converter applies to a specific route and variable.

Parameters
mixed$definitionThe parameter definition provided in the route options.
string$nameThe name of the parameter.
\Symfony\Component\Routing\Route$routeThe route to consider attaching to.
Returns
bool TRUE if the converter applies to the passed route and parameter, FALSE otherwise.
}

Implements ParamConverterInterface.

References Drupal\entityManager().

Here is the call graph for this function:

convert (   $value,
  $definition,
  $name,
array  $defaults 
)

{Converts path variables to their corresponding objects.

Parameters
mixed$valueThe raw value.
mixed$definitionThe parameter definition provided in the route options.
string$nameThe name of the parameter.
array$defaultsThe route defaults array.
Returns
mixed|null The converted parameter value.
}

Implements ParamConverterInterface.

References Drupal\entityManager(), and EntityConverter\getEntityTypeFromDefaults().

Here is the call graph for this function:

getEntityTypeFromDefaults (   $definition,
  $name,
array  $defaults 
)
protected

Determines the entity type ID given a route definition and route defaults.

Parameters
mixed$definitionThe parameter definition provided in the route options.
string$nameThe name of the parameter.
array$defaultsThe route defaults array.
Returns
string The entity type ID.
Exceptions
\Drupal\Core\ParamConverter\ParamNotConvertedExceptionThrown when the dynamic entity type is not found in the route defaults.

Referenced by EntityConverter\convert(), and AdminPathConfigEntityConverter\convert().

Here is the caller graph for this function:


The documentation for this class was generated from the following file: