You are here

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

Expanded class hierarchy of ApigeeEdgeLoadUnchangedEntity

See also

\Drupal\Core\ParamConverter\EntityConverter

1 string reference to 'ApigeeEdgeLoadUnchangedEntity'
apigee_edge.services.yml in ./apigee_edge.services.yml
apigee_edge.services.yml
1 service uses ApigeeEdgeLoadUnchangedEntity
paramconverter.apigee_edge_load_unchanged_entity in ./apigee_edge.services.yml
Drupal\apigee_edge\ParamConverter\ApigeeEdgeLoadUnchangedEntity

File

src/ParamConverter/ApigeeEdgeLoadUnchangedEntity.php, line 39

Namespace

Drupal\apigee_edge\ParamConverter
View 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

Namesort descending Modifiers Type Description Overrides
ApigeeEdgeLoadUnchangedEntity::$entityTypeManager protected property The entity type manager.
ApigeeEdgeLoadUnchangedEntity::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
ApigeeEdgeLoadUnchangedEntity::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert
ApigeeEdgeLoadUnchangedEntity::__construct public function DeveloperAppNameParameterConverter constructor.