You are here

class EntityUrl in Open Social 10.3.x

Returns the URL of an entity.

@DataProducer( id = "social_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") ), "options" = @ContextDefinition("any", label = @Translation("URL Options"), description = @Translation("Options to pass to the toUrl call"), required = FALSE ) } )

@internal

Hierarchy

  • class \Drupal\social_graphql\Plugin\GraphQL\DataProducer\Entity\EntityUrl extends \Drupal\graphql\Plugin\GraphQL\DataProducer\DataProducerPluginBase

Expanded class hierarchy of EntityUrl

Deprecated

remove when upgrading graphql module to a version that includes the options dataproducer setting.

See also

https://github.com/drupal-graphql/graphql/pull/1220

File

modules/custom/social_graphql/src/Plugin/GraphQL/DataProducer/Entity/EntityUrl.php, line 35

Namespace

Drupal\social_graphql\Plugin\GraphQL\DataProducer\Entity
View source
class EntityUrl extends DataProducerPluginBase {

  /**
   * Resolver.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity to create a canonical URL for.
   * @param null|array $options
   *   The options to provide to the URL generator.
   *
   * @return \Drupal\Core\Url
   *   Url object.
   *
   * @throws \Drupal\Core\Entity\EntityMalformedException
   */
  public function resolve(EntityInterface $entity, ?array $options) {
    return $entity
      ->toUrl('canonical', $options ?? []);
  }

}

Members