class DAMAsset in Media: Acquia DAM 8
A substitution plugin for the URL to a file.
Custom plugin for DAM assets because the source field is the DAM ID, not the actual file reference field.
Plugin annotation
@Substitution(
id = "dam_asset",
label = @Translation("Direct URL to DAM file entity"),
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\linkit\Plugin\Linkit\Substitution\Media implements ContainerFactoryPluginInterface, SubstitutionInterface
- class \Drupal\media_acquiadam\Plugin\Linkit\Substitution\DAMAsset
- class \Drupal\linkit\Plugin\Linkit\Substitution\Media implements ContainerFactoryPluginInterface, SubstitutionInterface
Expanded class hierarchy of DAMAsset
File
- src/
Plugin/ Linkit/ Substitution/ DAMAsset.php, line 25
Namespace
Drupal\media_acquiadam\Plugin\Linkit\SubstitutionView source
class DAMAsset extends Media {
/**
* Drupal entity type management service.
*
* @var \Drupal\Core\Entity\EntityTypeManager
*/
protected $entityTypeManager;
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@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) {
// We need special handling for Acquia DAM media sources.
// LinkIt assumes that a Media source field will be a FileInterface which is
// not a valid assumption.
if ($entity instanceof MediaInterface) {
$source = $entity
->getSource();
if (!empty($source) && $source instanceof AcquiadamAsset) {
$fid = $source
->getMetadata($entity, 'file');
if (!empty($fid)) {
$file = $this->entityTypeManager
->getStorage('file')
->load($fid);
// This is the original LinkIt behavior.
if (!empty($file) && $file instanceof FileInterface) {
$url = new GeneratedUrl();
$url
->setGeneratedUrl(file_create_url($file
->getFileUri()));
$url
->addCacheableDependency($entity);
return $url;
}
}
}
}
return parent::getUrl($entity);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DAMAsset:: |
protected | property | Drupal entity type management service. | |
DAMAsset:: |
public static | function |
Creates an instance of the plugin. Overrides Media:: |
|
DAMAsset:: |
public | function |
Get the URL associated with a given entity. Overrides Media:: |
|
DAMAsset:: |
public | function |
Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase:: |
|
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. |