class ApigeeEdgeLoadUnchangedEntity in Apigee Edge 8
Param converter that loads the unchanged (non cached) entity if needed.
EntityConverter always loads the cached version of an entity. In our case this could cause inconsistency problems, especially on the entity edit forms. For example, a developer could easily remove a previously added API product (on Apigee Edge) from their app when modifies it on the Developer Portal. This is why it is recommended to add "apigee_edge_load_unchanged_entity" option to the entity routes where non-cached data should be displayed.
Hierarchy
- class \Drupal\apigee_edge\ParamConverter\ApigeeEdgeLoadUnchangedEntity implements ParamConverterInterface
Expanded class hierarchy of ApigeeEdgeLoadUnchangedEntity
See also
\Drupal\Core\ParamConverter\EntityConverter
1 string reference to 'ApigeeEdgeLoadUnchangedEntity'
1 service uses ApigeeEdgeLoadUnchangedEntity
File
- src/
ParamConverter/ ApigeeEdgeLoadUnchangedEntity.php, line 39
Namespace
Drupal\apigee_edge\ParamConverterView source
class ApigeeEdgeLoadUnchangedEntity implements ParamConverterInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* DeveloperAppNameParameterConverter constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public function convert($value, $definition, $name, array $defaults) {
// $name is the entity type in this case.
return $this->entityTypeManager
->getStorage($name)
->loadUnchanged($value);
}
/**
* {@inheritdoc}
*/
public function applies($definition, $name, Route $route) {
if (!empty($route
->getOption('apigee_edge_load_unchanged_entity')) && !empty($definition['type']) && strpos($definition['type'], 'entity:') === 0) {
$entity_type_id = substr($definition['type'], strlen('entity:'));
if (strpos($definition['type'], '{') !== FALSE) {
$entity_type_slug = substr($entity_type_id, 1, -1);
return $name != $entity_type_slug && in_array($entity_type_slug, $route
->compile()
->getVariables(), TRUE);
}
return $this->entityTypeManager
->hasDefinition($entity_type_id);
}
return FALSE;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ApigeeEdgeLoadUnchangedEntity:: |
protected | property | The entity type manager. | |
ApigeeEdgeLoadUnchangedEntity:: |
public | function |
Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface:: |
|
ApigeeEdgeLoadUnchangedEntity:: |
public | function |
Converts path variables to their corresponding objects. Overrides ParamConverterInterface:: |
|
ApigeeEdgeLoadUnchangedEntity:: |
public | function | DeveloperAppNameParameterConverter constructor. |