Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -7,7 +7,7 @@
namespace Drupal\shortcut\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\shortcut\ShortcutSetInterface;
@ -47,7 +47,7 @@ use Drupal\shortcut\ShortcutSetInterface;
* }
* )
*/
class ShortcutSet extends ConfigEntityBase implements ShortcutSetInterface {
class ShortcutSet extends ConfigEntityBundleBase implements ShortcutSetInterface {
/**
* The machine name for the configuration entity.

View file

@ -38,7 +38,7 @@ class SetCustomize extends EntityForm {
$form['shortcuts']['links'] = array(
'#type' => 'table',
'#header' => array(t('Name'), t('Weight'), t('Operations')),
'#empty' => $this->t('No shortcuts available. <a href="@link">Add a shortcut</a>', array('@link' => $this->url('shortcut.link_add', array('shortcut_set' => $this->entity->id())))),
'#empty' => $this->t('No shortcuts available. <a href=":link">Add a shortcut</a>', array(':link' => $this->url('shortcut.link_add', array('shortcut_set' => $this->entity->id())))),
'#attributes' => array('id' => 'shortcuts'),
'#tabledrag' => array(
array(

View file

@ -187,12 +187,12 @@ class SwitchShortcutSet extends FormBase {
$replacements = array(
'%user' => $this->user->label(),
'%set_name' => $set->label(),
'@switch-url' => $this->url('<current>'),
':switch-url' => $this->url('<current>'),
);
if ($account_is_user) {
// Only administrators can create new shortcut sets, so we know they have
// access to switch back.
drupal_set_message($this->t('You are now using the new %set_name shortcut set. You can edit it from this page or <a href="@switch-url">switch back to a different one.</a>', $replacements));
drupal_set_message($this->t('You are now using the new %set_name shortcut set. You can edit it from this page or <a href=":switch-url">switch back to a different one.</a>', $replacements));
}
else {
drupal_set_message($this->t('%user is now using a new shortcut set called %set_name. You can edit it from this page.', $replacements));
@ -207,7 +207,7 @@ class SwitchShortcutSet extends FormBase {
/* @var \Drupal\shortcut\Entity\ShortcutSet $set */
$set = $this->shortcutSetStorage->load($form_state->getValue('set'));
$replacements = array(
'%user' => $this->user->label(),
'%user' => $this->user->getDisplayName(),
'%set_name' => $set->label(),
);
drupal_set_message($account_is_user ? $this->t('You are now using the %set_name shortcut set.', $replacements) : $this->t('%user is now using the %set_name shortcut set.', $replacements));

View file

@ -0,0 +1,31 @@
<?php
/**
* @file
* Contains \Drupal\shortcut\Plugin\migrate\destination\EntityShortcutSet.
*/
namespace Drupal\shortcut\Plugin\migrate\destination;
use Drupal\migrate\Row;
use Drupal\Core\Entity\EntityInterface;
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
/**
* @MigrateDestination(
* id = "entity:shortcut_set"
* )
*/
class EntityShortcutSet extends EntityConfigBase {
/**
* {@inheritdoc}
*/
protected function getEntity(Row $row, array $old_destination_id_values) {
$entity = parent::getEntity($row, $old_destination_id_values);
// Set the "syncing" flag to TRUE, to avoid duplication of default
// shortcut links
$entity->setSyncing(TRUE);
return $entity;
}
}

View file

@ -0,0 +1,101 @@
<?php
/**
* @file
* Contains \Drupal\shortcut\Plugin\migrate\destination\ShortcutSetUsers.
*/
namespace Drupal\shortcut\Plugin\migrate\destination;
use Drupal\shortcut\ShortcutSetStorageInterface;
use Drupal\user\Entity\User;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
/**
* @MigrateDestination(
* id = "shortcut_set_users"
* )
*/
class ShortcutSetUsers extends DestinationBase implements ContainerFactoryPluginInterface {
/**
* The shortcut set storage handler.
*
* @var \Drupal\shortcut\ShortcutSetStorageInterface
*/
protected $shortcutSetStorage;
/**
* Constructs an entity destination plugin.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param MigrationInterface $migration
* The migration.
* @param \Drupal\shortcut\ShortcutSetStorageInterface $shortcut_set_storage
* The shortcut_set entity storage handler.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, ShortcutSetStorageInterface $shortcut_set_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
$this->shortcutSetStorage = $shortcut_set_storage;
}
/**
* {@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,
$container->get('entity.manager')->getStorage('shortcut_set')
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return array(
'set_name' => array(
'type' => 'string',
),
'uid' => array(
'type' => 'integer',
),
);
}
/**
* {@inheritdoc}
*/
public function fields(MigrationInterface $migration = NULL) {
return [
'uid' => 'The users.uid for this set.',
'source' => 'The shortcut_set.set_name that will be displayed for this user.',
];
}
/**
* {@inheritdoc}
*/
public function import(Row $row, array $old_destination_id_values = array()) {
/** @var \Drupal\shortcut\ShortcutSetInterface $set */
$set = $this->shortcutSetStorage->load($row->getDestinationProperty('set_name'));
/** @var \Drupal\user\UserInterface $account */
$account = User::load($row->getDestinationProperty('uid'));
$this->shortcutSetStorage->assignUser($set, $account);
return array($set->id(), $account->id());
}
}

View file

@ -0,0 +1,52 @@
<?php
/**
* @file
* Contains \Drupal\shortcut\Plugin\migrate\source\d7\Shortcut.
*/
namespace Drupal\shortcut\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 shortcut links source from database.
*
* @MigrateSource(
* id = "d7_shortcut",
* source_provider = "shortcut"
* )
*/
class Shortcut extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('menu_links', 'ml')
->fields('ml', array('mlid', 'menu_name', 'link_path', 'link_title', 'weight'))
->condition('hidden', '0')
->condition('menu_name', 'shortcut-set-%', 'LIKE');
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'mlid' => $this->t("The menu.mlid primary key for this menu item (= shortcut link)."),
'menu_name' => $this->t("The menu_name (= set name) for this shortcut link."),
'link_path' => $this->t("The link for this shortcut."),
'link_title' => $this->t("The title for this shortcut."),
'weight' => $this->t("The weight for this shortcut"),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['mlid']['type'] = 'integer';
return $ids;
}
}

