Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023
This commit is contained in:
parent
2720a9ec4b
commit
f3791f1da3
1898 changed files with 54300 additions and 11481 deletions
|
@ -1,6 +1,6 @@
|
|||
migrate.source.d6_menu_link:
|
||||
migrate.source.menu_link:
|
||||
type: migrate_source_sql
|
||||
label: 'Drupal 6 menu link'
|
||||
label: 'Menu link'
|
||||
mapping:
|
||||
constants:
|
||||
type: migrate_entity_constant
|
||||
|
|
|
@ -3,7 +3,7 @@ label: Drupal 6 menu links
|
|||
migration_tags:
|
||||
- Drupal 6
|
||||
source:
|
||||
plugin: d6_menu_link
|
||||
plugin: menu_link
|
||||
constants:
|
||||
bundle: menu_link_content
|
||||
process:
|
||||
|
@ -18,9 +18,10 @@ process:
|
|||
- 0
|
||||
- attributes
|
||||
- title
|
||||
default: ''
|
||||
menu_name:
|
||||
plugin: migration
|
||||
migration: d6_menu
|
||||
migration: menu
|
||||
source: menu_name
|
||||
'link/uri':
|
||||
plugin: internal_uri
|
||||
|
@ -44,4 +45,4 @@ destination:
|
|||
plugin: entity:menu_link_content
|
||||
migration_dependencies:
|
||||
required:
|
||||
- d6_menu
|
||||
- menu
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
id: d7_menu_links
|
||||
label: Drupal 7 menu links
|
||||
migration_tags:
|
||||
- Drupal 7
|
||||
source:
|
||||
plugin: menu_link
|
||||
constants:
|
||||
bundle: menu_link_content
|
||||
process:
|
||||
id: mlid
|
||||
bundle: 'constants/bundle'
|
||||
title: link_title
|
||||
description:
|
||||
plugin: extract
|
||||
source:
|
||||
- options
|
||||
index:
|
||||
- 0
|
||||
- attributes
|
||||
- title
|
||||
default: ''
|
||||
menu_name:
|
||||
plugin: migration
|
||||
migration: menu
|
||||
source: menu_name
|
||||
'link/uri':
|
||||
plugin: internal_uri
|
||||
source:
|
||||
- link_path
|
||||
'link/options': options
|
||||
route:
|
||||
plugin: route
|
||||
source:
|
||||
- link_path
|
||||
- options
|
||||
route_name: @route/route_name
|
||||
route_parameters: @route/route_parameters
|
||||
url: @route/url
|
||||
options: @route/options
|
||||
external: external
|
||||
weight: weight
|
||||
expanded: expanded
|
||||
enabled: enabled
|
||||
parent:
|
||||
-
|
||||
plugin: skip_on_empty
|
||||
method: process
|
||||
source: plid
|
||||
-
|
||||
plugin: migration
|
||||
migration: d7_menu_links
|
||||
changed: updated
|
||||
destination:
|
||||
plugin: entity:menu_link_content
|
||||
migration_dependencies:
|
||||
required:
|
||||
- menu
|
|
@ -54,8 +54,9 @@ class MenuLinkContentAccessControlHandler extends EntityAccessControlHandler imp
|
|||
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
|
||||
switch ($operation) {
|
||||
case 'view':
|
||||
// There is no direct view.
|
||||
return AccessResult::neutral();
|
||||
// There is no direct viewing of a menu link, but still for purposes of
|
||||
// content_translation we need a generic way to check access.
|
||||
return AccessResult::allowedIfHasPermission($account, 'administer menu');
|
||||
|
||||
case 'update':
|
||||
if (!$account->hasPermission('administer menu')) {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\menu_link_content\Plugin\migrate\process\d6\InternalUri.
|
||||
*/
|
||||
|
||||
namespace Drupal\menu_link_content\Plugin\migrate\process\d6;
|
||||
|
||||
use Drupal\migrate\MigrateExecutableInterface;
|
||||
use Drupal\migrate\ProcessPluginBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Process a path into an 'internal:' URI.
|
||||
*
|
||||
* @MigrateProcessPlugin(
|
||||
* id = "internal_uri"
|
||||
* )
|
||||
*/
|
||||
class InternalUri extends ProcessPluginBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
|
||||
list($path) = $value;
|
||||
|
||||
if (parse_url($path, PHP_URL_SCHEME) === NULL) {
|
||||
return 'internal:/' . $path;
|
||||
}
|
||||
return $path;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\menu_link_content\Plugin\migrate\source\MenuLink.
|
||||
*/
|
||||
|
||||
namespace Drupal\menu_link_content\Plugin\migrate\source;
|
||||
|
||||
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
use Drupal\migrate\Row;
|
||||
|
||||
/**
|
||||
* Drupal menu link source from database.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "menu_link",
|
||||
* )
|
||||
*/
|
||||
class MenuLink extends DrupalSqlBase {
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function query() {
|
||||
return $this->select('menu_links', 'ml')
|
||||
->fields('ml')
|
||||
->condition('module', 'menu')
|
||||
->condition('customized', 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function fields() {
|
||||
return array(
|
||||
'menu_name' => t("The menu name. All links with the same menu name (such as 'navigation') are part of the same menu."),
|
||||
'mlid' => t('The menu link ID (mlid) is the integer primary key.'),
|
||||
'plid' => t('The parent link ID (plid) is the mlid of the link above in the hierarchy, or zero if the link is at the top level in its menu.'),
|
||||
'link_path' => t('The Drupal path or external path this link points to.'),
|
||||
'router_path' => t('For links corresponding to a Drupal path (external = 0), this connects the link to a {menu_router}.path for joins.'),
|
||||
'link_title' => t('The text displayed for the link, which may be modified by a title callback stored in {menu_router}.'),
|
||||
'options' => t('A serialized array of options to be passed to the url() or l() function, such as a query string or HTML attributes.'),
|
||||
'module' => t('The name of the module that generated this link.'),
|
||||
'hidden' => t('A flag for whether the link should be rendered in menus. (1 = a disabled menu item that may be shown on admin screens, -1 = a menu callback, 0 = a normal, visible link)'),
|
||||
'external' => t('A flag to indicate if the link points to a full URL starting with a protocol, like http:// (1 = external, 0 = internal).'),
|
||||
'has_children' => t('Flag indicating whether any links have this link as a parent (1 = children exist, 0 = no children).'),
|
||||
'expanded' => t('Flag for whether this link should be rendered as expanded in menus - expanded links always have their child links displayed, instead of only when the link is in the active trail (1 = expanded, 0 = not expanded)'),
|
||||
'weight' => t('Link weight among links in the same menu at the same depth.'),
|
||||
'depth' => t('The depth relative to the top level. A link with plid == 0 will have depth == 1.'),
|
||||
'customized' => t('A flag to indicate that the user has manually created or edited the link (1 = customized, 0 = not customized).'),
|
||||
'p1' => t('The first mlid in the materialized path. If N = depth, then pN must equal the mlid. If depth > 1 then p(N-1) must equal the plid. All pX where X > depth must equal zero. The columns p1 .. p9 are also called the parents.'),
|
||||
'p2' => t('The second mlid in the materialized path. See p1.'),
|
||||
'p3' => t('The third mlid in the materialized path. See p1.'),
|
||||
'p4' => t('The fourth mlid in the materialized path. See p1.'),
|
||||
'p5' => t('The fifth mlid in the materialized path. See p1.'),
|
||||
'p6' => t('The sixth mlid in the materialized path. See p1.'),
|
||||
'p7' => t('The seventh mlid in the materialized path. See p1.'),
|
||||
'p8' => t('The eighth mlid in the materialized path. See p1.'),
|
||||
'p9' => t('The ninth mlid in the materialized path. See p1.'),
|
||||
'updated' => t('Flag that indicates that this link was generated during the update from Drupal 5.'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function prepareRow(Row $row) {
|
||||
$row->setSourceProperty('options', unserialize($row->getSourceProperty('options')));
|
||||
$row->setSourceProperty('enabled', !$row->getSourceProperty('hidden'));
|
||||
|
||||
return parent::prepareRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getIds() {
|
||||
$ids['mlid']['type'] = 'integer';
|
||||
return $ids;
|
||||
}
|
||||
|
||||
}
|
|
@ -20,7 +20,7 @@ class MenuLinkContentTranslationUITest extends ContentTranslationUITestBase {
|
|||
/**
|
||||
* {inheritdoc}
|
||||
*/
|
||||
protected $defaultCacheContexts = ['languages:language_interface', 'theme', 'user.permissions', 'user.roles:authenticated'];
|
||||
protected $defaultCacheContexts = ['languages:language_interface', 'theme', 'url.path', 'url.query_args', 'user.permissions', 'user.roles:authenticated'];
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
|
|
|
@ -7,12 +7,13 @@
|
|||
|
||||
namespace Drupal\menu_link_content\Tests\Migrate\d6;
|
||||
|
||||
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||
use Drupal\migrate_drupal\Tests\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Menu link migration.
|
||||
*
|
||||
* @group menu_link_content
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateMenuLinkTest extends MigrateDrupal6TestBase {
|
||||
|
||||
|
@ -28,26 +29,17 @@ class MigrateMenuLinkTest extends MigrateDrupal6TestBase {
|
|||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installSchema('system', ['router']);
|
||||
$this->installEntitySchema('menu_link_content');
|
||||
|
||||
$menu = entity_create('menu', array('id' => 'secondary-links'));
|
||||
$menu->enforceIsNew(TRUE);
|
||||
$menu->save();
|
||||
|
||||
$this->prepareMigrations(array(
|
||||
'd6_menu' => array(
|
||||
array(array('secondary-links'), array('secondary-links')),
|
||||
),
|
||||
));
|
||||
|
||||
$this->loadDumps(['MenuLinks.php']);
|
||||
$this->executeMigration('menu');
|
||||
$this->executeMigration('d6_menu_links');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of menu links.
|
||||
*/
|
||||
public function testMenuLinks() {
|
||||
$menu_link = entity_load('menu_link_content', 138);
|
||||
$menu_link = MenuLinkContent::load(138);
|
||||
$this->assertIdentical('Test 1', $menu_link->getTitle());
|
||||
$this->assertIdentical('secondary-links', $menu_link->getMenuName());
|
||||
$this->assertIdentical('Test menu link 1', $menu_link->getDescription());
|
||||
|
@ -57,7 +49,7 @@ class MigrateMenuLinkTest extends MigrateDrupal6TestBase {
|
|||
$this->assertIdentical('internal:/user/login', $menu_link->link->uri);
|
||||
$this->assertIdentical(15, $menu_link->getWeight());
|
||||
|
||||
$menu_link = entity_load('menu_link_content', 139);
|
||||
$menu_link = MenuLinkContent::load(139);
|
||||
$this->assertIdentical('Test 2', $menu_link->getTitle());
|
||||
$this->assertIdentical('secondary-links', $menu_link->getMenuName());
|
||||
$this->assertIdentical('Test menu link 2', $menu_link->getDescription());
|
||||
|
@ -67,15 +59,26 @@ class MigrateMenuLinkTest extends MigrateDrupal6TestBase {
|
|||
$this->assertIdentical('internal:/admin', $menu_link->link->uri);
|
||||
$this->assertIdentical(12, $menu_link->getWeight());
|
||||
|
||||
$menu_link = entity_load('menu_link_content', 140);
|
||||
$menu_link = MenuLinkContent::load(140);
|
||||
$this->assertIdentical('Drupal.org', $menu_link->getTitle());
|
||||
$this->assertIdentical('secondary-links', $menu_link->getMenuName());
|
||||
$this->assertIdentical('', $menu_link->getDescription());
|
||||
$this->assertIdentical(NULL, $menu_link->getDescription());
|
||||
$this->assertIdentical(TRUE, $menu_link->isEnabled());
|
||||
$this->assertIdentical(FALSE, $menu_link->isExpanded());
|
||||
$this->assertIdentical(['attributes' => ['title' => '']], $menu_link->link->options);
|
||||
$this->assertIdentical('https://www.drupal.org', $menu_link->link->uri);
|
||||
$this->assertIdentical(0, $menu_link->getWeight());
|
||||
|
||||
// assert that missing title attributes don't stop or break migration.
|
||||
$menu_link = MenuLinkContent::load(393);
|
||||
$this->assertIdentical('Test 3', $menu_link->getTitle());
|
||||
$this->assertIdentical('secondary-links', $menu_link->getMenuName());
|
||||
$this->assertIdentical(NULL, $menu_link->getDescription());
|
||||
$this->assertIdentical(TRUE, $menu_link->isEnabled());
|
||||
$this->assertIdentical(FALSE, $menu_link->isExpanded());
|
||||
$this->assertIdentical([], $menu_link->link->options);
|
||||
$this->assertIdentical('internal:/user/login', $menu_link->link->uri);
|
||||
$this->assertIdentical(15, $menu_link->getWeight());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,103 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\menu_link_content\Tests\Migrate\d7\MigrateMenuLinkTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\menu_link_content\Tests\Migrate\d7;
|
||||
|
||||
use Drupal\Core\Database\Database;
|
||||
use Drupal\menu_link_content\Entity\MenuLinkContent;
|
||||
use Drupal\menu_link_content\MenuLinkContentInterface;
|
||||
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
|
||||
|
||||
/**
|
||||
* Menu link migration.
|
||||
*
|
||||
* @group menu_link_content
|
||||
*/
|
||||
class MigrateMenuLinkTest extends MigrateDrupal7TestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('link', 'menu_ui', 'menu_link_content');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->installSchema('system', ['router']);
|
||||
$this->installEntitySchema('menu_link_content');
|
||||
$this->executeMigration('menu');
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts various aspects of a menu link entity.
|
||||
*
|
||||
* @param string $id
|
||||
* The link ID.
|
||||
* @param string $title
|
||||
* The expected title of the link.
|
||||
* @param string $menu
|
||||
* The expected ID of the menu to which the link will belong.
|
||||
* @param string $description
|
||||
* The link's expected description.
|
||||
* @param bool $enabled
|
||||
* Whether the link is enabled.
|
||||
* @param bool $expanded
|
||||
* Whether the link is expanded
|
||||
* @param array $attributes
|
||||
* Additional attributes the link is expected to have.
|
||||
* @param string $uri
|
||||
* The expected URI of the link.
|
||||
* @param int $weight
|
||||
* The expected weight of the link.
|
||||
*/
|
||||
protected function assertEntity($id, $title, $menu, $description, $enabled, $expanded, array $attributes, $uri, $weight) {
|
||||
/** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link */
|
||||
$menu_link = MenuLinkContent::load($id);
|
||||
$this->assertTrue($menu_link instanceof MenuLinkContentInterface);
|
||||
$this->assertIdentical($title, $menu_link->getTitle());
|
||||
$this->assertIdentical($menu, $menu_link->getMenuName());
|
||||
// The migration sets the description of the link to the value of the
|
||||
// 'title' attribute. Bit strange, but there you go.
|
||||
$this->assertIdentical($description, $menu_link->getDescription());
|
||||
$this->assertIdentical($enabled, $menu_link->isEnabled());
|
||||
$this->assertIdentical($expanded, $menu_link->isExpanded());
|
||||
$this->assertIdentical($attributes, $menu_link->link->options);
|
||||
$this->assertIdentical($uri, $menu_link->link->uri);
|
||||
$this->assertIdentical($weight, $menu_link->getWeight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of menu links.
|
||||
*/
|
||||
public function testMenuLinks() {
|
||||
$this->executeMigration('d7_menu_links');
|
||||
$this->assertEntity(467, 'Google', 'menu-test-menu', 'Google', TRUE, FALSE, ['attributes' => ['title' => 'Google']], 'http://google.com', 0);
|
||||
$this->assertEntity(468, 'Yahoo', 'menu-test-menu', 'Yahoo', TRUE, FALSE, ['attributes' => ['title' => 'Yahoo']], 'http://yahoo.com', 0);
|
||||
$this->assertEntity(469, 'Bing', 'menu-test-menu', 'Bing', TRUE, FALSE, ['attributes' => ['title' => 'Bing']], 'http://bing.com', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migrating a link with an undefined title attribute.
|
||||
*/
|
||||
public function testUndefinedLinkTitle() {
|
||||
Database::getConnection('default', 'migrate')
|
||||
->update('menu_links')
|
||||
->fields(array(
|
||||
'options' => 'a:0:{}',
|
||||
))
|
||||
->condition('mlid', 467)
|
||||
->execute();
|
||||
|
||||
$this->executeMigration('d7_menu_links');
|
||||
$this->assertEntity(467, 'Google', 'menu-test-menu', NULL, TRUE, FALSE, [], 'http://google.com', 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\menu_link_content\Unit\Plugin\migrate\source\MenuLinkSourceTest.
|
||||
*/
|
||||
namespace Drupal\Tests\menu_link_content\Unit\Plugin\migrate\source;
|
||||
|
||||
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
|
||||
|
||||
/**
|
||||
* Tests menu link source plugin.
|
||||
*
|
||||
* @group menu_link_content
|
||||
*/
|
||||
class MenuLinkSourceTest extends MigrateSqlSourceTestCase {
|
||||
|
||||
const PLUGIN_CLASS = 'Drupal\menu_link_content\Plugin\migrate\source\MenuLink';
|
||||
|
||||
protected $migrationConfiguration = array(
|
||||
'id' => 'mlid',
|
||||
'source' => array(
|
||||
'plugin' => 'menu_link',
|
||||
),
|
||||
);
|
||||
|
||||
protected $expectedResults = array(
|
||||
array(
|
||||
'menu_name' => 'menu-test-menu',
|
||||
'mlid' => 138,
|
||||
'plid' => 0,
|
||||
'link_path' => 'admin',
|
||||
'router_path' => 'admin',
|
||||
'link_title' => 'Test 1',
|
||||
'options' => array('attributes' => array('title' => 'Test menu link 1')),
|
||||
'module' => 'menu',
|
||||
'hidden' => 0,
|
||||
'external' => 0,
|
||||
'has_children' => 1,
|
||||
'expanded' => 0,
|
||||
'weight' => 15,
|
||||
'depth' => 1,
|
||||
'customized' => 1,
|
||||
'p1' => '138',
|
||||
'p2' => '0',
|
||||
'p3' => '0',
|
||||
'p4' => '0',
|
||||
'p5' => '0',
|
||||
'p6' => '0',
|
||||
'p7' => '0',
|
||||
'p8' => '0',
|
||||
'p9' => '0',
|
||||
'updated' => '0',
|
||||
),
|
||||
array(
|
||||
'menu_name' => 'menu-test-menu',
|
||||
'mlid' => 139,
|
||||
'plid' => 138,
|
||||
'link_path' => 'admin/modules',
|
||||
'router_path' => 'admin/modules',
|
||||
'link_title' => 'Test 2',
|
||||
'options' => array('attributes' => array('title' => 'Test menu link 2')),
|
||||
'module' => 'menu',
|
||||
'hidden' => 0,
|
||||
'external' => 0,
|
||||
'has_children' => 0,
|
||||
'expanded' => 0,
|
||||
'weight' => 12,
|
||||
'depth' => 2,
|
||||
'customized' => 1,
|
||||
'p1' => '138',
|
||||
'p2' => '139',
|
||||
'p3' => '0',
|
||||
'p4' => '0',
|
||||
'p5' => '0',
|
||||
'p6' => '0',
|
||||
'p7' => '0',
|
||||
'p8' => '0',
|
||||
'p9' => '0',
|
||||
'updated' => '0',
|
||||
),
|
||||
);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp() {
|
||||
foreach ($this->expectedResults as $k => $row) {
|
||||
$row['options'] = serialize($row['options']);
|
||||
$this->databaseContents['menu_links'][$k] = $row;
|
||||
}
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue