interface MediaSourceFieldConstraintsInterface implements MediaSourceInterface (View source)

Defines an interface for a media source with source field constraints.

This allows a media source to optionally add source field validation constraints for media items. To add constraints at the entity level, a media source can also implement MediaSourceEntityConstraintsInterface.

Methods

string
getPluginId()

Gets the plugin_id of the plugin instance.

array
getPluginDefinition()

Gets the definition of the plugin implementation.

array
getConfiguration()

Gets this plugin's configuration.

setConfiguration(array $configuration)

Sets the configuration for this plugin instance.

array
defaultConfiguration()

Gets default configuration for this plugin.

array
calculateDependencies()

Calculates dependencies for the configured plugin.

array
buildConfigurationForm(array $form, FormStateInterface $form_state)

Form constructor.

validateConfigurationForm(array $form, FormStateInterface $form_state)

Form validation handler.

submitConfigurationForm(array $form, FormStateInterface $form_state)

Form submission handler.

array
getMetadataAttributes()

Gets a list of metadata attributes provided by this plugin.

mixed|null
getMetadata(MediaInterface $media, string $attribute_name)

Gets the value for a metadata attribute for a given media item.

getSourceFieldDefinition(MediaTypeInterface $type)

Get the source field definition for a media type.

createSourceField(MediaTypeInterface $type)

Creates the source field definition for a type.

prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayInterface $display)

Prepares the media type fields for this source in the view display.

prepareFormDisplay(MediaTypeInterface $type, EntityFormDisplayInterface $display)

Prepares the media type fields for this source in the form display.

mixed
getSourceFieldValue(MediaInterface $media)

Get the primary value stored in the source field.

Constraint[]
getSourceFieldConstraints()

Gets media source-specific validation constraints for a source field.

Details

string getPluginId()

Gets the plugin_id of the plugin instance.

Return Value

string

The plugin_id of the plugin instance.

array getPluginDefinition()

Gets the definition of the plugin implementation.

Return Value

array

The plugin definition, as returned by the discovery object used by the plugin manager.

array getConfiguration()

Gets this plugin's configuration.

Return Value

array

An array of this plugin's configuration.

setConfiguration(array $configuration)

Sets the configuration for this plugin instance.

Parameters

array $configuration

An associative array containing the plugin's configuration.

array defaultConfiguration()

Gets default configuration for this plugin.

Return Value

array

An associative array with the default configuration.

array calculateDependencies()

Calculates dependencies for the configured plugin.

Dependencies are saved in the plugin's configuration entity and are used to determine configuration synchronization order. For example, if the plugin integrates with specific user roles, this method should return an array of dependencies listing the specified roles.

Return Value

array

An array of dependencies grouped by type (config, content, module, theme). For example: @code array( 'config' => array('user.role.anonymous', 'user.role.authenticated'), 'content' => array('node:article:f0a189e6-55fb-47fb-8005-5bef81c44d6d'), 'module' => array('node', 'user'), 'theme' => array('seven'), ); @endcode

See also

ConfigDependencyManager
EntityInterface::getConfigDependencyName

array buildConfigurationForm(array $form, FormStateInterface $form_state)

Form constructor.

Plugin forms are embedded in other forms. In order to know where the plugin form is located in the parent form, #parents and #array_parents must be known, but these are not available during the initial build phase. In order to have these properties available when building the plugin form's elements, let this method return a form element that has a #process callback and build the rest of the form in the callback. By the time the callback is executed, the element's #parents and #array_parents properties will have been set by the form API. For more documentation on #parents and

array_parents, see \Drupal\Core\Render\Element\FormElement.

Parameters

array $form

An associative array containing the initial structure of the plugin form.

FormStateInterface $form_state

The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

Return Value

array

The form structure.

validateConfigurationForm(array $form, FormStateInterface $form_state)

Form validation handler.

Parameters

array $form

An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

FormStateInterface $form_state

The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

submitConfigurationForm(array $form, FormStateInterface $form_state)

Form submission handler.

Parameters

array $form

An associative array containing the structure of the plugin form as built by static::buildConfigurationForm().

FormStateInterface $form_state

The current state of the form. Calling code should pass on a subform state created through \Drupal\Core\Form\SubformState::createForSubform().

array getMetadataAttributes()

Gets a list of metadata attributes provided by this plugin.

Most media sources have associated metadata, describing attributes such as:

  • dimensions
  • duration
  • encoding
  • date
  • location
  • permalink
  • licensing information
  • ...

This method should list all metadata attributes that a media source MAY offer. In other words: it is possible that a particular media item does not contain a certain attribute. For example: an oEmbed media source can contain both video and images. Images don't have a duration, but videos do.

(The term 'attributes' was chosen because it cannot be confused with 'fields' and 'properties', both of which are concepts in Drupal's Entity Field API.)

Return Value

array

Associative array with:

  • keys: metadata attribute names
  • values: human-readable labels for those attribute names

mixed|null getMetadata(MediaInterface $media, string $attribute_name)

Gets the value for a metadata attribute for a given media item.

Parameters

MediaInterface $media

A media item.

string $attribute_name

Name of the attribute to fetch.

Return Value

mixed|null

Metadata attribute value or NULL if unavailable.

FieldDefinitionInterface|null getSourceFieldDefinition(MediaTypeInterface $type)

Get the source field definition for a media type.

Parameters

MediaTypeInterface $type

A media type.

Return Value

FieldDefinitionInterface|null

The source field definition, or NULL if it doesn't exist or has not been configured yet.

FieldConfigInterface createSourceField(MediaTypeInterface $type)

Creates the source field definition for a type.

Parameters

MediaTypeInterface $type

The media type.

Return Value

FieldConfigInterface

The unsaved field definition. The field storage definition, if new, should also be unsaved.

prepareViewDisplay(MediaTypeInterface $type, EntityViewDisplayInterface $display)

Prepares the media type fields for this source in the view display.

This method should normally call \Drupal\Core\Entity\Display\EntityDisplayInterface::setComponent() or \Drupal\Core\Entity\Display\EntityDisplayInterface::removeComponent() to configure the media type fields in the view display.

Parameters

MediaTypeInterface $type

The media type which is using this source.

EntityViewDisplayInterface $display

The display which should be prepared.

See also

EntityDisplayInterface::setComponent
EntityDisplayInterface::removeComponent

prepareFormDisplay(MediaTypeInterface $type, EntityFormDisplayInterface $display)

Prepares the media type fields for this source in the form display.

This method should normally call \Drupal\Core\Entity\Display\EntityDisplayInterface::setComponent() or \Drupal\Core\Entity\Display\EntityDisplayInterface::removeComponent() to configure the media type fields in the form display.

Parameters

MediaTypeInterface $type

The media type which is using this source.

EntityFormDisplayInterface $display

The display which should be prepared.

See also

EntityDisplayInterface::setComponent
EntityDisplayInterface::removeComponent

mixed getSourceFieldValue(MediaInterface $media)

Get the primary value stored in the source field.

Parameters

MediaInterface $media

A media item.

Return Value

mixed

The source value, or NULL if the media item's source field is empty.

Exceptions

RuntimeException

Constraint[] getSourceFieldConstraints()

Gets media source-specific validation constraints for a source field.

Return Value

Constraint[]

An array of validation constraint definitions, keyed by constraint name. Each constraint definition can be used for instantiating \Symfony\Component\Validator\Constraint objects.