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.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | node_access_via_code-2458671-1.patch | 1.31 KB | mac_weber |
Comments
Comment #1
mac_weber commentedThanks @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 forempty()in PHP<5.5. The current supported version for Drupal 8 is PHP 5.4.5 or higher.Comment #3
dawehnerWell, I'd argue that
\Drupal\Core\Url::getOptionsshould simply always return an array.Comment #4
mac_weber commentedComment #5
oriol_e9gNothing is commit... why it's fixed?
Comment #6
mac_weber commentedIt 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.