core/modules/rdf/rdf.module | 3 ++- .../src/Plugin/rest/resource/EntityResource.php | 18 ++++++++++---- core/modules/rest/src/Tests/ResourceTest.php | 28 ++++++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/core/modules/rdf/rdf.module b/core/modules/rdf/rdf.module index 33a3e92..ceda758 100644 --- a/core/modules/rdf/rdf.module +++ b/core/modules/rdf/rdf.module @@ -233,8 +233,9 @@ function rdf_comment_storage_load($comments) { $created_mapping = rdf_get_mapping('comment', $comment->bundle()) ->getPreparedFieldMapping('created'); $comment->rdf_data['date'] = rdf_rdfa_attributes($created_mapping, $comment->get('created')->first()->toArray()); + /** @var \Drupal\Core\Entity\EntityInterface $entity */ $entity = $comment->getCommentedEntity(); - $comment->rdf_data['entity_uri'] = $entity->url(); + $comment->rdf_data['entity_uri'] = $entity->toUrl()->toString(TRUE)->getGeneratedUrl(); if ($comment->hasParentComment()) { $comment->rdf_data['pid_uri'] = $comment->getParentComment()->url(); } diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php index 34b0bda..2d96603 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -144,13 +144,21 @@ public function patch(EntityInterface $original_entity, EntityInterface $entity } // Overwrite the received properties. - $langcode_key = $entity->getEntityType()->getKey('langcode'); + $entity_keys = array_values($entity->getEntityType()->getKeys()); foreach ($entity->_restSubmittedFields as $field_name) { $field = $entity->get($field_name); - // It is not possible to set the language to NULL as it is automatically - // re-initialized. As it must not be empty, skip it if it is. - if ($field_name == $langcode_key && $field->isEmpty()) { - continue; + + // Entity key fields need special treatment. + if (in_array($field_name, $entity_keys)) { + // Unchanged Values for entity keys same don't need access checking. + if ($original_entity->get($field_name)->getValue() === $entity->get($field_name)->getValue()) { + continue; + } + // It is not possible to set the language to NULL as it is automatically + // re-initialized. As it must not be empty, skip it if it is. + else if (isset($entity_keys['langcode']) && $field_name === $entity_keys['langcode'] && $field->isEmpty()) { + continue; + } } if (!$original_entity->get($field_name)->access('edit')) { diff --git a/core/modules/rest/src/Tests/ResourceTest.php b/core/modules/rest/src/Tests/ResourceTest.php index c20b751..50521cb 100644 --- a/core/modules/rest/src/Tests/ResourceTest.php +++ b/core/modules/rest/src/Tests/ResourceTest.php @@ -6,6 +6,8 @@ */ namespace Drupal\rest\Tests; + +use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Core\Session\AccountInterface; use Drupal\user\Entity\Role; @@ -121,4 +123,30 @@ public function testUriPaths() { } } + /** + * Tests that a resource with a missing plugin does not cause an exception. + */ + public function testMissingPlugin() { + $settings = array( + 'entity:nonexisting' => array( + 'GET' => array( + 'supported_formats' => array( + 'hal_json', + ), + ), + ), + ); + + try { + // Attempt to enable the resource. + $this->config->set('resources', $settings); + $this->config->save(); + $this->rebuildCache(); + $this->pass('rest.settings referencing a missing REST resource plugin does not cause an exception.'); + } + catch (PluginNotFoundException $e) { + $this->fail('rest.settings referencing a missing REST resource plugin caused an exception.'); + } + } + }