Commit a9f61307 authored by alexpott's avatar alexpott

Issue #2787183 by Berdir: LinkItem::getUrl() fails if options are NULL

parent 21d1b479
......@@ -169,7 +169,7 @@ public static function mainPropertyName() {
* {@inheritdoc}
*/
public function getUrl() {
return Url::fromUri($this->uri, $this->options);
return Url::fromUri($this->uri, (array) $this->options);
}
/**
......
......@@ -5,6 +5,7 @@
use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
......@@ -154,6 +155,11 @@ public function testLinkItem() {
$this->assertNull($entity->field_test->title);
$this->assertIdentical($entity->field_test->options, []);
// Check that setting options to NULL does not trigger an error when
// calling getUrl();
$entity->field_test->options = NULL;
$this->assertInstanceOf(Url::class, $entity->field_test[0]->getUrl());
// Check that setting LinkItem value NULL doesn't generate any error or
// warning.
$entity->field_test[0] = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment