class MediaLinkTargetStandaloneWhenAvailable

Provides a Media link target handler that prefers the standalone URL.

Hierarchy

Expanded class hierarchy of MediaLinkTargetStandaloneWhenAvailable

See also

\Drupal\media\Entity\MediaLinkTarget

File

core/modules/media/src/Entity/MediaLinkTargetStandaloneWhenAvailable.php, line 16

Namespace

Drupal\media\Entity
View source
class MediaLinkTargetStandaloneWhenAvailable extends MediaLinkTarget {
  
  /**
   * {@inheritdoc}
   */
  public function getLinkTarget(EntityInterface $entity) : GeneratedUrl {
    assert($entity instanceof MediaInterface);
    // Default to the standalone URL if it is enabled.
    // @see media_entity_type_alter()
    if (\Drupal::config('media.settings')->get('standalone_url')) {
      return $entity->toUrl('canonical')
        ->toString(TRUE);
    }
    return parent::getLinkTarget($entity);
  }

}

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