Core and composer updates

This commit is contained in:
Rob Davies 2017-07-03 16:47:07 +01:00
parent a82634bb98
commit 62cac30480
1118 changed files with 21770 additions and 6306 deletions

View file

@ -72,8 +72,9 @@ class LinkWidget extends WidgetBase {
elseif ($scheme === 'entity') {
list($entity_type, $entity_id) = explode('/', substr($uri, 7), 2);
// Show the 'entity:' URI as the entity autocomplete would.
$entity_manager = \Drupal::entityManager();
if ($entity_manager->getDefinition($entity_type, FALSE) && $entity = \Drupal::entityManager()->getStorage($entity_type)->load($entity_id)) {
// @todo Support entity types other than 'node'. Will be fixed in
// https://www.drupal.org/node/2423093.
if ($entity_type == 'node' && $entity = \Drupal::entityTypeManager()->getStorage($entity_type)->load($entity_id)) {
$displayable_string = EntityAutocomplete::getEntityLabels([$entity]);
}
}

View file

@ -1,12 +1,12 @@
<?php
namespace Drupal\link\Plugin\migrate\cckfield;
namespace Drupal\link\Plugin\migrate\field\d6;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
use Drupal\migrate_drupal\Plugin\migrate\field\FieldPluginBase;
/**
* @MigrateCckField(
* @MigrateField(
* id = "link",
* core = {6},
* type_map = {
@ -14,13 +14,13 @@ use Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase;
* }
* )
*/
class LinkField extends CckFieldPluginBase {
class LinkField extends FieldPluginBase {
/**
* {@inheritdoc}
*/
public function getFieldFormatterMap() {
// See d6_field_formatter_settings.yml and CckFieldPluginBase
// See d6_field_formatter_settings.yml and FieldPluginBase
// processFieldFormatter().
return [
'default' => 'link',
@ -37,9 +37,9 @@ class LinkField extends CckFieldPluginBase {
/**
* {@inheritdoc}
*/
public function processCckFieldValues(MigrationInterface $migration, $field_name, $data) {
public function processFieldValues(MigrationInterface $migration, $field_name, $data) {
$process = [
'plugin' => 'd6_cck_link',
'plugin' => 'd6_field_link',
'source' => $field_name,
];
$migration->mergeProcessOfProperty($field_name, $process);

View file

@ -1,12 +1,12 @@
<?php
namespace Drupal\link\Plugin\migrate\cckfield\d7;
namespace Drupal\link\Plugin\migrate\field\d7;
use Drupal\link\Plugin\migrate\cckfield\LinkField as D6LinkField;
use Drupal\link\Plugin\migrate\field\d6\LinkField as D6LinkField;
use Drupal\migrate\Plugin\MigrationInterface;
/**
* @MigrateCckField(
* @MigrateField(
* id = "link_field",
* core = {7},
* type_map = {

View file

@ -2,85 +2,16 @@
namespace Drupal\link\Plugin\migrate\process\d6;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
@trigger_error('CckLink is deprecated in Drupal 8.3.x and will be removed before
Drupal 9.0.x. Use \Drupal\link\Plugin\migrate\process\d6\FieldLink instead.',
E_USER_DEPRECATED);
/**
* @MigrateProcessPlugin(
* id = "d6_cck_link"
* )
*
* @deprecated in Drupal 8.3.x, to be removed before Drupal 9.0.x. Use
* \Drupal\link\Plugin\migrate\process\d6\FieldLink instead.
*/
class CckLink extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migration = $migration;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$migration
);
}
/**
* Turn a Drupal 6 URI into a Drupal 8-compatible format.
*
* @param string $uri
* The 'url' value from Drupal 6.
*
* @return string
* The Drupal 8-compatible URI.
*
* @see \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::getUserEnteredStringAsUri()
*/
protected function canonicalizeUri($uri) {
// If we already have a scheme, we're fine.
if (empty($uri) || !is_null(parse_url($uri, PHP_URL_SCHEME))) {
return $uri;
}
// Remove the <front> component of the URL.
if (strpos($uri, '<front>') === 0) {
$uri = substr($uri, strlen('<front>'));
}
// Add the internal: scheme and ensure a leading slash.
return 'internal:/' . ltrim($uri, '/');
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$attributes = unserialize($value['attributes']);
// Drupal 6 link attributes might be double serialized.
if (!is_array($attributes)) {
$attributes = unserialize($attributes);
}
if (!$attributes) {
$attributes = [];
}
// Massage the values into the correct form for the link.
$route['uri'] = $this->canonicalizeUri($value['url']);
$route['options']['attributes'] = $attributes;
$route['title'] = $value['title'];
return $route;
}
}
class CckLink extends FieldLink { }

View file

@ -0,0 +1,86 @@
<?php
namespace Drupal\link\Plugin\migrate\process\d6;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* @MigrateProcessPlugin(
* id = "d6_field_link"
* )
*/
class FieldLink extends ProcessPluginBase implements ContainerFactoryPluginInterface {
/**
* {@inheritdoc}
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migration = $migration;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$migration
);
}
/**
* Turn a Drupal 6 URI into a Drupal 8-compatible format.
*
* @param string $uri
* The 'url' value from Drupal 6.
*
* @return string
* The Drupal 8-compatible URI.
*
* @see \Drupal\link\Plugin\Field\FieldWidget\LinkWidget::getUserEnteredStringAsUri()
*/
protected function canonicalizeUri($uri) {
// If we already have a scheme, we're fine.
if (empty($uri) || !is_null(parse_url($uri, PHP_URL_SCHEME))) {
return $uri;
}
// Remove the <front> component of the URL.
if (strpos($uri, '<front>') === 0) {
$uri = substr($uri, strlen('<front>'));
}
// Add the internal: scheme and ensure a leading slash.
return 'internal:/' . ltrim($uri, '/');
}
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
$attributes = unserialize($value['attributes']);
// Drupal 6 link attributes might be double serialized.
if (!is_array($attributes)) {
$attributes = unserialize($attributes);
}
if (!$attributes) {
$attributes = [];
}
// Massage the values into the correct form for the link.
$route['uri'] = $this->canonicalizeUri($value['url']);
$route['options']['attributes'] = $attributes;
$route['title'] = $value['title'];
return $route;
}
}

View file

@ -8,6 +8,7 @@ use Drupal\Core\Url;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldConfig;
use Drupal\link\LinkItemInterface;
use Drupal\node\NodeInterface;
use Drupal\Tests\BrowserTestBase;
use Drupal\field\Entity\FieldStorageConfig;
@ -95,11 +96,7 @@ class LinkFieldTest extends BrowserTestBase {
// Create a node to test the link widget.
$node = $this->drupalCreateNode();
// Create an entity with restricted view access.
$entity_test_no_label_access = EntityTest::create([
'name' => 'forbid_access',
]);
$entity_test_no_label_access->save();
$restricted_node = $this->drupalCreateNode(['status' => NodeInterface::NOT_PUBLISHED]);
// Define some valid URLs (keys are the entered values, values are the
// strings displayed to the user).
@ -134,7 +131,7 @@ class LinkFieldTest extends BrowserTestBase {
// Entity URI displayed as ER autocomplete value when displayed in a form.
'entity:node/1' => $node->label() . ' (1)',
// URI for an entity that exists, but is not accessible by the user.
'entity:entity_test/' . $entity_test_no_label_access->id() => '- Restricted access - (' . $entity_test_no_label_access->id() . ')',
'entity:node/' . $restricted_node->id() => '- Restricted access - (' . $restricted_node->id() . ')',
// URI for an entity that doesn't exist, but with a valid ID.
'entity:user/999999' => 'entity:user/999999',
];
@ -609,6 +606,67 @@ class LinkFieldTest extends BrowserTestBase {
}
}
/**
* Tests editing a link to a non-node entity.
*/
public function testEditNonNodeEntityLink() {
$entity_type_manager = \Drupal::entityTypeManager();
$entity_test_storage = $entity_type_manager->getStorage('entity_test');
// Create a field with settings to validate.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => 'field_link',
'entity_type' => 'entity_test',
'type' => 'link',
'cardinality' => 1,
]);
$this->fieldStorage->save();
FieldConfig::create([
'field_storage' => $this->fieldStorage,
'label' => 'Read more about this entity',
'bundle' => 'entity_test',
'settings' => [
'title' => DRUPAL_OPTIONAL,
],
])->save();
$entity_type_manager
->getStorage('entity_form_display')
->load('entity_test.entity_test.default')
->setComponent('field_link', [
'type' => 'link_default',
])
->save();
// Create a node and a test entity to have a possibly valid reference for
// both. Create another test entity that references the first test entity.
$entity_test_link = $entity_test_storage->create(['name' => 'correct link target']);
$entity_test_link->save();
$node = $this->drupalCreateNode(['wrong link target']);
$correct_link = 'entity:entity_test/' . $entity_test_link->id();
$entity_test = $entity_test_storage->create([
'name' => 'correct link target',
'field_link' => $correct_link,
]);
$entity_test->save();
// Edit the entity and save it, verify the correct link is kept and not
// changed to point to a node. Currently, widget does not support non-node
// autocomplete and therefore must show the link unaltered.
$this->drupalGet($entity_test->toUrl('edit-form'));
$this->assertSession()->fieldValueEquals('field_link[0][uri]', $correct_link);
$this->drupalPostForm(NULL, [], 'Save');
$entity_test_storage->resetCache();
$entity_test = $entity_test_storage->load($entity_test->id());
$this->assertEquals($correct_link, $entity_test->get('field_link')->uri);
}
/**
* Renders a test_entity and returns the output.
*

View file

@ -2,21 +2,21 @@
namespace Drupal\Tests\link\Unit\Plugin\migrate\process\d6;
use Drupal\link\Plugin\migrate\process\d6\CckLink;
use Drupal\link\Plugin\migrate\process\d6\FieldLink;
use Drupal\Tests\UnitTestCase;
/**
* @group Link
*/
class CckLinkTest extends UnitTestCase {
class FieldLinkTest extends UnitTestCase {
/**
* Test the url transformations in the CckLink process plugin.
* Test the url transformations in the FieldLink process plugin.
*
* @dataProvider canonicalizeUriDataProvider
*/
public function testCanonicalizeUri($url, $expected) {
$link_plugin = new CckLink([], '', [], $this->getMock('\Drupal\migrate\Plugin\MigrationInterface'));
$link_plugin = new FieldLink([], '', [], $this->getMock('\Drupal\migrate\Plugin\MigrationInterface'));
$transformed = $link_plugin->transform([
'url' => $url,
'title' => '',