public function FileUrlSelection::validateReferenceableEntities in File URL 2.0.x
Same name and namespace in other branches
- 8 src/Plugin/EntityReferenceSelection/FileUrlSelection.php \Drupal\file_url\Plugin\EntityReferenceSelection\FileUrlSelection::validateReferenceableEntities()
Validates which existing entities can be referenced.
Parameters
array $ids: An array of IDs to validate.
Return value
array An array of valid entity IDs.
Overrides DefaultSelection::validateReferenceableEntities
File
- src/
Plugin/ EntityReferenceSelection/ FileUrlSelection.php, line 23
Class
- FileUrlSelection
- Default plugin implementation of the Entity Reference Selection plugin.
Namespace
Drupal\file_url\Plugin\EntityReferenceSelectionCode
public function validateReferenceableEntities(array $ids) {
/** @var \Drupal\file_url\FileUrlHandler $file_handler */
$file_handler = \Drupal::service('file_url.handler');
$found = [];
foreach ($ids as $id) {
$file = $file_handler::urlToFile($id);
// External file are always found.
if ($file_handler
->isRemote($file)) {
$uri = $file
->getFileUri();
}
else {
$uri = $file_handler::fileToUrl($file);
}
if (in_array($uri, $ids)) {
$found[] = $uri;
}
}
return $found;
}