View file

@ -0,0 +1,46 @@
<?php
/**
* @file
* Contains \Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSet.
*/
namespace Drupal\shortcut\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 shortcut_set source from database.
*
* @MigrateSource(
* id = "d7_shortcut_set",
* source_provider = "shortcut"
* )
*/
class ShortcutSet extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('shortcut_set', 'ss')->fields('ss');
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'set_name' => $this->t("The name under which the set's links are stored."),
'title' => $this->t("The title of the set."),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['set_name']['type'] = 'string';
return $ids;
}
}

View file

@ -0,0 +1,52 @@
<?php
/**
* @file
* Contains \Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSetUsers.
*/
namespace Drupal\shortcut\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 shortcut_set_users source from database.
*
* @MigrateSource(
* id = "d7_shortcut_set_users",
* source_provider = "shortcut"
* )
*/
class ShortcutSetUsers extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('shortcut_set_users', 'ssu')->fields('ssu');
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'uid' => $this->t('The users.uid for this set.'),
'set_name' => $this->t('The shortcut_set.set_name that will be displayed for this user.'),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return array(
'set_name' => array(
'type' => 'string',
),
'uid' => array(
'type' => 'integer',
),
);
}
}

View file

@ -55,7 +55,7 @@ class ShortcutAccessControlHandler extends EntityAccessControlHandler implements
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
if ($shortcut_set = $this->shortcutSetStorage->load($entity->bundle())) {
return shortcut_set_edit_access($shortcut_set, $account);
}

View file

