function MediaWithLinkTargetSelection::buildEntityQuery

File

core/modules/media/src/Plugin/EntityReferenceSelection/MediaWithLinkTargetSelection.php, line 33

Class

MediaWithLinkTargetSelection
Limits selection of media entities to those that have a link target.

Namespace

Drupal\media\Plugin\EntityReferenceSelection

Code

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.