/** * {@inheritdoc} */ public function convert($value, $definition, $name, array $defaults, Request $request) { if (!($entity = parent::convert($value, $definition, $name, $defaults, $request))) { return; } return $entity; }
/** * {@inheritdoc} */ public function convert($value, $definition, $name, array $defaults) { // Standard upcasting: check if the config entity exists at all in the // storage. if (!($entity = parent::convert($value, $definition, $name, $defaults))) { return; } // Now check if there is also a version being edited and return that. $store = $this->tempStoreFactory->get($entity->getEntityTypeId()); $edited_entity = $store->get($value); if ($edited_entity) { return $edited_entity; } return $entity; }
/** * {@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->isSubclassOf('\\Drupal\\Core\\Config\\Entity\\ConfigEntityInterface')) { 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 convert($value, $definition, $name, array $defaults) { /** @var \Drupal\search_api\IndexInterface $entity */ if (!($entity = parent::convert($value, $definition, $name, $defaults))) { return NULL; } // Get the temp store for this variable if it needs one. Attempt to load the // index from the temp store, update the currently logged-in user's ID and // store the lock metadata. $store = $this->tempStoreFactory->get('search_api_index'); $current_user_id = $this->currentUser->id() ?: session_id(); /** @var \Drupal\search_api\IndexInterface|\Drupal\search_api\UnsavedConfigurationInterface $index */ if ($index = $store->get($value)) { $index->setCurrentUserId($current_user_id); $index->setLockInformation($store->getMetadata($value)); } else { $index = new UnsavedIndexConfiguration($entity, $store, $current_user_id); } return $index; }
/** * {@inheritdoc} */ public function convert($value, $definition, $name, array $defaults) { if (!($entity = parent::convert($value, $definition, $name, $defaults))) { return; } // Get the temp store for this variable if it needs one. Attempt to load the // view from the temp store, synchronize its status with the existing view, // and store the lock metadata. $store = $this->tempStoreFactory->get('views'); if ($view = $store->get($value)) { if ($entity->status()) { $view->enable(); } else { $view->disable(); } $view->lock = $store->getMetadata($value); } else { $view = new ViewUI($entity); } return $view; }
/** * Tests the convert() method with an invalid dynamic entity type. * * @expectedException \Drupal\Core\ParamConverter\ParamNotConvertedException * @expectedExceptionMessage The "foo" parameter was not converted because the "invalid_id" parameter is missing */ public function testConvertWithInvalidDynamicEntityType() { $this->entityConverter->convert('id', ['type' => 'entity:{invalid_id}'], 'foo', ['foo' => 'id']); }
/** * {@inheritdoc} */ public function convert($value, $definition, $name, array $defaults) { $entity = parent::convert($value, $definition, $name, $defaults); if ($entity && $this->moderationInformation->isModeratedEntity($entity) && !$this->moderationInformation->isLatestRevision($entity)) { $entity_type_id = $this->getEntityTypeFromDefaults($definition, $name, $defaults); $latest_revision = $this->moderationInformation->getLatestRevision($entity_type_id, $value); // If the entity type is translatable, ensure we return the proper // translation object for the current context. if ($latest_revision instanceof EntityInterface && $entity instanceof TranslatableInterface) { $latest_revision = $this->entityManager->getTranslationFromContext($latest_revision, NULL, array('operation' => 'entity_upcast')); } if ($latest_revision->isRevisionTranslationAffected()) { $entity = $latest_revision; } } return $entity; }