Hello,

When I create a node with a url field via code ( both my own code and devel generate), i can't access the node via /node/nid. On my screen the following error shows up:

Fatal error: Unsupported operand types in path/to/project/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php on line 188

When I look at my error messages a get the following:
Recoverable fatal error: Argument 2 passed to Drupal\Core\Utility\UnroutedUrlAssembler::assemble() must be of the type array, null given, called in path/to/project/drupal8test.local/core/lib/Drupal/Core/Url.php on line 743 and defined in Drupal\Core\Utility\UnroutedUrlAssembler->assemble() (line 60 of path/to/project/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php).

Oddly enough, when i edit the node and save it, the node/nid page works.

I did a quick fix on my local project in the /core/lib/Drupal/Core/url.php in the function toString() :

public function toString() {
    if ($this->unrouted) {
+      if(empty($this->getOptions)) {
+        return $this->unroutedUrlAssembler()->assemble($this->getUri(), []);
+      }
+      else {
        return $this->unroutedUrlAssembler()->assemble($this->getUri(), $this->getOptions());
+      }
    }

I'm not shore if this is the correct way to solve it.

CommentFileSizeAuthor
#1 node_access_via_code-2458671-1.patch1.31 KBmac_weber

Comments

mac_weber’s picture

Status: Active » Needs review
StatusFileSize
new1.31 KB

Thanks @al0a. Next time upload a patch file, it is easier to review and the bot can automatically test it ;)

I had to do some modifications on your code, as $this->getOptions() is a function and it cannot be used directly as an argument for empty() in PHP<5.5. The current supported version for Drupal 8 is PHP 5.4.5 or higher.

dawehner’s picture

Status: Needs review » Needs work

Well, I'd argue that \Drupal\Core\Url::getOptions should simply always return an array.

mac_weber’s picture

Status: Needs work » Fixed
oriol_e9g’s picture

Version: 8.0.0-beta7 » 8.0.x-dev
Status: Fixed » Needs work

Nothing is commit... why it's fixed?

mac_weber’s picture

Status: Needs work » Fixed

It is fixed because this error does not exist anymore. It was not caused by the Link module and the way it was fixed here is not correct.

I just tested creating nodes with link via custom code and via drush. Both working fine.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.