class Media in Linkit 8.5
A substitution plugin for the URL to a file.
Plugin annotation
@Substitution(
id = "media",
label = @Translation("Direct URL to media file entity"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\linkit\Plugin\Linkit\Substitution\Media implements ContainerFactoryPluginInterface, SubstitutionInterface
Expanded class hierarchy of Media
1 file declares its use of Media
- SubstitutionPluginTest.php in tests/
src/ Kernel/ SubstitutionPluginTest.php
2 string references to 'Media'
- editor.editor.format_1.yml in tests/
fixtures/ update/ editor.editor.format_1.yml - tests/fixtures/update/editor.editor.format_1.yml
- editor.editor.format_2.yml in tests/
fixtures/ update/ editor.editor.format_2.yml - tests/fixtures/update/editor.editor.format_2.yml
File
- src/
Plugin/ Linkit/ Substitution/ Media.php, line 23
Namespace
Drupal\linkit\Plugin\Linkit\SubstitutionView source
class Media extends PluginBase implements SubstitutionInterface, ContainerFactoryPluginInterface {
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function getUrl(EntityInterface $entity) {
$url = new GeneratedUrl();
if (!$entity instanceof MediaInterface) {
return $url;
}
$source_field = $entity
->getSource()
->getSourceFieldDefinition($entity
->get('bundle')->entity);
if ($source_field && $entity
->hasField($source_field
->getName()) && $entity
->get($source_field
->getName())->entity instanceof FileInterface) {
/** @var \Drupal\file\FileInterface $file */
$file = $entity
->get($source_field
->getName())->entity;
$url
->setGeneratedUrl(file_create_url($file
->getFileUri()));
$url
->addCacheableDependency($entity);
return $url;
}
// If available, fall back to the canonical URL if the bundle doesn't have
// a file source field.
if ($entity
->getEntityType()
->getLinkTemplate('canonical') != $entity
->getEntityType()
->getLinkTemplate('edit-form')) {
return $entity
->toUrl('canonical')
->toString(TRUE);
}
return $url;
}
/**
* {@inheritdoc}
*/
public static function isApplicable(EntityTypeInterface $entity_type) {
return $entity_type
->entityClassImplements('Drupal\\media\\MediaInterface');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Media:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
Media:: |
public | function |
Get the URL associated with a given entity. Overrides SubstitutionInterface:: |
|
Media:: |
public static | function |
Checks if this substitution plugin is applicable for the given entity type. Overrides SubstitutionInterface:: |
|
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginBase:: |
public | function | Constructs a \Drupal\Component\Plugin\PluginBase object. | 92 |