class MediaImage in Lightning Media 8
Same name and namespace in other branches
- 8.4 src/Plugin/entity_embed/EntityEmbedDisplay/MediaImage.php \Drupal\lightning_media\Plugin\entity_embed\EntityEmbedDisplay\MediaImage
- 8.2 src/Plugin/entity_embed/EntityEmbedDisplay/MediaImage.php \Drupal\lightning_media\Plugin\entity_embed\EntityEmbedDisplay\MediaImage
- 8.3 src/Plugin/entity_embed/EntityEmbedDisplay/MediaImage.php \Drupal\lightning_media\Plugin\entity_embed\EntityEmbedDisplay\MediaImage
Renders a media item's image via the image formatter.
If the embedded media item has an image field as its source field, that image is rendered through the image formatter. Otherwise, the media item's thumbnail is used.
Plugin annotation
@EntityEmbedDisplay(
id = "media_image",
label = @Translation("Media Image"),
entity_types = {"media"},
field_type = "image",
provider = "image"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayBase implements ContainerFactoryPluginInterface, EntityEmbedDisplayInterface
- class \Drupal\entity_embed\EntityEmbedDisplay\FieldFormatterEntityEmbedDisplayBase uses PluginDependencyTrait
- class \Drupal\entity_embed\Plugin\entity_embed\EntityEmbedDisplay\EntityReferenceFieldFormatter implements TrustedCallbackInterface
- class \Drupal\entity_embed\Plugin\entity_embed\EntityEmbedDisplay\FileFieldFormatter
- class \Drupal\entity_embed\Plugin\entity_embed\EntityEmbedDisplay\ImageFieldFormatter
- class \Drupal\lightning_media\Plugin\entity_embed\EntityEmbedDisplay\MediaImage
- class \Drupal\entity_embed\Plugin\entity_embed\EntityEmbedDisplay\ImageFieldFormatter
- class \Drupal\entity_embed\Plugin\entity_embed\EntityEmbedDisplay\FileFieldFormatter
- class \Drupal\entity_embed\Plugin\entity_embed\EntityEmbedDisplay\EntityReferenceFieldFormatter implements TrustedCallbackInterface
- class \Drupal\entity_embed\EntityEmbedDisplay\FieldFormatterEntityEmbedDisplayBase uses PluginDependencyTrait
- class \Drupal\entity_embed\EntityEmbedDisplay\EntityEmbedDisplayBase implements ContainerFactoryPluginInterface, EntityEmbedDisplayInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of MediaImage
File
- src/
Plugin/ entity_embed/ EntityEmbedDisplay/ MediaImage.php, line 26
Namespace
Drupal\lightning_media\Plugin\entity_embed\EntityEmbedDisplayView source
class MediaImage extends ImageFieldFormatter {
/**
* {@inheritdoc}
*/
public function getFieldFormatterId() {
return 'image';
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
// Don't allow linking directly to the content.
unset($form['image_link']['#options']['content']);
return $form;
}
/**
* {@inheritdoc}
*/
public function getAttributeValues() {
$field = $this
->getItem();
$label = $field
->getEntity()
->label();
// Try to default to the alt and title attributes set on the field item, but
// fall back to the entity label for both.
return parent::getAttributeValues() + [
'alt' => $field->alt ?: $label,
'title' => $field->title ?: $label,
];
}
/**
* {@inheritdoc}
*/
protected function isValidImage() {
// This display plugin works for any media entity. And media items always
// have at least a thumbnail. So, we can bypass this access gate.
return AccessResult::allowed();
}
/**
* {@inheritdoc}
*/
public function getFieldDefinition() {
// The parent method will set the target_type to the entity type being
// embedded, but we are actually rendering an image (i.e., a file entity).
return parent::getFieldDefinition()
->setSetting('target_type', 'file');
}
/**
* {@inheritdoc}
*/
public function getFieldValue() {
$value = parent::getFieldValue();
$value['target_id'] = $this
->getItem()->target_id;
return $value;
}
/**
* Returns the image field item to use for the embedded entity.
*
* @return \Drupal\image\Plugin\Field\FieldType\ImageItem
* The image field item.
*/
protected function getItem() {
/** @var \Drupal\media\MediaInterface $entity */
$entity = $this
->getEntityFromContext();
$item = MediaHelper::getSourceField($entity)
->first();
return $item instanceof ImageItem ? $item : $entity
->get('thumbnail')
->first();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
DependencyTrait:: |
protected | property | The object's dependencies. | |
DependencyTrait:: |
protected | function | Adds multiple dependencies. | |
DependencyTrait:: |
protected | function | Adds a dependency. | |
EntityEmbedDisplayBase:: |
public | property | The attributes on the embedded entity. | |
EntityEmbedDisplayBase:: |
public | property | The context for the plugin. | |
EntityEmbedDisplayBase:: |
protected | property | The entity type manager service. | |
EntityEmbedDisplayBase:: |
protected | property | The language manager. | |
EntityEmbedDisplayBase:: |
public | function | Gets the value for an attribute. | |
EntityEmbedDisplayBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurableInterface:: |
|
EntityEmbedDisplayBase:: |
public | function | Gets a configuration value. | |
EntityEmbedDisplayBase:: |
public | function | Gets the value for a defined context. | |
EntityEmbedDisplayBase:: |
public | function | Gets the values for all defined contexts. | |
EntityEmbedDisplayBase:: |
public | function | Gets the entity from the current context. | |
EntityEmbedDisplayBase:: |
public | function | Gets the entity type from the current context. | |
EntityEmbedDisplayBase:: |
public | function | Gets the current language code. | |
EntityEmbedDisplayBase:: |
public | function | Checks if an attribute is set. | |
EntityEmbedDisplayBase:: |
public | function | Returns whether or not value is set for a defined context. | |
EntityEmbedDisplayBase:: |
protected | function | Validates that this display plugin applies to the current entity type. | |
EntityEmbedDisplayBase:: |
public | function | Sets the values for all attributes. | |
EntityEmbedDisplayBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurableInterface:: |
|
EntityEmbedDisplayBase:: |
public | function | Sets the value for a defined context. | |
EntityEmbedDisplayBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
|
EntityReferenceFieldFormatter:: |
protected | property | The configuration factory. | |
EntityReferenceFieldFormatter:: |
public | function |
Builds the renderable array for this Entity Embed display plugin. Overrides FieldFormatterEntityEmbedDisplayBase:: |
|
EntityReferenceFieldFormatter:: |
public static | function | Disables Contextual Links for the embedded media by removing its property. | |
EntityReferenceFieldFormatter:: |
public static | function | Disables Quick Edit for the embedded media by removing its attributes. | |
EntityReferenceFieldFormatter:: |
protected | function |
Checks if the field formatter is applicable. Overrides FieldFormatterEntityEmbedDisplayBase:: |
|
EntityReferenceFieldFormatter:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
|
FieldFormatterEntityEmbedDisplayBase:: |
protected | property | The field definition. | |
FieldFormatterEntityEmbedDisplayBase:: |
protected | property | The field formatter. | |
FieldFormatterEntityEmbedDisplayBase:: |
protected | property | The field formatter plugin manager. | |
FieldFormatterEntityEmbedDisplayBase:: |
protected | property | The typed data manager. | |
FieldFormatterEntityEmbedDisplayBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides EntityEmbedDisplayBase:: |
1 |
FieldFormatterEntityEmbedDisplayBase:: |
protected | function | Creates a new faux-field definition. | |
FieldFormatterEntityEmbedDisplayBase:: |
public | function | Constructs a field formatter. | 1 |
FileFieldFormatter:: |
public | function |
Gets default configuration for this plugin. Overrides FieldFormatterEntityEmbedDisplayBase:: |
|
ImageFieldFormatter:: |
protected | property | The image factory. | |
ImageFieldFormatter:: |
protected | property |
The messenger. Overrides MessengerTrait:: |
|
ImageFieldFormatter:: |
public | function |
Indicates whether this Entity Embed display can be used. Overrides FieldFormatterEntityEmbedDisplayBase:: |
|
ImageFieldFormatter:: |
public static | function |
Creates an instance of the plugin. Overrides EntityReferenceFieldFormatter:: |
|
ImageFieldFormatter:: |
public | function |
Form submission handler. Overrides EntityEmbedDisplayBase:: |
|
ImageFieldFormatter:: |
public | function |
Constructs an ImageFieldFormatter object. Overrides EntityReferenceFieldFormatter:: |
|
MediaImage:: |
public | function |
Form constructor. Overrides ImageFieldFormatter:: |
|
MediaImage:: |
public | function |
Gets the values for all attributes. Overrides EntityEmbedDisplayBase:: |
|
MediaImage:: |
public | function |
Get the FieldDefinition object required to render this field's formatter. Overrides EntityReferenceFieldFormatter:: |
|
MediaImage:: |
public | function |
Returns the field formatter id. Overrides FieldFormatterEntityEmbedDisplayBase:: |
|
MediaImage:: |
public | function |
Get the field value required to pass into the field formatter. Overrides ImageFieldFormatter:: |
|
MediaImage:: |
protected | function | Returns the image field item to use for the embedded entity. | |
MediaImage:: |
protected | function |
Checks if the image is valid. Overrides ImageFieldFormatter:: |
|
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
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. | |
PluginDependencyTrait:: |
protected | function | Calculates and adds dependencies of a specific plugin instance. | 1 |
PluginDependencyTrait:: |
protected | function | Calculates and returns dependencies of a specific plugin instance. | |
PluginDependencyTrait:: |
protected | function | Wraps the module handler. | 1 |
PluginDependencyTrait:: |
protected | function | Wraps the theme handler. | 1 |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. |