diff --git a/core/modules/workspace/src/Entity/WorkspaceInterface.php b/core/modules/workspace/src/Entity/WorkspaceInterface.php index 16a211a..2b5caad 100644 --- a/core/modules/workspace/src/Entity/WorkspaceInterface.php +++ b/core/modules/workspace/src/Entity/WorkspaceInterface.php @@ -21,8 +21,7 @@ public function getUpdateSeq(); * @param int $timestamp * The workspace creation timestamp. * - * @return \Drupal\workspace\Entity\WorkspaceInterface - * The called workspace entity. + * @return $this */ public function setCreatedTime($timestamp); diff --git a/core/modules/workspace/src/EntityAccess.php b/core/modules/workspace/src/EntityAccess.php index 4482894..ad3f8c5 100644 --- a/core/modules/workspace/src/EntityAccess.php +++ b/core/modules/workspace/src/EntityAccess.php @@ -15,6 +15,7 @@ * Service wrapper for hooks relating to entity access control. */ class EntityAccess implements ContainerInjectionInterface { + use StringTranslationTrait; /** @@ -62,7 +63,6 @@ public static function create(ContainerInterface $container) { ); } - /** * Hook bridge; * @@ -136,7 +136,7 @@ protected function bypassAccessResult(AccountInterface $account) { return AccessResult::allowedIfHasPermission($account, 'bypass_entity_access_workspace_' . $active_workspace->id()) ->orIf( AccessResult::allowedIf($active_workspace->getOwnerId() == $account->id()) - ->andIf(AccessResult::allowedIfHasPermission($account, 'bypass_entity_access_own_workspace')) + ->andIf(AccessResult::allowedIfHasPermission($account, 'bypass entity access own workspace')) ); } @@ -155,9 +155,9 @@ protected function bypassAccessResult(AccountInterface $account) { public function workspaceAccess(WorkspaceInterface $workspace, $operation, AccountInterface $account) { $operations = [ - 'view' => ['any' => 'view_any_workspace', 'own' => 'view_own_workspace'], - 'update' => ['any' => 'edit_any_workspace', 'own' => 'edit_own_workspace'], - 'delete' => ['any' => 'delete_any_workspace', 'own' => 'delete_own_workspace'], + 'view' => ['any' => 'view any workspace', 'own' => 'view own workspace'], + 'update' => ['any' => 'edit any workspace', 'own' => 'edit own workspace'], + 'delete' => ['any' => 'delete any workspace', 'own' => 'delete own workspace'], ]; // The default workspace is always viewable, no matter what. @@ -187,7 +187,7 @@ public function workspaceAccess(WorkspaceInterface $workspace, $operation, Accou * @return AccessResult */ public function workspaceCreateAccess(AccountInterface $account, array $context, $entity_bundle) { - return AccessResult::allowedIfHasPermission($account, 'create_workspace'); + return AccessResult::allowedIfHasPermission($account, 'create workspace'); } /** @@ -216,7 +216,8 @@ public function workspacePermissions() { /** * Returns a list of all workspace entities in the system. * - * @return WorkspaceInterface[] + * @return \Drupal\workspace\Entity\WorkspaceInterface[] + * An array of workspace entities, keyed by their IDs. */ protected function getAllWorkspaces() { return $this->entityTypeManager->getStorage('workspace')->loadMultiple(); diff --git a/core/modules/workspace/src/Index/SequenceIndex.php b/core/modules/workspace/src/Index/SequenceIndex.php index 4dab7fb..aaa0ed5 100644 --- a/core/modules/workspace/src/Index/SequenceIndex.php +++ b/core/modules/workspace/src/Index/SequenceIndex.php @@ -31,7 +31,6 @@ class SequenceIndex implements SequenceIndexInterface { */ protected $workspaceManager; - /** * @param \Drupal\workspace\KeyValueStore\KeyValueSortedSetFactoryInterface $sorted_set_factory * @param \Drupal\Workspace\WorkspaceManagerInterface $workspace_manager @@ -85,7 +84,8 @@ public function getLastSequenceId() { /** * @param $workspace_id - * @return \Drupal\key_value\KeyValueStore\KeyValueStoreSortedSetInterface + * + * @return \Drupal\workspace\KeyValueStore\KeyValueStoreSortedSetInterface */ protected function sortedSetStore($workspace_id = NULL) { if (!$workspace_id) { diff --git a/core/modules/workspace/src/Index/SequenceIndexInterface.php b/core/modules/workspace/src/Index/SequenceIndexInterface.php index 6055960..0c58e2f 100644 --- a/core/modules/workspace/src/Index/SequenceIndexInterface.php +++ b/core/modules/workspace/src/Index/SequenceIndexInterface.php @@ -11,12 +11,15 @@ /** * @param $id - * @return \Drupal\multiversion\Entity\Index\IndexInterface + * + * @return $this */ public function useWorkspace($id); /** * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * + * @return $this */ public function add(ContentEntityInterface $entity); diff --git a/core/modules/workspace/src/KeyValueStore/KeyValueSortedSetFactory.php b/core/modules/workspace/src/KeyValueStore/KeyValueSortedSetFactory.php index 0fd80e6..9496259 100644 --- a/core/modules/workspace/src/KeyValueStore/KeyValueSortedSetFactory.php +++ b/core/modules/workspace/src/KeyValueStore/KeyValueSortedSetFactory.php @@ -3,6 +3,7 @@ namespace Drupal\workspace\KeyValueStore; use Drupal\Core\KeyValueStore\KeyValueFactory; + /** * Defines the key/value store factory. */ diff --git a/core/modules/workspace/src/KeyValueStore/KeyValueSortedSetFactoryInterface.php b/core/modules/workspace/src/KeyValueStore/KeyValueSortedSetFactoryInterface.php index 24b6d93..d96fb55 100644 --- a/core/modules/workspace/src/KeyValueStore/KeyValueSortedSetFactoryInterface.php +++ b/core/modules/workspace/src/KeyValueStore/KeyValueSortedSetFactoryInterface.php @@ -13,7 +13,7 @@ * @param string $collection * The name of the collection holding key and value pairs. * - * @return \Drupal\Core\KeyValueStore\KeyValueStoreSortedSetInterface + * @return \Drupal\workspace\KeyValueStore\KeyValueStoreSortedSetInterface * An sorted set key/value store implementation for the given $collection. */ public function get($collection); diff --git a/core/modules/workspace/src/WorkspaceListBuilder.php b/core/modules/workspace/src/WorkspaceListBuilder.php index 0132894..02be42b 100644 --- a/core/modules/workspace/src/WorkspaceListBuilder.php +++ b/core/modules/workspace/src/WorkspaceListBuilder.php @@ -16,22 +16,13 @@ class WorkspaceListBuilder extends EntityListBuilder { /** + * The workspace manager service. + * * @var \Drupal\workspace\WorkspaceManagerInterface */ protected $workspaceManager; /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), - $container->get('workspace.manager') - ); - } - - /** * Constructs a new EntityListBuilder object. * * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type @@ -39,6 +30,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI * @param \Drupal\Core\Entity\EntityStorageInterface $storage * The entity storage class. * @param \Drupal\workspace\WorkspaceManagerInterface $workspace_manager + * The workspace manager service. */ public function __construct(EntityTypeInterface $entity_type, EntityStorageInterface $storage, WorkspaceManagerInterface $workspace_manager) { parent::__construct($entity_type, $storage); @@ -48,6 +40,17 @@ public function __construct(EntityTypeInterface $entity_type, EntityStorageInter /** * {@inheritdoc} */ + public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { + return new static( + $entity_type, + $container->get('entity.manager')->getStorage($entity_type->id()), + $container->get('workspace.manager') + ); + } + + /** + * {@inheritdoc} + */ public function buildHeader() { $header['label'] = t('Workspace'); $header['uid'] = t('Owner'); @@ -64,7 +67,8 @@ public function buildRow(EntityInterface $entity) { $row['label'] = $entity->label() . ' (' . $entity->getMachineName() . ')'; $row['owner'] = $entity->getOwner()->getDisplayname(); $active_workspace = $this->workspaceManager->getActiveWorkspace(); - $row['status'] = $active_workspace == $entity->id() ? 'Active' : 'Inactive'; + $row['status'] = $active_workspace == $entity->id() ? $this->t('Active') : $this->t('Inactive'); + return $row + parent::buildRow($entity); } @@ -75,7 +79,7 @@ public function getDefaultOperations(EntityInterface $entity) { /** @var \Drupal\workspace\Entity\WorkspaceInterface $entity */ $operations = parent::getDefaultOperations($entity); if (isset($operations['edit'])) { - $operations['edit']['query']['destination'] = $entity->url('collection'); + $operations['edit']['query']['destination'] = $entity->toUrl('collection'); } $active_workspace = $this->workspaceManager->getActiveWorkspace(); @@ -83,7 +87,7 @@ public function getDefaultOperations(EntityInterface $entity) { $operations['activate'] = [ 'title' => $this->t('Set Active'), 'weight' => 20, - 'url' => $entity->urlInfo('activate-form', ['query' => ['destination' => $entity->url('collection')]]), + 'url' => $entity->toUrl('activate-form', ['query' => ['destination' => $entity->toUrl('collection')]]), ]; } @@ -91,7 +95,7 @@ public function getDefaultOperations(EntityInterface $entity) { $operations['deployment'] = [ 'title' => $this->t('Deploy content'), 'weight' => 20, - 'url' => $entity->urlInfo('deployment-form', ['query' => ['destination' => $entity->url('collection')]]), + 'url' => $entity->toUrl('deployment-form', ['query' => ['destination' => $entity->toUrl('collection')]]), ]; } diff --git a/core/modules/workspace/src/WorkspaceManager.php b/core/modules/workspace/src/WorkspaceManager.php index 72543fd..9e6bb87 100644 --- a/core/modules/workspace/src/WorkspaceManager.php +++ b/core/modules/workspace/src/WorkspaceManager.php @@ -86,8 +86,8 @@ public function entityCanBelongToWorkspaces(EntityInterface $entity) { * {@inheritdoc} */ public function entityTypeCanBelongToWorkspaces(EntityTypeInterface $entity_type) { - if (!in_array($entity_type->id(), $this->blacklist) - &&is_a($entity_type->getClass(), EntityPublishedInterface::class, TRUE) + if (!in_array($entity_type->id(), $this->blacklist, TRUE) + && is_a($entity_type->getClass(), EntityPublishedInterface::class, TRUE) && $entity_type->isRevisionable()) { return TRUE; } diff --git a/core/modules/workspace/src/WorkspaceServiceProvider.php b/core/modules/workspace/src/WorkspaceServiceProvider.php index 97b641f..7b82aeb 100644 --- a/core/modules/workspace/src/WorkspaceServiceProvider.php +++ b/core/modules/workspace/src/WorkspaceServiceProvider.php @@ -10,6 +10,9 @@ */ class WorkspaceServiceProvider extends ServiceProviderBase { + /** + * {@inheritdoc} + */ public function alter(ContainerBuilder $container) { $renderer_config = $container->getParameter('renderer.config'); $renderer_config['required_cache_contexts'][] = 'workspace'; diff --git a/core/modules/workspace/tests/src/Functional/ReplicationTest.php b/core/modules/workspace/tests/src/Functional/ReplicationTest.php index eb3f39a..fdf9e6f 100644 --- a/core/modules/workspace/tests/src/Functional/ReplicationTest.php +++ b/core/modules/workspace/tests/src/Functional/ReplicationTest.php @@ -40,8 +40,8 @@ public function setUp() { $this->createNodeType('Test', 'test'); $permissions = [ - 'create_workspace', - 'view_any_workspace', + 'create workspace', + 'view any workspace', 'create test content', 'edit own test content', 'access administration pages', diff --git a/core/modules/workspace/tests/src/Functional/WorkspaceBypassTest.php b/core/modules/workspace/tests/src/Functional/WorkspaceBypassTest.php index 644d25d..d477f6b 100644 --- a/core/modules/workspace/tests/src/Functional/WorkspaceBypassTest.php +++ b/core/modules/workspace/tests/src/Functional/WorkspaceBypassTest.php @@ -25,9 +25,9 @@ class WorkspaceBypassTest extends BrowserTestBase { */ public function testBypassSpecificWorkspace() { $permissions = [ - 'create_workspace', - 'edit_own_workspace', - 'view_own_workspace', + 'create workspace', + 'edit own workspace', + 'view own workspace', ]; $this->createNodeType('Test', 'test'); @@ -88,10 +88,10 @@ public function testBypassSpecificWorkspace() { */ public function testBypassOwnWorkspace() { $permissions = [ - 'create_workspace', - 'edit_own_workspace', - 'view_own_workspace', - 'bypass_entity_access_own_workspace', + 'create workspace', + 'edit own workspace', + 'view own workspace', + 'bypass entity access own workspace', ]; $this->createNodeType('Test', 'test'); diff --git a/core/modules/workspace/tests/src/Functional/WorkspaceEntityTest.php b/core/modules/workspace/tests/src/Functional/WorkspaceEntityTest.php index ac788dc..09303f0 100644 --- a/core/modules/workspace/tests/src/Functional/WorkspaceEntityTest.php +++ b/core/modules/workspace/tests/src/Functional/WorkspaceEntityTest.php @@ -30,9 +30,9 @@ class WorkspaceEntityTest extends BrowserTestBase { public function testNodeEntity($initial_workspace) { $permissions = [ 'administer nodes', - 'create_workspace', - 'edit_any_workspace', - 'view_any_workspace', + 'create workspace', + 'edit any workspace', + 'view any workspace', ]; $this->createNodeType('Test', 'test'); diff --git a/core/modules/workspace/tests/src/Functional/WorkspaceIndividualPermissionsTest.php b/core/modules/workspace/tests/src/Functional/WorkspaceIndividualPermissionsTest.php index 9bf4a0c..33f692c 100644 --- a/core/modules/workspace/tests/src/Functional/WorkspaceIndividualPermissionsTest.php +++ b/core/modules/workspace/tests/src/Functional/WorkspaceIndividualPermissionsTest.php @@ -29,9 +29,9 @@ public function testEditIndividualWorkspace() { $permissions = [ 'access administration pages', 'administer site configuration', - 'create_workspace', - 'edit_own_workspace', - 'view_own_workspace', + 'create workspace', + 'edit own workspace', + 'view own workspace', ]; $editor1 = $this->drupalCreateUser($permissions); @@ -61,8 +61,8 @@ public function testViewIndividualWorkspace() { $permissions = [ 'access administration pages', 'administer site configuration', - 'create_workspace', - 'edit_own_workspace', + 'create workspace', + 'edit own workspace', ]; $editor1 = $this->drupalCreateUser($permissions); diff --git a/core/modules/workspace/tests/src/Functional/WorkspacePermissionsTest.php b/core/modules/workspace/tests/src/Functional/WorkspacePermissionsTest.php index 0438d8b..9749421 100644 --- a/core/modules/workspace/tests/src/Functional/WorkspacePermissionsTest.php +++ b/core/modules/workspace/tests/src/Functional/WorkspacePermissionsTest.php @@ -28,7 +28,7 @@ public function testCreateWorkspace() { $editor = $this->drupalCreateUser([ 'access administration pages', 'administer site configuration', - 'create_workspace', + 'create workspace', ]); // Login as a limited-access user and create a workspace. @@ -68,8 +68,8 @@ public function testEditOwnWorkspace() { $permissions = [ 'access administration pages', 'administer site configuration', - 'create_workspace', - 'edit_own_workspace', + 'create workspace', + 'edit own workspace', ]; $editor1 = $this->drupalCreateUser($permissions); @@ -120,8 +120,8 @@ public function testEditAnyWorkspace() { $permissions = [ 'access administration pages', 'administer site configuration', - 'create_workspace', - 'edit_own_workspace', + 'create workspace', + 'edit own workspace', ]; $editor1 = $this->drupalCreateUser($permissions); @@ -149,7 +149,7 @@ public function testEditAnyWorkspace() { // Now login as a different user and ensure they don't have edit access, // and vice versa. - $admin = $this->drupalCreateUser(array_merge($permissions, ['edit_any_workspace'])); + $admin = $this->drupalCreateUser(array_merge($permissions, ['edit any workspace'])); $this->drupalLogin($admin); $session = $this->getSession(); diff --git a/core/modules/workspace/tests/src/Functional/WorkspaceSwitcherTest.php b/core/modules/workspace/tests/src/Functional/WorkspaceSwitcherTest.php index 98e4e26..cc76c73 100644 --- a/core/modules/workspace/tests/src/Functional/WorkspaceSwitcherTest.php +++ b/core/modules/workspace/tests/src/Functional/WorkspaceSwitcherTest.php @@ -24,10 +24,10 @@ class WorkspaceSwitcherTest extends BrowserTestBase { */ public function testSwitchingWorkspaces() { $permissions = [ - 'create_workspace', - 'edit_own_workspace', - 'view_own_workspace', - 'bypass_entity_access_own_workspace', + 'create workspace', + 'edit own workspace', + 'view own workspace', + 'bypass entity access own workspace', ]; $this->setupWorkspaceSwitcherBlock(); diff --git a/core/modules/workspace/tests/src/Functional/WorkspaceTest.php b/core/modules/workspace/tests/src/Functional/WorkspaceTest.php index 8027c70..02a548e 100644 --- a/core/modules/workspace/tests/src/Functional/WorkspaceTest.php +++ b/core/modules/workspace/tests/src/Functional/WorkspaceTest.php @@ -18,8 +18,8 @@ public function testSpecialCharacters() { $permissions = [ 'access administration pages', 'administer site configuration', - 'create_workspace', - 'edit_own_workspace', + 'create workspace', + 'edit own workspace', ]; $editor1 = $this->drupalCreateUser($permissions); diff --git a/core/modules/workspace/tests/src/Functional/WorkspaceViewTest.php b/core/modules/workspace/tests/src/Functional/WorkspaceViewTest.php index fa9a3cc..b3aa981 100644 --- a/core/modules/workspace/tests/src/Functional/WorkspaceViewTest.php +++ b/core/modules/workspace/tests/src/Functional/WorkspaceViewTest.php @@ -24,9 +24,9 @@ public function testViewOwnWorkspace() { $permissions = [ 'access administration pages', 'administer site configuration', - 'create_workspace', - 'edit_own_workspace', - 'view_own_workspace', + 'create workspace', + 'edit own workspace', + 'view own workspace', ]; $editor1 = $this->drupalCreateUser($permissions); @@ -66,9 +66,9 @@ public function testViewAnyWorkspace() { $permissions = [ 'access administration pages', 'administer site configuration', - 'create_workspace', - 'edit_own_workspace', - 'view_any_workspace', + 'create workspace', + 'edit own workspace', + 'view any workspace', ]; $editor1 = $this->drupalCreateUser($permissions); diff --git a/core/modules/workspace/workspace.install b/core/modules/workspace/workspace.install index 1b933b3..923fb47 100644 --- a/core/modules/workspace/workspace.install +++ b/core/modules/workspace/workspace.install @@ -2,13 +2,13 @@ /** * @file - * Contains install and update functions for Workspace. + * Contains install, update and uninstall functions for the workspace module. */ use Drupal\workspace\Entity\Workspace; /** - * Implementation of hook_install(). + * Implements hook_install(). */ function workspace_install() { /** @var \Drupal\workspace\Entity\WorkspaceInterface $live */ diff --git a/core/modules/workspace/workspace.module b/core/modules/workspace/workspace.module index ec5c3fd..b38d075 100644 --- a/core/modules/workspace/workspace.module +++ b/core/modules/workspace/workspace.module @@ -121,7 +121,6 @@ function workspace_views_query_alter(ViewExecutable $view, QueryPluginBase $quer } } - /** * Implements hook_entity_load(). */ @@ -293,7 +292,7 @@ function workspace_theme($existing, $type, $theme, $path) { * Implements hook_page_bottom(). */ function workspace_page_bottom(array &$page_bottom) { - if (\Drupal::currentUser()->hasPermission('view_own_workspace') || \Drupal::currentUser()->hasPermission('view_any_workspace')) { + if (\Drupal::currentUser()->hasPermission('view own workspace') || \Drupal::currentUser()->hasPermission('view any workspace')) { /** @var \Drupal\workspace\Entity\WorkspaceInterface $active_workspace */ $active_workspace = \Drupal::service('workspace.manager') ->getActiveWorkspace(TRUE); diff --git a/core/modules/workspace/workspace.permissions.yml b/core/modules/workspace/workspace.permissions.yml index b1ee465..36a12e1 100644 --- a/core/modules/workspace/workspace.permissions.yml +++ b/core/modules/workspace/workspace.permissions.yml @@ -1,35 +1,32 @@ administer workspaces: title: Administer workspaces -create_workspace: +create workspace: title: Create a new workspace -view_own_workspace: +view own workspace: title: View own workspace -view_any_workspace: +view any workspace: title: View any workspace -edit_own_workspace: +edit own workspace: title: Edit own workspace -edit_any_workspace: +edit any workspace: title: Edit any workspace -delete_own_workspace: +delete own workspace: title: Delete own workspace -delete_any_workspace: +delete any workspace: title: Delete any workspace -bypass_entity_access_own_workspace: +bypass entity access own workspace: title: Bypass content entity access in own workspace description: Allow all Edit/Update/Delete permissions for all content entities in a workspace owned by the user. restrict access: TRUE -view_revision_trees: - title: View revision trees - update any workspace from upstream: title: Update any workspace from upstream diff --git a/core/modules/workspace/workspace.routing.yml b/core/modules/workspace/workspace.routing.yml index 9ed125a..c2b03ce 100644 --- a/core/modules/workspace/workspace.routing.yml +++ b/core/modules/workspace/workspace.routing.yml @@ -4,7 +4,7 @@ entity.workspace.collection: _title: 'Workspaces' _entity_list: 'workspace' requirements: - _permission: 'administer workspaces+edit_any_workspace' + _permission: 'administer workspaces+edit any workspace' entity.workspace.activate_form: path: '/admin/structure/workspace/{workspace}/activate'