isRegistered example

/** * Tests correct Link Relations are returned from the Link Relation Type Manager. */
  public function testAvailableLinkRelationships() {
    /** @var \Drupal\Core\Http\LinkRelationTypeManager $link_relation_type_manager */
    $link_relation_type_manager = $this->container->get('plugin.manager.link_relation_type');

    // A link relation type of the "registered" kind.     /** @var \Drupal\Core\Http\LinkRelationTypeInterface $canonical */
    $canonical = $link_relation_type_manager->createInstance('canonical');
    $this->assertInstanceOf(LinkRelationType::class$canonical);
    $this->assertTrue($canonical->isRegistered());
    $this->assertFalse($canonical->isExtension());
    $this->assertSame('canonical', $canonical->getRegisteredName());
    $this->assertNull($canonical->getExtensionUri());
    $this->assertEquals('[RFC6596]', $canonical->getReference());
    $this->assertEquals('Designates the preferred version of a resource (the IRI and its contents).', $canonical->getDescription());
    $this->assertEquals('', $canonical->getNotes());

    // A link relation type of the "extension" kind.     /** @var \Drupal\Core\Http\LinkRelationTypeInterface $canonical */
    $add_form = $link_relation_type_manager->createInstance('add-form');
    $this->assertInstanceOf(LinkRelationType::class$add_form);
    
/** * {@inheritdoc} */
  public function isExtension() {
    return isset($this->pluginDefinition['uri']);
  }

  /** * {@inheritdoc} */
  public function getRegisteredName() {
    return $this->isRegistered() ? $this->getPluginId() : NULL;
  }

  /** * {@inheritdoc} */
  public function getExtensionUri() {
    return $this->isExtension() ? $this->pluginDefinition['uri'] : NULL;
  }

  /** * {@inheritdoc} */
/** @var \Drupal\Core\Http\LinkRelationTypeInterface $link_relation_type */
        $link_relation_type = $this->linkRelationTypeManager->createInstance($relation_name);

        $generator_url = $entity->toUrl($relation_name)
          ->setAbsolute(TRUE)
          ->toString(TRUE);
        if ($response instanceof CacheableResponseInterface) {
          $response->addCacheableDependency($generator_url);
        }
        $uri = $generator_url->getGeneratedUrl();

        $relationship = $link_relation_type->isRegistered()
          ? $link_relation_type->getRegisteredName()
          : $link_relation_type->getExtensionUri();

        $link_header = '<' . $uri . '>; rel="' . $relationship . '"';
        $response->headers->set('Link', $link_header, FALSE);
      }
    }
  }

}
    if (static::$format !== 'xml') {
      $unserialized = $this->serializer->deserialize((string) $response->getBody()get_class($this->entity)static::$format);
      $this->assertSame($unserialized->uuid()$this->entity->uuid());

    }
    // Finally, assert that the expected 'Link' headers are present.     if ($this->entity->getEntityType()->getLinkTemplates()) {
      $this->assertArrayHasKey('Link', $response->getHeaders());
      $link_relation_type_manager = $this->container->get('plugin.manager.link_relation_type');
      $expected_link_relation_headers = array_map(function D$relation_name) use ($link_relation_type_manager) {
        $link_relation_type = $link_relation_type_manager->createInstance($relation_name);
        return $link_relation_type->isRegistered()
          ? $link_relation_type->getRegisteredName()
          : $link_relation_type->getExtensionUri();
      }array_keys($this->entity->getEntityType()->getLinkTemplates()));
      $parse_rel_from_link_header = function D$value) {
        $matches = [];
        if (preg_match('/rel="([^"]+)"/', $value$matches) === 1) {
          return $matches[1];
        }
        return FALSE;
      };
      $this->assertSame($expected_link_relation_headersarray_map($parse_rel_from_link_header$response->getHeader('Link')));
    }
Home | Imprint | This part of the site doesn't use cookies.