media_entity_file_redirect-8.x-1.0-beta1/src/Plugin/Linkit/Substitution/MediaFileRedirect.php

src/Plugin/Linkit/Substitution/MediaFileRedirect.php
<?php

namespace Drupal\media_entity_file_redirect\Plugin\Linkit\Substitution;

use Drupal\Component\Plugin\PluginBase;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Url;
use Drupal\linkit\SubstitutionInterface;

/**
 * A substitution plugin for the URL to a file associated with a media entity.
 *
 * @Substitution(
 *   id = "media_file_redirect",
 *   label = @Translation("URL that redirects to direct file path"),
 * )
 */
class MediaFileRedirect extends PluginBase implements SubstitutionInterface {

  /**
   * {@inheritdoc}
   */
  public function getUrl(EntityInterface $entity): Url {
    return Url::fromRoute('media_entity_file_redirect.file_redirect', ['media' => $entity->id()]);
  }

  /**
   * {@inheritdoc}
   */
  public static function isApplicable(EntityTypeInterface $entity_type) {
    return $entity_type->entityClassImplements('Drupal\media\MediaInterface');
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc