Commit 948fbd83 authored by Dries's avatar Dries

Issue #2036629 by amateescu: Fixed 'shortcut' entity type is very confusing...

Issue #2036629 by amateescu: Fixed 'shortcut' entity type is very confusing and should be renamed to 'shortcut_set()'.
parent 38bf424d
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\shortcut\Controller\ShortCutController.
* Contains \Drupal\shortcut\Controller\ShortcutSetController.
*/
namespace Drupal\shortcut\Controller;
......@@ -11,7 +11,7 @@
use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Routing\PathBasedGeneratorInterface;
use Drupal\shortcut\ShortcutInterface;
use Drupal\shortcut\ShortcutSetInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
......@@ -20,7 +20,7 @@
/**
* Builds the page for administering shortcut sets.
*/
class ShortcutController implements ControllerInterface {
class ShortcutSetController implements ControllerInterface {
/**
* The module handler.
......@@ -73,7 +73,7 @@ public static function create(ContainerInterface $container) {
/**
* Creates a new link in the provided shortcut set.
*
* @param \Drupal\shortcut\ShortcutInterface $shortcut
* @param \Drupal\shortcut\ShortcutSetInterface $shortcut_set
* The shortcut set to add a link to.
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
......@@ -83,7 +83,7 @@ public static function create(ContainerInterface $container) {
*
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
*/
public function addShortcutLinkInline(ShortcutInterface $shortcut, Request $request) {
public function addShortcutLinkInline(ShortcutSetInterface $shortcut_set, Request $request) {
$token = $request->query->get('token');
$link = $request->query->get('link');
if (isset($token) && drupal_valid_token($token, 'shortcut-add-link') && shortcut_valid_link($link)) {
......@@ -94,8 +94,8 @@ public function addShortcutLinkInline(ShortcutInterface $shortcut, Request $requ
'link_path' => $link,
);
$this->moduleHandler->loadInclude('shortcut', 'admin.inc');
shortcut_admin_add_link($link, $shortcut);
if ($shortcut->save() == SAVED_UPDATED) {
shortcut_admin_add_link($link, $shortcut_set);
if ($shortcut_set->save() == SAVED_UPDATED) {
drupal_set_message(t('Added a shortcut for %title.', array('%title' => $link['link_title'])));
}
else {
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\shortcut\Form\ShortcutDeleteForm.
* Contains \Drupal\shortcut\Form\ShortcutSetDeleteForm.
*/
namespace Drupal\shortcut\Form;
......@@ -10,7 +10,7 @@
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Entity\EntityControllerInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\shortcut\ShortcutStorageControllerInterface;
use Drupal\shortcut\ShortcutSetStorageControllerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Database\Connection;
use Symfony\Component\HttpFoundation\Request;
......@@ -18,7 +18,7 @@
/**
* Builds the shortcut set deletion form.
*/
class ShortcutDeleteForm extends EntityConfirmFormBase implements EntityControllerInterface {
class ShortcutSetDeleteForm extends EntityConfirmFormBase implements EntityControllerInterface {
/**
* The database connection.
......@@ -30,14 +30,14 @@ class ShortcutDeleteForm extends EntityConfirmFormBase implements EntityControll
/**
* The shortcut storage controller.
*
* @var \Drupal\shortcut\ShortcutStorageControllerInterface
* @var \Drupal\shortcut\ShortcutSetStorageControllerInterface
*/
protected $storageController;
/**
* Constructs a ShortcutDeleteForm object.
* Constructs a ShortcutSetDeleteForm object.
*/
public function __construct(ModuleHandlerInterface $module_handler, Connection $database, ShortcutStorageControllerInterface $storage_controller) {
public function __construct(ModuleHandlerInterface $module_handler, Connection $database, ShortcutSetStorageControllerInterface $storage_controller) {
parent::__construct($module_handler);
$this->database = $database;
$this->storageController = $storage_controller;
......@@ -50,7 +50,7 @@ public static function createInstance(ContainerInterface $container, $entity_typ
return new static(
$container->get('module_handler'),
$container->get('database'),
$container->get('plugin.manager.entity')->getStorageController('shortcut')
$container->get('plugin.manager.entity')->getStorageController('shortcut_set')
);
}
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\shortcut\Plugin\Core\Entity\Shortcut.
* Contains \Drupal\shortcut\Plugin\Core\Entity\ShortcutSet.
*/
namespace Drupal\shortcut\Plugin\Core\Entity;
......@@ -11,24 +11,24 @@
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\shortcut\ShortcutInterface;
use Drupal\shortcut\ShortcutSetInterface;
/**
* Defines the Shortcut configuration entity.
*
* @EntityType(
* id = "shortcut",
* id = "shortcut_set",
* label = @Translation("Shortcut set"),
* module = "shortcut",
* controllers = {
* "storage" = "Drupal\shortcut\ShortcutStorageController",
* "access" = "Drupal\shortcut\ShortcutAccessController",
* "list" = "Drupal\shortcut\ShortcutListController",
* "storage" = "Drupal\shortcut\ShortcutSetStorageController",
* "access" = "Drupal\shortcut\ShortcutSetAccessController",
* "list" = "Drupal\shortcut\ShortcutSetListController",
* "form" = {
* "default" = "Drupal\shortcut\ShortcutFormController",
* "edit" = "Drupal\shortcut\ShortcutFormController",
* "default" = "Drupal\shortcut\ShortcutSetFormController",
* "edit" = "Drupal\shortcut\ShortcutSetFormController",
* "customize" = "Drupal\shortcut\Form\SetCustomize",
* "delete" = "Drupal\shortcut\Form\ShortcutDeleteForm"
* "delete" = "Drupal\shortcut\Form\ShortcutSetDeleteForm"
* }
* },
* config_prefix = "shortcut.set",
......@@ -39,7 +39,7 @@
* }
* )
*/
class Shortcut extends ConfigEntityBase implements ShortcutInterface {
class ShortcutSet extends ConfigEntityBase implements ShortcutSetInterface {
/**
* The machine name for the configuration entity.
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\shortcut\ShortcutAccessController.
* Contains \Drupal\shortcut\ShortcutSetAccessController.
*/
namespace Drupal\shortcut;
......@@ -14,7 +14,7 @@
/**
* Defines the access controller for the shortcut entity type.
*/
class ShortcutAccessController extends EntityAccessController {
class ShortcutSetAccessController extends EntityAccessController {
/**
* {@inheritdoc}
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\shortcut\ShortcutFormController.
* Contains \Drupal\shortcut\ShortcutSetFormController.
*/
namespace Drupal\shortcut;
......@@ -12,7 +12,7 @@
/**
* Form controller for the shortcut set entity edit forms.
*/
class ShortcutFormController extends EntityFormController {
class ShortcutSetFormController extends EntityFormController {
/**
* Overrides \Drupal\Core\Entity\EntityFormController::form().
......
......@@ -2,7 +2,7 @@
/**
* @file
* Contains \Drupal\shortcut\Plugin\Core\Entity\ShortcutInterface.
* Contains \Drupal\shortcut\Plugin\Core\Entity\ShortcutSetInterface.
*/
namespace Drupal\shortcut;
......@@ -12,6 +12,6 @@
/**
* Provides an interface defining a shortcut entity.
*/
interface ShortcutInterface extends ConfigEntityInterface {
interface ShortcutSetInterface extends ConfigEntityInterface {
}
<?php
/**
* Contains \Drupal\shortcut\ShortcutListController.
* @file
* Contains \Drupal\shortcut\ShortcutSetListController.
*/
namespace Drupal\shortcut;
......@@ -12,7 +13,7 @@
/**
* Provides a listing of shortcut sets.
*/
class ShortcutListController extends ConfigEntityListController {
class ShortcutSetListController extends ConfigEntityListController {
/**
* Overrides \Drupal\Core\Entity\EntityListController::buildHeader().
......
......@@ -2,18 +2,18 @@
/**
* @file
* Contains \Drupal\shortcut\ShortcutStorageController.
* Contains \Drupal\shortcut\ShortcutSetStorageController.
*/
namespace Drupal\shortcut;
use Drupal\Core\Config\Entity\ConfigStorageController;
use Drupal\shortcut\Plugin\Core\Entity\Shortcut;
use Drupal\shortcut\ShortcutSetInterface;
/**
* Defines a storage controller for shortcut entities.
*/
class ShortcutStorageController extends ConfigStorageController implements ShortcutStorageControllerInterface {
class ShortcutSetStorageController extends ConfigStorageController implements ShortcutSetStorageControllerInterface {
/**
* Overrides \Drupal\config\ConfigStorageController::attachLoad().
......@@ -32,7 +32,7 @@ protected function attachLoad(&$queried_entities, $revision_id = FALSE) {
/**
* {@inheritdoc}
*/
public function deleteAssignedShortcutSets(Shortcut $entity) {
public function deleteAssignedShortcutSets(ShortcutSetInterface $entity) {
// First, delete any user assignments for this set, so that each of these
// users will go back to using whatever default set applies.
db_delete('shortcut_set_users')
......@@ -43,7 +43,7 @@ public function deleteAssignedShortcutSets(Shortcut $entity) {
/**
* {@inheritdoc}
*/
public function assignUser($shortcut_set, $account) {
public function assignUser(ShortcutSetInterface $shortcut_set, $account) {
db_merge('shortcut_set_users')
->key(array('uid' => $account->id()))
->fields(array('set_name' => $shortcut_set->id()))
......@@ -74,7 +74,7 @@ public function getAssignedToUser($account) {
/**
* {@inheritdoc}
*/
public function countAssignedUsers(Shortcut $shortcut) {
return db_query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE set_name = :name', array(':name' => $shortcut->id()))->fetchField();
public function countAssignedUsers(ShortcutSetInterface $shortcut_set) {
return db_query('SELECT COUNT(*) FROM {shortcut_set_users} WHERE set_name = :name', array(':name' => $shortcut_set->id()))->fetchField();
}
}
......@@ -2,28 +2,28 @@
/**
* @file
* Contains \Drupal\shortcut\ShortcutStorageControllerInterface.
* Contains \Drupal\shortcut\ShortcutSetStorageControllerInterface.
*/
namespace Drupal\shortcut;
use Drupal\Core\Entity\EntityStorageControllerInterface;
use Drupal\shortcut\Plugin\Core\Entity\Shortcut;
use Drupal\shortcut\ShortcutSetInterface;
/**
* Defines a common interface for shortcut entity controller classes.
*/
interface ShortcutStorageControllerInterface extends EntityStorageControllerInterface {
interface ShortcutSetStorageControllerInterface extends EntityStorageControllerInterface {
/**
* Assigns a user to a particular shortcut set.
*
* @param \Drupal\shortcut\Plugin\Core\Entity\Shortcut $shortcut_set
* @param \Drupal\shortcut\ShortcutSetInterface $shortcut_set
* An object representing the shortcut set.
* @param $account
* A user account that will be assigned to use the set.
*/
public function assignUser($shortcut_set, $account);
public function assignUser(ShortcutSetInterface $shortcut_set, $account);
/**
* Unassigns a user from any shortcut set they may have been assigned to.
......@@ -43,10 +43,10 @@ public function unassignUser($account);
/**
* Delete shortcut sets assigned to users.
*
* @param \Drupal\shortcut\Plugin\Core\Entity\Shortcut $entity
* @param \Drupal\shortcut\ShortcutSetInterface $entity
* Delete the user assigned sets belonging to this shortcut.
*/
public function deleteAssignedShortcutSets(Shortcut $entity);
public function deleteAssignedShortcutSets(ShortcutSetInterface $entity);
/**
* Get the name of the set assigned to this user.
......@@ -62,11 +62,11 @@ public function getAssignedToUser($account);
/**
* Get the number of users who have this set assigned to them.
*
* @param \Drupal\shortcut\Plugin\Core\Entity\Shortcut $shortcut
* @param \Drupal\shortcut\ShortcutSetInterface $shortcut_set
* The shortcut to count the users assigned to.
*
* @return int
* The number of users who have this set assigned to them.
*/
public function countAssignedUsers(Shortcut $shortcut);
public function countAssignedUsers(ShortcutSetInterface $shortcut_set);
}
......@@ -27,7 +27,7 @@ public static function getInfo() {
*/
function testShortcutSetAdd() {
$new_set = $this->generateShortcutSet($this->randomName());
$sets = entity_load_multiple('shortcut');
$sets = entity_load_multiple('shortcut_set');
$this->assertTrue(isset($sets[$new_set->id()]), 'Successfully created a shortcut set.');
$this->drupalGet('user/' . $this->admin_user->id() . '/shortcuts');
$this->assertText($new_set->label(), 'Generated shortcut set was listed as a choice on the user account page.');
......@@ -147,7 +147,7 @@ function testShortcutSetDelete() {
$new_set = $this->generateShortcutSet($this->randomName());
$this->drupalPost('admin/config/user-interface/shortcut/manage/' . $new_set->id() . '/delete', array(), t('Delete'));
$sets = entity_load_multiple('shortcut');
$sets = entity_load_multiple('shortcut_set');
$this->assertFalse(isset($sets[$new_set->id()]), 'Successfully deleted a shortcut set.');
}
......@@ -165,7 +165,7 @@ function testShortcutSetDeleteDefault() {
function testShortcutSetCreateWithSetName() {
$random_name = $this->randomName();
$new_set = $this->generateShortcutSet($random_name, $random_name, TRUE);
$sets = entity_load_multiple('shortcut');
$sets = entity_load_multiple('shortcut_set');
$this->assertTrue(isset($sets[$random_name]), 'Successfully created a shortcut set with a defined set name.');
$this->drupalGet('user/' . $this->admin_user->id() . '/shortcuts');
$this->assertText($new_set->label(), 'Generated shortcut set was listed as a choice on the user account page.');
......
......@@ -85,7 +85,7 @@ function setUp() {
* Creates a generic shortcut set.
*/
function generateShortcutSet($label = '', $id = NULL, $default_links = TRUE) {
$set = entity_create('shortcut', array(
$set = entity_create('shortcut_set', array(
'id' => isset($id) ? $id : strtolower($this->randomName()),
'label' => empty($label) ? $this->randomString() : $label,
));
......
......@@ -33,7 +33,7 @@ function shortcut_set_switch($form, &$form_state, $account = NULL) {
}
// Prepare the list of shortcut sets.
$sets = entity_load_multiple('shortcut');
$sets = entity_load_multiple('shortcut_set');
$current_set = shortcut_current_displayed_set($account);
$options = array();
......@@ -136,7 +136,7 @@ function shortcut_set_switch_submit($form, &$form_state) {
if ($form_state['values']['set'] == 'new') {
// Save a new shortcut set with links copied from the user's default set.
$default_set = shortcut_default_set($account);
$set = entity_create('shortcut', array(
$set = entity_create('shortcut_set', array(
'id' => $form_state['values']['id'],
'label' => $form_state['values']['label'],
'links' => $default_set->links,
......
......@@ -234,7 +234,7 @@ function shortcut_link_access($menu_link) {
function shortcut_menu_link_delete($menu_link) {
// If the deleted menu link was in a shortcut set, remove it.
if (strpos($menu_link->menu_name, 'shortcut-') === 0) {
$shortcut = entity_load('shortcut', str_replace('shortcut-', '', $menu_link->menu_name));
$shortcut = entity_load('shortcut_set', str_replace('shortcut-', '', $menu_link->menu_name));
unset($shortcut->links[$menu_link->uuid]);
$shortcut->save();
}
......@@ -254,7 +254,7 @@ function shortcut_menu_link_delete($menu_link) {
* If the shortcut set does not exist, the function returns NULL.
*/
function shortcut_set_load($id) {
return entity_load('shortcut', $id);
return entity_load('shortcut_set', $id);
}
/**
......@@ -285,7 +285,7 @@ function shortcut_set_reset_link_weights(&$shortcut_set) {
*/
function shortcut_set_assign_user($shortcut_set, $account) {
Drupal::entityManager()
->getStorageController('shortcut')
->getStorageController('shortcut_set')
->assignUser($shortcut_set, $account);
}
......@@ -304,7 +304,7 @@ function shortcut_set_assign_user($shortcut_set, $account) {
*/
function shortcut_set_unassign_user($account) {
return (bool) Drupal::entityManager()
->getStorageController('shortcut')
->getStorageController('shortcut_set')
->unassignUser($account);
}
......@@ -333,7 +333,7 @@ function shortcut_current_displayed_set($account = NULL) {
// If none was found, try to find a shortcut set that is explicitly assigned
// to this user.
$shortcut_set_name = Drupal::entityManager()
->getStorageController('shortcut')
->getStorageController('shortcut_set')
->getAssignedToUser($account);
if ($shortcut_set_name) {
$shortcut_set = shortcut_set_load($shortcut_set_name);
......@@ -389,7 +389,7 @@ function shortcut_default_set($account = NULL) {
* TRUE if a shortcut set with that title exists; FALSE otherwise.
*/
function shortcut_set_title_exists($title) {
$sets = entity_load_multiple('shortcut');
$sets = entity_load_multiple('shortcut_set');
foreach ($sets as $id => $set) {
if ($set->label == $title) {
return TRUE;
......
......@@ -6,43 +6,43 @@ shortcut_link_delete:
_access_shortcut_link_delete: 'TRUE'
shortcut_set_delete:
pattern: '/admin/config/user-interface/shortcut/manage/{shortcut}/delete'
pattern: '/admin/config/user-interface/shortcut/manage/{shortcut_set}/delete'
defaults:
_entity_form: 'shortcut.delete'
_entity_form: 'shortcut_set.delete'
requirements:
_entity_access: 'shortcut.delete'
_entity_access: 'shortcut_set.delete'
shortcut_set_admin:
pattern: '/admin/config/user-interface/shortcut'
defaults:
_entity_list: 'shortcut'
_entity_list: 'shortcut_set'
requirements:
_permission: 'administer shortcuts'
shortcut_set_add:
pattern: '/admin/config/user-interface/shortcut/add-set'
defaults:
_entity_form: 'shortcut.add'
_entity_form: 'shortcut_set.add'
requirements:
_entity_create_access: 'shortcut'
_entity_create_access: 'shortcut_set'
shortcut_set_edit:
pattern: '/admin/config/user-interface/shortcut/manage/{shortcut}/edit'
pattern: '/admin/config/user-interface/shortcut/manage/{shortcut_set}/edit'
defaults:
_entity_form: 'shortcut.edit'
_entity_form: 'shortcut_set.edit'
requirements:
_entity_access: 'shortcut.update'
_entity_access: 'shortcut_set.update'
shortcut_link_add_inline:
pattern: '/admin/config/user-interface/shortcut/manage/{shortcut}/add-link-inline'
pattern: '/admin/config/user-interface/shortcut/manage/{shortcut_set}/add-link-inline'
defaults:
_controller: 'Drupal\shortcut\Controller\ShortcutController::addShortcutLinkInline'
_controller: 'Drupal\shortcut\Controller\ShortcutSetController::addShortcutLinkInline'
requirements:
_entity_access: 'shortcut.update'
_entity_access: 'shortcut_set.update'
shortcut_set_customize:
pattern: '/admin/config/user-interface/shortcut/manage/{shortcut}'
pattern: '/admin/config/user-interface/shortcut/manage/{shortcut_set}'
defaults:
_entity_form: 'shortcut.customize'
_entity_form: 'shortcut_set.customize'
requirements:
_entity_access: 'shortcut.update'
_entity_access: 'shortcut_set.update'
......@@ -22,6 +22,9 @@ public static function getInfo() {
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz',
......@@ -39,14 +42,14 @@ public function testContactUpgrade() {
$this->assertFalse(db_table_exists('shortcut_set'), 'Table {shortcut_set} has been deleted.');
// Ensure that the Drupal 7 default set has been created.
$set = entity_load('shortcut', 'default');
$set = entity_load('shortcut_set', 'default');
$this->assertTrue($set->uuid(), 'Converted set has a UUID');
$this->assertEqual($set->label(), 'Default');
// Test that the custom set has been updated.
$set = entity_load('shortcut', 'shortcut-set-2');
$set = entity_load('shortcut_set', 'shortcut-set-2');
$this->assertTrue($set->uuid(), 'Converted set has a UUID');
$this->assertEqual($set->label(), 'Custom shortcut set');
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment