EntityUrl.php in GraphQL 8.4
File
src/Plugin/GraphQL/DataProducer/Entity/EntityUrl.phpView source
<?php
namespace Drupal\graphql\Plugin\GraphQL\DataProducer\Entity;
use Drupal\Core\Entity\EntityInterface;
use Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase;
/**
* Returns the URL of an entity.
*
* @DataProducer(
* id = "entity_url",
* name = @Translation("Entity url"),
* description = @Translation("Returns the entity's url."),
* produces = @ContextDefinition("any",
* label = @Translation("Url")
* ),
* consumes = {
* "entity" = @ContextDefinition("entity",
* label = @Translation("Entity")
* )
* }
* )
*/
class EntityUrl extends DataProducerPluginBase {
/**
* Resolver.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
*
* @return \Drupal\Core\Url
*
* @throws \Drupal\Core\Entity\EntityMalformedException
*/
public function resolve(EntityInterface $entity) {
return $entity
->toUrl();
}
}