@ -22,7 +22,7 @@ class ShortcutSetAccessControlHandler extends EntityAccessControlHandler {
/**
* {@inheritdoc}
*/
protected function checkAccess(EntityInterface $entity, $operation, $langcode, AccountInterface $account) {
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
switch ($operation) {
case 'update':
if ($account->hasPermission('administer shortcuts')) {

View file

@ -7,13 +7,13 @@
namespace Drupal\shortcut;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\BundleEntityFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Form controller for the shortcut set entity edit forms.
*/
class ShortcutSetForm extends EntityForm {
class ShortcutSetForm extends BundleEntityFormBase {
/**
* {@inheritdoc}
@ -38,14 +38,13 @@ class ShortcutSetForm extends EntityForm {
'replace' => '-',
),
'#default_value' => $entity->id(),
'#disabled' => !$entity->isNew(),
// This id could be used for menu name.
'#maxlength' => 23,
);
$form['actions']['submit']['#value'] = t('Create new set');
return $form;
return $this->protectBundleIdElement($form);
}
/**

View file

@ -0,0 +1,77 @@
<?php
/**
* @file
* Contains \Drupal\shortcut\Tests\Migrate\d7\MigrateShortcutSetTest.
*/
namespace Drupal\shortcut\Tests\Migrate\d7;
use Drupal\shortcut\Entity\ShortcutSet;
use Drupal\shortcut\ShortcutSetInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Test shortcut_set migration to ShortcutSet entities.
*
* @group shortcut
*/
class MigrateShortcutSetTest extends MigrateDrupal7TestBase {
/**
* Modules to enable.
*
* @var array
*/
static $modules = array(
'link',
'field',
'shortcut',
'menu_link_content',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', array('router'));
$this->installEntitySchema('shortcut');
$this->installEntitySchema('menu_link_content');
$this->executeMigration('d7_shortcut_set');
$this->executeMigration('menu');
$this->executeMigration('d7_menu_links');
$this->executeMigration('d7_shortcut');
}
/**
* Test the shortcut set migration.
*/
public function testShortcutSetMigration() {
$this->assertEntity('default', 'Default', 2);
$this->assertEntity('shortcut_set_2', 'Alternative shortcut set', 2);
}
/**
* Asserts various aspects of a shortcut set entity.
*
* @param string $id
* The expected shortcut set ID.
* @param string $label
* The expected shortcut set label.
* @param int $expected_size
* The number of shortcuts expected to be in the set.
*/
protected function assertEntity($id, $label, $expected_size) {
$shortcut_set = ShortcutSet::load($id);
$this->assertTrue($shortcut_set instanceof ShortcutSetInterface);
/** @var \Drupal\shortcut\ShortcutSetInterface $shortcut_set */
$this->assertIdentical($id, $shortcut_set->id());
$this->assertIdentical($label, $shortcut_set->label());
// Check the number of shortcuts in the set.
$shortcuts = $shortcut_set->getShortcuts();
$this->assertIdentical(count($shortcuts), $expected_size);
}
}

View file

@ -0,0 +1,61 @@
<?php
/**
* @file
* Contains \Drupal\shortcut\Tests\Migrate\d7\MigrateShortcutSetUsersTest.
*/
namespace Drupal\shortcut\Tests\Migrate\d7;
use Drupal\user\Entity\User;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Test shortcut_set_users migration.
*
* @group shortcut
*/
class MigrateShortcutSetUsersTest extends MigrateDrupal7TestBase {
/**
* Modules to enable.
*
* @var array
*/
static $modules = array(
'link',
'field',
'shortcut',
'menu_link_content',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', array('router'));
$this->installEntitySchema('shortcut');
$this->installEntitySchema('menu_link_content');
$this->installSchema('shortcut', ['shortcut_set_users']);
$this->executeMigration('d7_user_role');
$this->executeMigration('d7_user');
$this->executeMigration('d7_shortcut_set');
$this->executeMigration('menu');
$this->executeMigration('d7_menu_links');
$this->executeMigration('d7_shortcut');
$this->executeMigration('d7_shortcut_set_users');
}
/**
* Test the shortcut set migration.
*/
public function testShortcutSetUsersMigration() {
// Check if migrated user has correct migrated shortcut set assigned.
$account = User::load(2);
$shortcut_set = shortcut_current_displayed_set($account);
/** @var \Drupal\shortcut\ShortcutSetInterface $shortcut_set */
$this->assertIdentical('shortcut_set_2', $shortcut_set->id());
}
}

View file

@ -0,0 +1,79 @@
<?php
/**
* @file
* Contains \Drupal\shortcut\Tests\Migrate\d7\MigrateShortcutTest.
*/
namespace Drupal\shortcut\Tests\Migrate\d7;
use Drupal\shortcut\Entity\Shortcut;
use Drupal\shortcut\ShortcutInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Test shortcut menu links migration to Shortcut entities.
*
* @group shortcut
*/
class MigrateShortcutTest extends MigrateDrupal7TestBase {
/**
* Modules to enable.
*
* @var array
*/
static $modules = array(
'link',
'field',
'shortcut',
'menu_link_content',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', array('router'));
$this->installEntitySchema('shortcut');
$this->installEntitySchema('menu_link_content');
$this->executeMigration('d7_shortcut_set');
$this->executeMigration('menu');
$this->executeMigration('d7_menu_links');
$this->executeMigration('d7_shortcut');
}
/**
* Asserts various aspects of a shortcut entity.
*
* @param int $id
* The shortcut ID.
* @param string $title
* The expected title of the shortcut.
* @param int $weight
* The expected weight of the shortcut.
* @param string $url
* The expected URL of the shortcut.
*/
protected function assertEntity($id, $title, $weight, $url) {
$shortcut = Shortcut::load($id);
$this->assertTrue($shortcut instanceof ShortcutInterface);
/** @var \Drupal\shortcut\ShortcutInterface $shortcut */
$this->assertIdentical($title, $shortcut->getTitle());
$this->assertIdentical($weight, $shortcut->getWeight());
$this->assertIdentical($url, $shortcut->getUrl()->toString());
}
/**
* Test the shortcut migration.
*/
public function testShortcutMigration() {
// Check if the 4 shortcuts were migrated correctly.
$this->assertEntity(1, 'Add content', '-20', '/node/add');
$this->assertEntity(2, 'Find content', '-19', '/admin/content');
$this->assertEntity(3, 'Help', '-49', '/admin/help');
$this->assertEntity(4, 'People', '-50', '/admin/people');
}
}

View file

@ -26,6 +26,15 @@ class ShortcutLinksTest extends ShortcutTestBase {
*/
public static $modules = array('router_test', 'views', 'block');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('page_title_block');
}
/**
* Tests that creating a shortcut works properly.
*/
@ -105,6 +114,21 @@ class ShortcutLinksTest extends ShortcutTestBase {
];
$this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $set->id() . '/add-link', $form_data, t('Save'));
$this->assertLink($title, 0, 'Shortcut link found on the page.');
// Create a new shortcut set and add a link to it.
$this->drupalLogin($this->adminUser);
$edit = array(
'label' => $this->randomMachineName(),
'id' => strtolower($this->randomMachineName()),
);
$this->drupalPostForm('admin/config/user-interface/shortcut/add-set', $edit, t('Save'));
$title = $this->randomMachineName();
$form_data = [
'title[0][value]' => $title,
'link[0][uri]' => '/admin',
];
$this->drupalPostForm('admin/config/user-interface/shortcut/manage/' . $edit['id'] . '/add-link', $form_data, t('Save'));
$this->assertResponse(200);
}
/**

View file

@ -73,7 +73,7 @@ class ShortcutSetsTest extends ShortcutTestBase {
// Test the contents of each th cell.
$expected_items = array(t('Name'), t('Weight'), t('Operations'));
foreach ($elements as $key => $element) {
$this->assertIdentical((string) $element[0], $expected_items[$key]);
$this->assertEqual((string) $element[0], $expected_items[$key]);
}
// Look for test shortcuts in the table.
@ -148,8 +148,7 @@ class ShortcutSetsTest extends ShortcutTestBase {
function testShortcutSetSwitchNoSetName() {
$edit = array('set' => 'new');
$this->drupalPostForm('user/' . $this->adminUser->id() . '/shortcuts', $edit, t('Change set'));
$this->assertRaw('1 error has been found:');
$this->assertRaw('<a href="#edit-label">Label</a>');
$this->assertText(t('The new set label is required.'));
$current_set = shortcut_current_displayed_set($this->adminUser);
$this->assertEqual($current_set->id(), $this->set->id(), 'Attempting to switch to a new shortcut set without providing a set name does not succeed.');
$this->assertFieldByXPath("//input[@name='label' and contains(concat(' ', normalize-space(@class), ' '), ' error ')]", NULL, 'The new set label field has the error class');

View file

@ -21,7 +21,7 @@ class ShortcutTranslationUITest extends ContentTranslationUITestBase {
/**
* {inheritdoc}
*/
protected $defaultCacheContexts = ['languages:language_interface', 'theme', 'user', 'url.path', 'url.query_args', 'url.site'];
protected $defaultCacheContexts = ['languages:language_interface', 'session', 'theme', 'user', 'url.path', 'url.query_args', 'url.site'];
/**
* Modules to enable.