isExtension example


  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);
    $this->assertFalse($add_form->isRegistered());
    
use Drupal\Core\Plugin\PluginBase;

/** * Defines a single link relationship type. */
class LinkRelationType extends PluginBase implements LinkRelationTypeInterface {

  /** * {@inheritdoc} */
  public function isRegistered() {
    return !$this->isExtension();
  }

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

  /** * {@inheritdoc} */
Home | Imprint | This part of the site doesn't use cookies.