MenuLinkContentLinkTarget.php

Namespace

Drupal\menu_link_content\Entity

File

core/modules/menu_link_content/src/Entity/MenuLinkContentLinkTarget.php

View source
<?php

declare (strict_types=1);
namespace Drupal\menu_link_content\Entity;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityLinkTargetInterface;
use Drupal\Core\GeneratedUrl;
use Drupal\menu_link_content\MenuLinkContentInterface;

/**
 * Provides a MenuLinkContent link target handler.
 *
 * MenuLinkContent entities are atypical because they describe a link to
 * elsewhere and don't have a canonical route to view them. So when linking to
 * such an entity, the link target must be their destination.
 *
 * @see \Drupal\menu_link_content\MenuLinkContentInterface::getUrlObject()
 */
class MenuLinkContentLinkTarget implements EntityLinkTargetInterface {
  
  /**
   * {@inheritdoc}
   */
  public function getLinkTarget(EntityInterface $entity) : GeneratedUrl {
    assert($entity instanceof MenuLinkContentInterface);
    return $entity->getUrlObject()
      ->toString(TRUE);
  }

}

Classes

Title Deprecated Summary
MenuLinkContentLinkTarget Provides a MenuLinkContent link target handler.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.