diff --git a/core/modules/editor/editor.module b/core/modules/editor/editor.module index 7fa3c05..c0ea371 100644 --- a/core/modules/editor/editor.module +++ b/core/modules/editor/editor.module @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\Html; +use Drupal\Core\Database\InvalidQueryException; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Form\FormStateInterface; @@ -414,7 +415,12 @@ function editor_entity_revision_delete(EntityInterface $entity) { */ function _editor_record_file_usage(array $uuids, EntityInterface $entity) { foreach ($uuids as $uuid) { - if ($file = \Drupal::entityManager()->loadEntityByUuid('file', $uuid)) { + try { + $file = \Drupal::entityManager()->loadEntityByUuid('file', $uuid); + } catch (InvalidQueryException $ex) { + $file = NULL; + } + if ($file) { if ($file->status !== FILE_STATUS_PERMANENT) { $file->status = FILE_STATUS_PERMANENT; $file->save(); @@ -439,7 +445,12 @@ function _editor_record_file_usage(array $uuids, EntityInterface $entity) { */ function _editor_delete_file_usage(array $uuids, EntityInterface $entity, $count) { foreach ($uuids as $uuid) { - if ($file = \Drupal::entityManager()->loadEntityByUuid('file', $uuid)) { + try { + $file = \Drupal::entityManager()->loadEntityByUuid('file', $uuid); + } catch (InvalidQueryException $ex) { + $file = NULL; + } + if ($file) { \Drupal::service('file.usage')->delete($file, 'editor', $entity->getEntityTypeId(), $entity->id(), $count); } } diff --git a/core/modules/editor/src/Plugin/Filter/EditorFileReference.php b/core/modules/editor/src/Plugin/Filter/EditorFileReference.php index 41161ab..aafafe8 100644 --- a/core/modules/editor/src/Plugin/Filter/EditorFileReference.php +++ b/core/modules/editor/src/Plugin/Filter/EditorFileReference.php @@ -8,6 +8,7 @@ namespace Drupal\editor\Plugin\Filter; use Drupal\Component\Utility\Html; +use Drupal\Core\Database\InvalidQueryException; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\filter\FilterProcessResult; @@ -80,7 +81,12 @@ public function process($text, $langcode) { if (!isset($processed_uuids[$uuid])) { $processed_uuids[$uuid] = TRUE; - $file = $this->entityManager->loadEntityByUuid('file', $uuid); + try { + $file = $this->entityManager->loadEntityByUuid('file', $uuid); + } + catch (InvalidQueryException $e) { + $file = NULL; + } if ($file) { $result->addCacheTags($file->getCacheTags()); } diff --git a/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php b/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php index 1205650..87809ef 100644 --- a/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php +++ b/core/modules/editor/src/Tests/EditorFileReferenceFilterTest.php @@ -96,15 +96,11 @@ function testEditorFileReferenceFilter() { $this->assertIdentical($input, $output->getProcessedText()); $this->assertEqual($cache_tag, $output->getCacheTags()); - /** - * @todo: Determine how to treat queries for invalid UUIDs. - * @see https://www.drupal.org/node/2403271 $this->pass('One data-entity-uuid attribute with an invalid value.'); $input = ''; $output = $test($input); $this->assertIdentical($input, $output->getProcessedText()); $this->assertEqual(array(), $output->getCacheTags()); - */ $this->pass('Two different data-entity-uuid attributes.'); $input = ''; diff --git a/core/modules/editor/src/Tests/EditorFileUsageTest.php b/core/modules/editor/src/Tests/EditorFileUsageTest.php index 926228e..7b5210e 100644 --- a/core/modules/editor/src/Tests/EditorFileUsageTest.php +++ b/core/modules/editor/src/Tests/EditorFileUsageTest.php @@ -65,9 +65,7 @@ public function testEditorEntityHooks() { $body_value = '

Hello, world!

'; // Test handling of an invalid data-entity-uuid attribute. - // @todo: Determine how to change this test for invalid UUIDs. - // @see https://www.drupal.org/node/2403271 - // $body_value .= ''; + $body_value .= ''; // Test handling of an invalid data-entity-type attribute. $body_value .= ''; // Test handling of a non-existing UUID.