class MediaWithLinkTargetSelection
Limits selection of media entities to those that have a link target.
When standalone URLs are:
- enabled, all media entities have a link target and will be returned
- disabled, only media entities using a media source plugin whose ::getMetadata() method computes a METADATA_ATTRIBUTE_LINK_TARGET should be returned, because only they can have link targets.
Attributes
#[EntityReferenceSelection(id: "default:media_link_target", label: new TranslatableMarkup("Media with link target selection"), group: "default", weight: 0, entity_types: [
"media",
])]
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\DependencyInjection\AutowiredInstanceTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\Core\Plugin\ConfigurablePluginBase implements \Drupal\Component\Plugin\ConfigurableInterface uses \Drupal\Core\Plugin\ConfigurableTrait extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase implements \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface, \Drupal\Component\Plugin\DependentPluginInterface extends \Drupal\Core\Plugin\ConfigurablePluginBase
- class \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\Core\Entity\EntityReferenceSelection\SelectionWithAutocreateInterface extends \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase
- class \Drupal\media\Plugin\EntityReferenceSelection\MediaSelection extends \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection
- class \Drupal\media\Plugin\EntityReferenceSelection\MediaWithLinkTargetSelection extends \Drupal\media\Plugin\EntityReferenceSelection\MediaSelection
- class \Drupal\media\Plugin\EntityReferenceSelection\MediaSelection extends \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection
- class \Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection implements \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\Core\Entity\EntityReferenceSelection\SelectionWithAutocreateInterface extends \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase
- class \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginBase implements \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface, \Drupal\Component\Plugin\DependentPluginInterface extends \Drupal\Core\Plugin\ConfigurablePluginBase
- class \Drupal\Core\Plugin\ConfigurablePluginBase implements \Drupal\Component\Plugin\ConfigurableInterface uses \Drupal\Core\Plugin\ConfigurableTrait extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\DependencyInjection\AutowiredInstanceTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of MediaWithLinkTargetSelection
See also
\Drupal\media\MediaSourceInterface::METADATA_ATTRIBUTE_LINK_TARGET
\Drupal\media\Plugin\media\Source\OEmbed::getMetadata()
\Drupal\media\Entity\MediaLinkTarget
File
-
core/
modules/ media/ src/ Plugin/ EntityReferenceSelection/ MediaWithLinkTargetSelection.php, line 21
Namespace
Drupal\media\Plugin\EntityReferenceSelectionView source
class MediaWithLinkTargetSelection extends MediaSelection {
/**
* {@inheritdoc}
*/
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
// phpcs:disable
// @see \Drupal\media\MediaSourceBase::getMetadata()
if (!\Drupal::config('media.settings')->get('standalone_url')) {
// @todo fix in https://www.drupal.org/project/drupal/issues/3524300.
// The logic for finding media entities (which are used to provide entity link suggestions in CKEditor)
// should be at the API level for bundles. From the core, we enable node bundle selection only
// @see \Drupal\ckeditor5\Hook\Ckeditor5Hooks::entityBundleInfoAlter().
// To generates entity link suggestions for use by an autocomplete in CKEditor 5, an equivalent entity selection
// plugin is selected, @see \Drupal\ckeditor5\Controller\EntityLinkSuggestionsController::getSuggestions.
// This is an example to build and add logic to avoid finding media entities that are not linkable:
// any media bundle whose media source does not compute a link target should be omitted.
// $query->condition('bundle', 'document', '<>');
}
// phpcs:enable
return $query;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.