Problem/Motivation
I got a fatal error in 'hal_json' entity serialization:
The website encountered an unexpected error. Please try again later.
Error: Class 'Drupal\rest\EventSubscriber\ResourceResponseSubscriber' not found in Drupal\hal\LinkManager\LinkManagerBase->getLinkDomain() (line 65 of core/modules/hal/src/LinkManager/LinkManagerBase.php).
Drupal\hal\LinkManager\LinkManagerBase->getLinkDomain(Array) (Line: 72)
Drupal\hal\LinkManager\TypeLinkManager->getTypeUri('node', 'page', Array) (Line: 38)
Drupal\hal\LinkManager\LinkManager->getTypeUri('node', 'page', Array) (Line: 71)
Drupal\hal\Normalizer\ContentEntityNormalizer->normalize(Object, 'hal_json', Array) (Line: 142)
...
I noticed that the recently closed issue #2864816: HAL LinkManager doesn't add 'url.site' cache context when needed introduces the use of the missing class 'ResourceResponseSubscriber' belonging to the 'rest' module. From the committed patch #45 of that issue:
...
--- a/core/modules/hal/src/LinkManager/LinkManagerBase.php
+++ b/core/modules/hal/src/LinkManager/LinkManagerBase.php
@@ -2,6 +2,8 @@
namespace Drupal\hal\LinkManager;
+use Drupal\rest\EventSubscriber\ResourceResponseSubscriber;
+
...
That creates a new dependency of the HAL module on the 'rest' module.
Steps to reproduce
- fresh install of 8.5-dev Drupal with standard profile
- enable the HAL module. Will ask to enable serialization as well by dependency
- download and enable the devel module
- try this PHP snippet at /devel/php:
$node = \Drupal\node\Entity\Node::create([
'type' => 'page',
'title' => 'Test node',
]);
$serialized_node = \Drupal::service('serializer')->serialize($node, 'hal_json');
echo $serialized_node;
Proposed resolutions
- Add dependency declaration in the 'rest' module in HAL
- Review the implementation of #2864816: HAL LinkManager doesn't add 'url.site' cache context when needed to avoid this dependency
Remaining tasks
Comments
Comment #2
manuel.adanComment #3
dawehnerI think the right fix would be to not register the event subscriber when rest module is not installed.
Comment #5
manuel.adanI can confirm that this bug is present in 8.5.0-alpha1, which causes the fixed_block_content contributed module fail if the rest module (in core) is not installed.
Tagging this as "Contributed project soft blocker" since, as a work around, I can add the rest module as a new dependency.
However, this affects Drupal core itself. As previously mentioned, #2864816: HAL LinkManager doesn't add 'url.site' cache context when needed introduced a hard dependency in the core hal on the rest module that is not declared in hal info file, so it will fail if the rest module is not installed.
Comment #6
dawehnerI think we should merge this and #2938642: Circular dependency between serialization and rest modules into one issue.
Comment #7
timmillwoodThis looks like a duplicate of #2931765: Regression: \Drupal\hal\LinkManager\LinkManagerBase implicitly depends on REST module.
Comment #8
manuel.adan@dawehner, as far I can see, the reasons for dependency on the rest module are different in hal than in serialization, so I think it's better to have an issue for each bug.
@timmillwood, this issue was opened earlier than #2931765: Regression: \Drupal\hal\LinkManager\LinkManagerBase implicitly depends on REST module, but there are some work done in that one that solves the bug described here, so I'm closing this as duplicate.
Comment #9
wim leers#2931765: Regression: \Drupal\hal\LinkManager\LinkManagerBase implicitly depends on REST module has just been committed.