configFactory = $config_factory; $this->adminContext = $admin_context; } /** * {@inheritdoc} */ public function convert($value, $definition, $name, array $defaults) { $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); // If the entity type is dynamic, confirm it to be a config entity. Static // entity types will have performed this check in self::applies(). if (strpos($definition['type'], 'entity:{') === 0) { $entity_type = $this->entityManager->getDefinition($entity_type_id); if (!$entity_type->entityClassImplements(ConfigEntityInterface::class)) { return parent::convert($value, $definition, $name, $defaults); } } if ($storage = $this->entityManager->getStorage($entity_type_id)) { // Make sure no overrides are loaded. return $storage->loadOverrideFree($value); } } /** * {@inheritdoc} */ public function applies($definition, $name, Route $route) { if (isset($definition['with_config_overrides']) && $definition['with_config_overrides']) { return FALSE; } if (parent::applies($definition, $name, $route)) { $entity_type_id = substr($definition['type'], strlen('entity:')); // If the entity type is dynamic, defer checking to self::convert(). if (strpos($entity_type_id, '{') === 0) { return TRUE; } // As we only want to override EntityConverter for ConfigEntities, find // out whether the current entity is a ConfigEntity. $entity_type = $this->entityManager->getDefinition($entity_type_id); if ($entity_type->entityClassImplements(ConfigEntityInterface::class)) { return $this->adminContext->isAdminRoute($route); } } return FALSE; } }