Commit 17f5f48b authored by alexpott's avatar alexpott

Issue #2411143 by dawehner, effulgentsia, amateescu, larowlan: Change LinkItem...

Issue #2411143 by dawehner, effulgentsia, amateescu, larowlan: Change LinkItem schema to store URIs rather than URLs/paths/routes
parent 91a05649
...@@ -86,7 +86,7 @@ public function testBlockFields() { ...@@ -86,7 +86,7 @@ public function testBlockFields() {
$this->drupalGet('block/add/link'); $this->drupalGet('block/add/link');
$edit = array( $edit = array(
'info[0][value]' => $this->randomMachineName(8), 'info[0][value]' => $this->randomMachineName(8),
$this->fieldStorage->getName() . '[0][url]' => 'http://example.com', $this->fieldStorage->getName() . '[0][uri]' => 'http://example.com',
$this->fieldStorage->getName() . '[0][title]' => 'Example.com' $this->fieldStorage->getName() . '[0][title]' => 'Example.com'
); );
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
......
...@@ -9,11 +9,15 @@ ...@@ -9,11 +9,15 @@
use Drupal\Component\Utility\String; use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FormatterBase; use Drupal\Core\Field\FormatterBase;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Path\PathValidatorInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url; use Drupal\Core\Url;
use Drupal\link\LinkItemInterface; use Drupal\link\LinkItemInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
/** /**
...@@ -27,7 +31,55 @@ ...@@ -27,7 +31,55 @@
* } * }
* ) * )
*/ */
class LinkFormatter extends FormatterBase { class LinkFormatter extends FormatterBase implements ContainerFactoryPluginInterface {
/**
* The path validator service.
*
* @var \Drupal\Core\Path\PathValidatorInterface
*/
protected $pathValidator;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$plugin_id,
$plugin_definition,
$configuration['field_definition'],
$configuration['settings'],
$configuration['label'],
$configuration['view_mode'],
$configuration['third_party_settings'],
$container->get('path.validator')
);
}
/**
* Constructs a new LinkFormatter.
*
* @param string $plugin_id
* The plugin_id for the formatter.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
* The definition of the field to which the formatter is associated.
* @param array $settings
* The formatter settings.
* @param string $label
* The formatter label display setting.
* @param string $view_mode
* The view mode.
* @param array $third_party_settings
* Third party settings.
* @param \Drupal\Core\Path\PathValidatorInterface $path_validator
* The path validator service.
*/
public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, PathValidatorInterface $path_validator) {
parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
$this->pathValidator = $path_validator;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
...@@ -155,7 +207,7 @@ public function viewElements(FieldItemListInterface $items) { ...@@ -155,7 +207,7 @@ public function viewElements(FieldItemListInterface $items) {
// Piggyback on the metadata attributes, which will be placed in the // Piggyback on the metadata attributes, which will be placed in the
// field template wrapper, and set the URL value in a content // field template wrapper, and set the URL value in a content
// attribute. // attribute.
$item->_attributes += array('content' => $item->url); $item->_attributes += array('content' => $item->uri);
} }
} }
else { else {
...@@ -189,6 +241,10 @@ public function viewElements(FieldItemListInterface $items) { ...@@ -189,6 +241,10 @@ public function viewElements(FieldItemListInterface $items) {
* An Url object. * An Url object.
*/ */
protected function buildUrl(LinkItemInterface $item) { protected function buildUrl(LinkItemInterface $item) {
// @todo Consider updating the usage of the path validator with whatever
// gets added in https://www.drupal.org/node/2405551.
$url = $this->pathValidator->getUrlIfValidWithoutAccessCheck($item->uri) ?: Url::fromRoute('<none>');
$settings = $this->getSettings(); $settings = $this->getSettings();
$options = $item->options; $options = $item->options;
...@@ -200,13 +256,7 @@ protected function buildUrl(LinkItemInterface $item) { ...@@ -200,13 +256,7 @@ protected function buildUrl(LinkItemInterface $item) {
if (!empty($settings['target'])) { if (!empty($settings['target'])) {
$options['attributes']['target'] = $settings['target']; $options['attributes']['target'] = $settings['target'];
} }
$url->setOptions($options);
if ($item->isExternal()) {
$url = Url::fromUri($item->url, $options);
}
else {
$url = Url::fromRoute($item->route_name, (array) $item->route_parameters, (array) $options);
}
return $url; return $url;
} }
......
...@@ -44,18 +44,14 @@ public static function defaultFieldSettings() { ...@@ -44,18 +44,14 @@ public static function defaultFieldSettings() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['url'] = DataDefinition::create('string') // @todo Change the type from 'string' to 'uri':
->setLabel(t('URL')); // https://www.drupal.org/node/2412509.
$properties['uri'] = DataDefinition::create('string')
->setLabel(t('URI'));
$properties['title'] = DataDefinition::create('string') $properties['title'] = DataDefinition::create('string')
->setLabel(t('Link text')); ->setLabel(t('Link text'));
$properties['route_name'] = DataDefinition::create('string')
->setLabel(t('Route name'));
$properties['route_parameters'] = MapDataDefinition::create()
->setLabel(t('Route parameters'));
$properties['options'] = MapDataDefinition::create() $properties['options'] = MapDataDefinition::create()
->setLabel(t('Options')); ->setLabel(t('Options'));
...@@ -68,8 +64,8 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel ...@@ -68,8 +64,8 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel
public static function schema(FieldStorageDefinitionInterface $field_definition) { public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array( return array(
'columns' => array( 'columns' => array(
'url' => array( 'uri' => array(
'description' => 'The URL of the link.', 'description' => 'The URI of the link.',
'type' => 'varchar', 'type' => 'varchar',
'length' => 2048, 'length' => 2048,
), ),
...@@ -78,17 +74,6 @@ public static function schema(FieldStorageDefinitionInterface $field_definition) ...@@ -78,17 +74,6 @@ public static function schema(FieldStorageDefinitionInterface $field_definition)
'type' => 'varchar', 'type' => 'varchar',
'length' => 255, 'length' => 255,
), ),
'route_name' => array(
'description' => 'The machine name of a defined Route this link represents.',
'type' => 'varchar',
'length' => 255,
),
'route_parameters' => array(
'description' => 'Serialized array of route parameters of the link.',
'type' => 'blob',
'size' => 'big',
'serialize' => TRUE,
),
'options' => array( 'options' => array(
'description' => 'Serialized array of options for the link.', 'description' => 'Serialized array of options for the link.',
'type' => 'blob', 'type' => 'blob',
...@@ -152,7 +137,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin ...@@ -152,7 +137,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin
$values['title'] = mt_rand(0,1) ? $random->sentences(4) : ''; $values['title'] = mt_rand(0,1) ? $random->sentences(4) : '';
break; break;
} }
$values['url'] = 'http://www.' . $random->word($domain_length) . '.' . $tlds[mt_rand(0, (sizeof($tlds)-1))]; $values['uri'] = 'http://www.' . $random->word($domain_length) . '.' . $tlds[mt_rand(0, (sizeof($tlds)-1))];
return $values; return $values;
} }
...@@ -160,7 +145,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin ...@@ -160,7 +145,7 @@ public static function generateSampleValue(FieldDefinitionInterface $field_defin
* {@inheritdoc} * {@inheritdoc}
*/ */
public function isEmpty() { public function isEmpty() {
$value = $this->get('url')->getValue(); $value = $this->get('uri')->getValue();
return $value === NULL || $value === ''; return $value === NULL || $value === '';
} }
...@@ -168,14 +153,15 @@ public function isEmpty() { ...@@ -168,14 +153,15 @@ public function isEmpty() {
* {@inheritdoc} * {@inheritdoc}
*/ */
public function isExternal() { public function isExternal() {
// External links don't have a route_name value. // External links don't resolve to a route.
return empty($this->route_name); $url = \Drupal::pathValidator()->getUrlIfValid($this->uri);
return $url->isExternal();
} }
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public static function mainPropertyName() { public static function mainPropertyName() {
return 'url'; return 'uri';
} }
} }
...@@ -41,13 +41,13 @@ public static function defaultSettings() { ...@@ -41,13 +41,13 @@ public static function defaultSettings() {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) { public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$default_url_value = NULL; $default_url_value = NULL;
if (isset($items[$delta]->url)) { if (isset($items[$delta]->uri)) {
if ($url = \Drupal::pathValidator()->getUrlIfValid($items[$delta]->url)) { if ($url = \Drupal::pathValidator()->getUrlIfValid($items[$delta]->uri)) {
$url->setOptions($items[$delta]->options); $url->setOptions($items[$delta]->options);
$default_url_value = ltrim($url->toString(), '/'); $default_url_value = ltrim($url->toString(), '/');
} }
} }
$element['url'] = array( $element['uri'] = array(
'#type' => 'url', '#type' => 'url',
'#title' => $this->t('URL'), '#title' => $this->t('URL'),
'#placeholder' => $this->getSetting('placeholder_url'), '#placeholder' => $this->getSetting('placeholder_url'),
...@@ -59,18 +59,18 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen ...@@ -59,18 +59,18 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
// If the field is configured to support internal links, it cannot use the // If the field is configured to support internal links, it cannot use the
// 'url' form element and we have to do the validation ourselves. // 'url' form element and we have to do the validation ourselves.
if ($this->supportsInternalLinks()) { if ($this->supportsInternalLinks()) {
$element['url']['#type'] = 'textfield'; $element['uri']['#type'] = 'textfield';
} }
// If the field is configured to allow only internal links, add a useful // If the field is configured to allow only internal links, add a useful
// element prefix. // element prefix.
if (!$this->supportsExternalLinks()) { if (!$this->supportsExternalLinks()) {
$element['url']['#field_prefix'] = \Drupal::url('<front>', array(), array('absolute' => TRUE)); $element['uri']['#field_prefix'] = \Drupal::url('<front>', array(), array('absolute' => TRUE));
} }
// If the field is configured to allow both internal and external links, // If the field is configured to allow both internal and external links,
// show a useful description. // show a useful description.
elseif ($this->supportsExternalLinks() && $this->supportsInternalLinks()) { elseif ($this->supportsExternalLinks() && $this->supportsInternalLinks()) {
$element['url']['#description'] = $this->t('This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array('%front' => '<front>', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org')); $element['uri']['#description'] = $this->t('This can be an internal Drupal path such as %add-node or an external URL such as %drupal. Enter %front to link to the front page.', array('%front' => '<front>', '%add-node' => 'node/add', '%drupal' => 'http://drupal.org'));
} }
$element['title'] = array( $element['title'] = array(
...@@ -188,7 +188,7 @@ public function settingsSummary() { ...@@ -188,7 +188,7 @@ public function settingsSummary() {
* Conditionally requires the link title if a URL value was filled in. * Conditionally requires the link title if a URL value was filled in.
*/ */
public function validateTitle(&$element, FormStateInterface $form_state, $form) { public function validateTitle(&$element, FormStateInterface $form_state, $form) {
if ($element['url']['#value'] !== '' && $element['title']['#value'] === '') { if ($element['uri']['#value'] !== '' && $element['title']['#value'] === '') {
$element['title']['#required'] = TRUE; $element['title']['#required'] = TRUE;
$form_state->setError($element['title'], $this->t('!name field is required.', array('!name' => $element['title']['#title']))); $form_state->setError($element['title'], $this->t('!name field is required.', array('!name' => $element['title']['#title'])));
} }
...@@ -199,19 +199,16 @@ public function validateTitle(&$element, FormStateInterface $form_state, $form) ...@@ -199,19 +199,16 @@ public function validateTitle(&$element, FormStateInterface $form_state, $form)
*/ */
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
foreach ($values as &$value) { foreach ($values as &$value) {
if (!empty($value['url'])) { if (!empty($value['uri'])) {
$url = \Drupal::pathValidator()->getUrlIfValid($value['url']); $url = \Drupal::pathValidator()->getUrlIfValid($value['uri']);
if (!$url) { if (!$url) {
return $values; return $values;
} }
// @todo Don't use the toArray method here. Removed once it is $value += ['options' => []];
// deprecated.
$value += $url->toArray();
// Reset the URL value to contain only the path. // Reset the URL value to contain only the path.
if (!$url->isExternal() && $this->supportsInternalLinks()) { if (!$url->isExternal() && $this->supportsInternalLinks()) {
$value['url'] = substr($url->toString(), strlen(\Drupal::request()->getBasePath() . '/')); $value['uri'] = substr($url->toString(), strlen(\Drupal::request()->getBasePath() . '/'));
} }
} }
} }
......
...@@ -52,7 +52,7 @@ public function validate($value, Constraint $constraint) { ...@@ -52,7 +52,7 @@ public function validate($value, Constraint $constraint) {
/** @var $link_item \Drupal\link\LinkItemInterface */ /** @var $link_item \Drupal\link\LinkItemInterface */
$link_item = $value; $link_item = $value;
$link_type = $link_item->getFieldDefinition()->getSetting('link_type'); $link_type = $link_item->getFieldDefinition()->getSetting('link_type');
$url_string = $link_item->url; $url_string = $link_item->uri;
// Validate the url property. // Validate the url property.
if ($url_string !== '') { if ($url_string !== '') {
if ($url = \Drupal::pathValidator()->getUrlIfValid($url_string)) { if ($url = \Drupal::pathValidator()->getUrlIfValid($url_string)) {
......
...@@ -88,7 +88,7 @@ function testURLValidation() { ...@@ -88,7 +88,7 @@ function testURLValidation() {
// Display creation form. // Display creation form.
$this->drupalGet('entity_test/add'); $this->drupalGet('entity_test/add');
$this->assertFieldByName("{$field_name}[0][url]", '', 'Link URL field is displayed'); $this->assertFieldByName("{$field_name}[0][uri]", '', 'Link URL field is displayed');
$this->assertRaw('placeholder="http://example.com"'); $this->assertRaw('placeholder="http://example.com"');
// Create a path alias. // Create a path alias.
...@@ -143,7 +143,7 @@ function testURLValidation() { ...@@ -143,7 +143,7 @@ function testURLValidation() {
protected function assertValidEntries($field_name, array $valid_entries) { protected function assertValidEntries($field_name, array $valid_entries) {
foreach ($valid_entries as $value) { foreach ($valid_entries as $value) {
$edit = array( $edit = array(
"{$field_name}[0][url]" => $value, "{$field_name}[0][uri]" => $value,
); );
$this->drupalPostForm('entity_test/add', $edit, t('Save')); $this->drupalPostForm('entity_test/add', $edit, t('Save'));
preg_match('|entity_test/manage/(\d+)|', $this->url, $match); preg_match('|entity_test/manage/(\d+)|', $this->url, $match);
...@@ -164,7 +164,7 @@ protected function assertValidEntries($field_name, array $valid_entries) { ...@@ -164,7 +164,7 @@ protected function assertValidEntries($field_name, array $valid_entries) {
protected function assertInvalidEntries($field_name, array $invalid_entries) { protected function assertInvalidEntries($field_name, array $invalid_entries) {
foreach ($invalid_entries as $invalid_value) { foreach ($invalid_entries as $invalid_value) {
$edit = array( $edit = array(
"{$field_name}[0][url]" => $invalid_value, "{$field_name}[0][uri]" => $invalid_value,
); );
$this->drupalPostForm('entity_test/add', $edit, t('Save')); $this->drupalPostForm('entity_test/add', $edit, t('Save'));
$this->assertText(t('The URL @url is not valid.', array('@url' => $invalid_value))); $this->assertText(t('The URL @url is not valid.', array('@url' => $invalid_value)));
...@@ -219,7 +219,7 @@ function testLinkTitle() { ...@@ -219,7 +219,7 @@ function testLinkTitle() {
$this->drupalGet('entity_test/add'); $this->drupalGet('entity_test/add');
// Assert label is shown. // Assert label is shown.
$this->assertText('Read more about this entity'); $this->assertText('Read more about this entity');
$this->assertFieldByName("{$field_name}[0][url]", '', 'URL field found.'); $this->assertFieldByName("{$field_name}[0][uri]", '', 'URL field found.');
$this->assertRaw('placeholder="http://example.com"'); $this->assertRaw('placeholder="http://example.com"');
if ($title_setting === DRUPAL_DISABLED) { if ($title_setting === DRUPAL_DISABLED) {
...@@ -233,14 +233,14 @@ function testLinkTitle() { ...@@ -233,14 +233,14 @@ function testLinkTitle() {
if ($title_setting === DRUPAL_REQUIRED) { if ($title_setting === DRUPAL_REQUIRED) {
// Verify that the link text is required, if the URL is non-empty. // Verify that the link text is required, if the URL is non-empty.
$edit = array( $edit = array(
"{$field_name}[0][url]" => 'http://www.example.com', "{$field_name}[0][uri]" => 'http://www.example.com',
); );
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertText(t('!name field is required.', array('!name' => t('Link text')))); $this->assertText(t('!name field is required.', array('!name' => t('Link text'))));
// Verify that the link text is not required, if the URL is empty. // Verify that the link text is not required, if the URL is empty.
$edit = array( $edit = array(
"{$field_name}[0][url]" => '', "{$field_name}[0][uri]" => '',
); );
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
$this->assertNoText(t('!name field is required.', array('!name' => t('Link text')))); $this->assertNoText(t('!name field is required.', array('!name' => t('Link text'))));
...@@ -248,7 +248,7 @@ function testLinkTitle() { ...@@ -248,7 +248,7 @@ function testLinkTitle() {
// Verify that a URL and link text meets requirements. // Verify that a URL and link text meets requirements.
$this->drupalGet('entity_test/add'); $this->drupalGet('entity_test/add');
$edit = array( $edit = array(
"{$field_name}[0][url]" => 'http://www.example.com', "{$field_name}[0][uri]" => 'http://www.example.com',
"{$field_name}[0][title]" => 'Example', "{$field_name}[0][title]" => 'Example',
); );
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
...@@ -260,7 +260,7 @@ function testLinkTitle() { ...@@ -260,7 +260,7 @@ function testLinkTitle() {
// Verify that a link without link text is rendered using the URL as text. // Verify that a link without link text is rendered using the URL as text.
$value = 'http://www.example.com/'; $value = 'http://www.example.com/';
$edit = array( $edit = array(
"{$field_name}[0][url]" => $value, "{$field_name}[0][uri]" => $value,
"{$field_name}[0][title]" => '', "{$field_name}[0][title]" => '',
); );
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
...@@ -332,10 +332,10 @@ function testLinkFormatter() { ...@@ -332,10 +332,10 @@ function testLinkFormatter() {
// Intentionally contains an ampersand that needs sanitization on output. // Intentionally contains an ampersand that needs sanitization on output.
$title2 = 'A very long & strange example title that could break the nice layout of the site'; $title2 = 'A very long & strange example title that could break the nice layout of the site';
$edit = array( $edit = array(
"{$field_name}[0][url]" => $url1, "{$field_name}[0][uri]" => $url1,
// Note that $title1 is not submitted. // Note that $title1 is not submitted.
"{$field_name}[0][title]" => '', "{$field_name}[0][title]" => '',
"{$field_name}[1][url]" => $url2, "{$field_name}[1][uri]" => $url2,
"{$field_name}[1][title]" => $title2, "{$field_name}[1][title]" => $title2,
); );
// Assert label is shown. // Assert label is shown.
...@@ -470,8 +470,8 @@ function testLinkSeparateFormatter() { ...@@ -470,8 +470,8 @@ function testLinkSeparateFormatter() {
// Intentionally contains an ampersand that needs sanitization on output. // Intentionally contains an ampersand that needs sanitization on output.
$title2 = 'A very long & strange example title that could break the nice layout of the site'; $title2 = 'A very long & strange example title that could break the nice layout of the site';
$edit = array( $edit = array(
"{$field_name}[0][url]" => $url1, "{$field_name}[0][uri]" => $url1,
"{$field_name}[1][url]" => $url2, "{$field_name}[1][uri]" => $url2,
"{$field_name}[1][title]" => $title2, "{$field_name}[1][title]" => $title2,
); );
$this->drupalPostForm(NULL, $edit, t('Save')); $this->drupalPostForm(NULL, $edit, t('Save'));
......
...@@ -28,6 +28,7 @@ class LinkItemTest extends FieldUnitTestBase { ...@@ -28,6 +28,7 @@ class LinkItemTest extends FieldUnitTestBase {
protected function setUp() { protected function setUp() {
parent::setUp(); parent::setUp();
$this->installSchema('system', ['router']);
// Create a link field for validation. // Create a link field for validation.
entity_create('field_storage_config', array( entity_create('field_storage_config', array(
...@@ -52,7 +53,7 @@ public function testLinkItem() { ...@@ -52,7 +53,7 @@ public function testLinkItem() {
$parsed_url = UrlHelper::parse($url); $parsed_url = UrlHelper::parse($url);
$title = $this->randomMachineName(); $title = $this->randomMachineName();
$class = $this->randomMachineName(); $class = $this->randomMachineName();
$entity->field_test->url = $parsed_url['path']; $entity->field_test->uri = $parsed_url['path'];
$entity->field_test->title = $title; $entity->field_test->title = $title;
$entity->field_test->first()->get('options')->set('query', $parsed_url['query']); $entity->field_test->first()->get('options')->set('query', $parsed_url['query']);
$entity->field_test->first()->get('options')->set('attributes', array('class' => $class)); $entity->field_test->first()->get('options')->set('attributes', array('class' => $class));
...@@ -64,8 +65,8 @@ public function testLinkItem() { ...@@ -64,8 +65,8 @@ public function testLinkItem() {
$entity = entity_load('entity_test', $id); $entity = entity_load('entity_test', $id);
$this->assertTrue($entity->field_test instanceof FieldItemListInterface, 'Field implements interface.'); $this->assertTrue($entity->field_test instanceof FieldItemListInterface, 'Field implements interface.');
$this->assertTrue($entity->field_test[0] instanceof FieldItemInterface, 'Field item implements interface.'); $this->assertTrue($entity->field_test[0] instanceof FieldItemInterface, 'Field item implements interface.');
$this->assertEqual($entity->field_test->url, $parsed_url['path']); $this->assertEqual($entity->field_test->uri, $parsed_url['path']);
$this->assertEqual($entity->field_test[0]->url, $parsed_url['path']); $this->assertEqual($entity->field_test[0]->uri, $parsed_url['path']);
$this->assertEqual($entity->field_test->title, $title); $this->assertEqual($entity->field_test->title, $title);
$this->assertEqual($entity->field_test[0]->title, $title); $this->assertEqual($entity->field_test[0]->title, $title);
$this->assertEqual($entity->field_test->options['attributes']['class'], $class); $this->assertEqual($entity->field_test->options['attributes']['class'], $class);
...@@ -77,7 +78,7 @@ public function testLinkItem() { ...@@ -77,7 +78,7 @@ public function testLinkItem() {
$entity->save(); $entity->save();
$id = $entity->id(); $id = $entity->id();
$entity = entity_load('entity_test', $id); $entity = entity_load('entity_test', $id);
$this->assertEqual($entity->field_test->url, $parsed_url['path']); $this->assertEqual($entity->field_test->uri, $parsed_url['path']);
$this->assertEqual($entity->field_test->options['attributes']['class'], $class); $this->assertEqual($entity->field_test->options['attributes']['class'], $class);
$this->assertEqual($entity->field_test->options['query'], $parsed_url['query']); $this->assertEqual($entity->field_test->options['query'], $parsed_url['query']);
...@@ -85,11 +86,11 @@ public function testLinkItem() { ...@@ -85,11 +86,11 @@ public function testLinkItem() {
$new_url = 'http://drupal.org'; $new_url = 'http://drupal.org';
$new_title = $this->randomMachineName(); $new_title = $this->randomMachineName();
$new_class = $this->randomMachineName(); $new_class = $this->randomMachineName();
$entity->field_test->url = $new_url; $entity->field_test->uri = $new_url;
$entity->field_test->title = $new_title; $entity->field_test->title = $new_title;
$entity->field_test->first()->get('options')->set('query', NULL); $entity->field_test->first()->get('options')->set('query', NULL);
$entity->field_test->first()->get('options')->set('attributes', array('class' => $new_class)); $entity->field_test->first()->get('options')->set('attributes', array('class' => $new_class));
$this->assertEqual($entity->field_test->url, $new_url); $this->assertEqual($entity->field_test->uri, $new_url);
$this->assertEqual($entity->field_test->title, $new_title); $this->assertEqual($entity->field_test->title, $new_title);
$this->assertEqual($entity->field_test->options['attributes']['class'], $new_class); $this->assertEqual($entity->field_test->options['attributes']['class'], $new_class);
$this->assertNull($entity->field_test->options['query']); $this->assertNull($entity->field_test->options['query']);
...@@ -97,7 +98,7 @@ public function testLinkItem() { ...@@ -97,7 +98,7 @@ public function testLinkItem() {
// Read changed entity and assert changed values. // Read changed entity and assert changed values.
$entity->save(); $entity->save();
$entity = entity_load('entity_test', $id); $entity = entity_load('entity_test', $id);
$this->assertEqual($entity->field_test->url, $new_url); $this->assertEqual($entity->field_test->uri, $new_url);
$this->assertEqual($entity->field_test->title, $new_title); $this->assertEqual($entity->field_test->title, $new_title);
$this->assertEqual($entity->field_test->options['attributes']['class'], $new_class); $this->assertEqual($entity->field_test->options['attributes']['class'], $new_class);
......
...@@ -8,16 +8,39 @@ ...@@ -8,16 +8,39 @@
namespace Drupal\migrate_drupal\Plugin\migrate\process\d6; namespace Drupal\migrate_drupal\Plugin\migrate\process\d6;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\MigrateExecutable; use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row; use Drupal\migrate\Row;
use Drupal\migrate\Plugin\migrate\process\Route; use Drupal\migrate\Plugin\migrate\process\Route;
use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* @MigrateProcessPlugin( * @MigrateProcessPlugin(
* id = "d6_cck_link" * id = "d6_cck_link"
* ) * )