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

  1. fresh install of 8.5-dev Drupal with standard profile
  2. enable the HAL module. Will ask to enable serialization as well by dependency
  3. download and enable the devel module
  4. 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

  1. Add dependency declaration in the 'rest' module in HAL
  2. Review the implementation of #2864816: HAL LinkManager doesn't add 'url.site' cache context when needed to avoid this dependency

Remaining tasks

CommentFileSizeAuthor
#2 2928869-2.patch265 bytesmanuel.adan

Comments

manuel.adan created an issue. See original summary.

manuel.adan’s picture

Assigned: manuel.adan » Unassigned
Status: Active » Needs review
StatusFileSize
new265 bytes
dawehner’s picture

I think the right fix would be to not register the event subscriber when rest module is not installed.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

manuel.adan’s picture

I 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.

dawehner’s picture

I think we should merge this and #2938642: Circular dependency between serialization and rest modules into one issue.

timmillwood’s picture

manuel.adan’s picture

@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.

wim leers’s picture