Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Link.php

function Link::__construct

Same name in this branch
  1. 11.1.x vendor/open-telemetry/sdk/Trace/Link.php \OpenTelemetry\SDK\Trace\Link::__construct()
  2. 11.1.x vendor/open-telemetry/gen-otlp-protobuf/Opentelemetry/Proto/Trace/V1/Span/Link.php \Opentelemetry\Proto\Trace\V1\Span\Link::__construct()
  3. 11.1.x vendor/composer/composer/src/Composer/Package/Link.php \Composer\Package\Link::__construct()
  4. 11.1.x vendor/phpdocumentor/reflection-docblock/src/DocBlock/Tags/Link.php \phpDocumentor\Reflection\DocBlock\Tags\Link::__construct()
  5. 11.1.x core/lib/Drupal/Core/Link.php \Drupal\Core\Link::__construct()

JSON:API Link constructor.

Parameters

\Drupal\Core\Cache\CacheableMetadata $cacheability: Any cacheability metadata associated with the link. For example, a 'call-to-action' link might reference a registration resource if an event has vacancies or a wait-list resource otherwise. Therefore, the link's cacheability might be depend on a certain entity's values other than the entity on which the link will appear.

\Drupal\Core\Url $url: The Url object for the link.

string $link_relation_type: An array of registered or extension RFC8288 link relation types.

array $target_attributes: An associative array of target attributes for the link.

See also

https://tools.ietf.org/html/rfc8288#section-2.1

File

core/modules/jsonapi/src/JsonApiResource/Link.php, line 75

Class

Link
Represents an RFC8288 based link.

Namespace

Drupal\jsonapi\JsonApiResource

Code

public function __construct(CacheableMetadata $cacheability, Url $url, string $link_relation_type, array $target_attributes = []) {
    assert(Inspector::assertAllStrings(array_keys($target_attributes)));
    assert(Inspector::assertAll(function ($target_attribute_value) {
        return is_string($target_attribute_value) || is_array($target_attribute_value);
    }, array_values($target_attributes)));
    $generated_url = $url->setAbsolute()
        ->toString(TRUE);
    $this->href = $generated_url->getGeneratedUrl();
    $this->uri = $url;
    $this->rel = $link_relation_type;
    $this->attributes = $target_attributes;
    $this->setCacheability($cacheability->addCacheableDependency($generated_url));
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal