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

8.3.x
Alex Pott 2016-08-22 12:46:16 +01:00
parent 21d1b47914
commit a9f6130738
2 changed files with 7 additions and 1 deletions

View File

@ -169,7 +169,7 @@ class LinkItem extends FieldItemBase implements LinkItemInterface {
* {@inheritdoc}
*/
public function getUrl() {
return Url::fromUri($this->uri, $this->options);
return Url::fromUri($this->uri, (array) $this->options);
}
/**

View File

@ -5,6 +5,7 @@ namespace Drupal\Tests\link\Kernel;
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 @@ class LinkItemTest extends FieldKernelTestBase {
$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;