Verified Commit 686e984d authored by Dave Long's avatar Dave Long
Browse files

task: #3573868 Remove deprecated code from Workspaces and Workspace UI modules

By: amateescu
parent e4f6bb43
Loading
Loading
Loading
Loading
Loading
+0 −60
Original line number Diff line number Diff line
@@ -43985,54 +43985,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/workspaces/src/Plugin/Validation/Constraint/EntityWorkspaceConflictConstraintValidator.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\workspaces\\\\WorkspaceAssociation\\:\\:deleteAssociations\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/workspaces/src/WorkspaceAssociation.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\workspaces\\\\WorkspaceAssociation\\:\\:initializeWorkspace\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/workspaces/src/WorkspaceAssociation.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\workspaces\\\\WorkspaceAssociation\\:\\:trackEntity\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/workspaces/src/WorkspaceAssociation.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\workspaces\\\\WorkspaceAssociation\\:\\:workspaceInsert\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/workspaces/src/WorkspaceAssociation.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\workspaces\\\\WorkspaceAssociationInterface\\:\\:deleteAssociations\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/workspaces/src/WorkspaceAssociationInterface.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\workspaces\\\\WorkspaceAssociationInterface\\:\\:initializeWorkspace\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/workspaces/src/WorkspaceAssociationInterface.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\workspaces\\\\WorkspaceAssociationInterface\\:\\:trackEntity\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/workspaces/src/WorkspaceAssociationInterface.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\workspaces\\\\WorkspaceAssociationInterface\\:\\:workspaceInsert\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/workspaces/src/WorkspaceAssociationInterface.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\workspaces\\\\WorkspaceInterface\\:\\:publish\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
@@ -44045,18 +43997,6 @@
	'count' => 1,
	'path' => __DIR__ . '/modules/workspaces/src/WorkspaceManager.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\workspaces\\\\WorkspaceManager\\:\\:purgeDeletedWorkspacesBatch\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/workspaces/src/WorkspaceManager.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\workspaces\\\\WorkspaceManagerInterface\\:\\:purgeDeletedWorkspacesBatch\\(\\) has no return type specified\\.$#',
	'identifier' => 'missingType.return',
	'count' => 1,
	'path' => __DIR__ . '/modules/workspaces/src/WorkspaceManagerInterface.php',
];
$ignoreErrors[] = [
	'message' => '#^Method Drupal\\\\workspaces\\\\WorkspaceMerger\\:\\:checkConflictsOnTarget\\(\\) should return array but return statement is missing\\.$#',
	'identifier' => 'return.missing',
+0 −109
Original line number Diff line number Diff line
<?php

namespace Drupal\workspaces;

use Drupal\Core\Entity\RevisionableInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * Provides a class for CRUD operations on workspace associations.
 *
 * @deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. Use
 *  \Drupal\workspaces\WorkspaceTracker instead.
 *
 * @see https://www.drupal.org/node/3551450
 */
class WorkspaceAssociation implements WorkspaceAssociationInterface, EventSubscriberInterface {

  public function __construct(
    protected $workspaceTracker,
  ) {
    if (!$this->workspaceTracker instanceof WorkspaceTrackerInterface) {
      $this->workspaceTracker = \Drupal::service('workspace.tracker');
    }
  }

  /**
   * {@inheritdoc}
   */
  public function trackEntity(RevisionableInterface $entity, WorkspaceInterface $workspace) {
    $this->workspaceTracker->trackEntity($workspace->id(), $workspace);
  }

  /**
   * {@inheritdoc}
   */
  public function workspaceInsert(WorkspaceInterface $workspace) {}

  /**
   * {@inheritdoc}
   */
  public function getTrackedEntities($workspace_id, $entity_type_id = NULL, $entity_ids = NULL) {
    return $this->workspaceTracker->getTrackedEntities($workspace_id, $entity_type_id, $entity_ids);
  }

  /**
   * {@inheritdoc}
   */
  public function getTrackedEntitiesForListing($workspace_id, ?int $pager_id = NULL, int|false $limit = 50): array {
    return $this->workspaceTracker->getTrackedEntitiesForListing($workspace_id, $pager_id, $limit);
  }

  /**
   * {@inheritdoc}
   */
  public function getAssociatedRevisions($workspace_id, $entity_type_id, $entity_ids = NULL) {
    return $this->workspaceTracker->getAllTrackedRevisions($workspace_id, $entity_type_id, $entity_ids);
  }

  /**
   * {@inheritdoc}
   */
  public function getAssociatedInitialRevisions(string $workspace_id, string $entity_type_id, array $entity_ids = []) {
    return $this->workspaceTracker->getTrackedInitialRevisions($workspace_id, $entity_type_id, $entity_ids);
  }

  /**
   * {@inheritdoc}
   */
  public function getEntityTrackingWorkspaceIds(RevisionableInterface $entity, bool $latest_revision = FALSE) {
    return $this->workspaceTracker->getEntityTrackingWorkspaceIds($entity, $latest_revision);
  }

  /**
   * {@inheritdoc}
   */
  public function deleteAssociations($workspace_id = NULL, $entity_type_id = NULL, $entity_ids = NULL, $revision_ids = NULL) {
    $this->workspaceTracker->deleteTrackedEntities($workspace_id, $entity_type_id, $entity_ids);
  }

  /**
   * {@inheritdoc}
   */
  public function initializeWorkspace(WorkspaceInterface $workspace) {
    $this->workspaceTracker->initializeWorkspace($workspace);
  }

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents(): array {
    return [];
  }

  /**
   * Determines the target ID field name for an entity type.
   *
   * @param string $entity_type_id
   *   The entity type ID.
   *
   * @return string
   *   The name of the workspace association target ID field.
   *
   * @internal
   */
  public static function getIdField(string $entity_type_id): string {
    return WorkspaceTracker::getIdField($entity_type_id);
  }

}
+0 −151
Original line number Diff line number Diff line
<?php

namespace Drupal\workspaces;

use Drupal\Core\Entity\RevisionableInterface;

/**
 * Defines an interface for the workspace_association service.
 *
 * @deprecated in drupal:11.3.0 and is removed from drupal:12.0.0.
 * Use \Drupal\workspaces\WorkspaceTrackerInterface instead.
 *
 * @see https://www.drupal.org/node/3551450
 */
interface WorkspaceAssociationInterface {

  /**
   * Updates or creates the association for a given entity and a workspace.
   *
   * @param \Drupal\Core\Entity\RevisionableInterface $entity
   *   The entity to update or create from.
   * @param \Drupal\workspaces\WorkspaceInterface $workspace
   *   The workspace in which the entity will be tracked.
   */
  public function trackEntity(RevisionableInterface $entity, WorkspaceInterface $workspace);

  /**
   * Responds to the creation of a new workspace entity.
   *
   * @param \Drupal\workspaces\WorkspaceInterface $workspace
   *   The workspaces that was inserted.
   */
  public function workspaceInsert(WorkspaceInterface $workspace);

  /**
   * Retrieves the entities tracked by a given workspace.
   *
   * @param string $workspace_id
   *   The ID of the workspace.
   * @param string|null $entity_type_id
   *   (optional) An entity type ID to filter the results by. Defaults to NULL.
   * @param int[]|string[]|null $entity_ids
   *   (optional) An array of entity IDs to filter the results by. Defaults to
   *   NULL.
   *
   * @return array
   *   Returns a multidimensional array where the first level keys are entity
   *   type IDs and the values are an array of entity IDs keyed by revision IDs.
   */
  public function getTrackedEntities($workspace_id, $entity_type_id = NULL, $entity_ids = NULL);

  /**
   * Retrieves a paged list of entities tracked by a given workspace.
   *
   * @param string $workspace_id
   *   The ID of the workspace.
   * @param int|null $pager_id
   *   (optional) A pager ID. Defaults to NULL.
   * @param int|false $limit
   *   (optional) An integer specifying the number of elements per page. If
   *   passed a false value (FALSE, 0, NULL), the pager is disabled. Defaults to
   *   50.
   *
   * @return array
   *   Returns a multidimensional array where the first level keys are entity
   *   type IDs and the values are an array of entity IDs keyed by revision IDs.
   */
  public function getTrackedEntitiesForListing($workspace_id, ?int $pager_id = NULL, int|false $limit = 50): array;

  /**
   * Retrieves all content revisions tracked by a given workspace.
   *
   * Since the 'workspace_association' index table only tracks the latest
   * associated revisions, this method retrieves all the tracked revisions by
   * querying the entity type's revision table directly.
   *
   * @param string $workspace_id
   *   The ID of the workspace.
   * @param string $entity_type_id
   *   An entity type ID to find revisions for.
   * @param int[]|string[]|null $entity_ids
   *   (optional) An array of entity IDs to filter the results by. Defaults to
   *   NULL.
   *
   * @return array
   *   Returns an array where the values are an array of entity IDs keyed by
   *   revision IDs.
   */
  public function getAssociatedRevisions($workspace_id, $entity_type_id, $entity_ids = NULL);

  /**
   * Retrieves all content revisions that were created in a given workspace.
   *
   * @param string $workspace_id
   *   The ID of the workspace.
   * @param string $entity_type_id
   *   An entity type ID to find revisions for.
   * @param int[]|string[] $entity_ids
   *   (optional) An array of entity IDs to filter the results by. Defaults to
   *   an empty array.
   *
   * @return array
   *   Returns an array where the values are an array of entity IDs keyed by
   *   revision IDs.
   */
  public function getAssociatedInitialRevisions(string $workspace_id, string $entity_type_id, array $entity_ids = []);

  /**
   * Gets a list of workspace IDs in which an entity is tracked.
   *
   * @param \Drupal\Core\Entity\RevisionableInterface $entity
   *   An entity object.
   * @param bool $latest_revision
   *   (optional) Whether to return only the workspaces in which the latest
   *   revision of the entity is tracked. Defaults to FALSE.
   *
   * @return string[]
   *   An array of workspace IDs where the given entity is tracked, or an empty
   *   array if it is not tracked anywhere.
   */
  public function getEntityTrackingWorkspaceIds(RevisionableInterface $entity, bool $latest_revision = FALSE);

  /**
   * Deletes all the workspace association records for the given workspace.
   *
   * @param string|null $workspace_id
   *   (optional) A workspace entity ID. Defaults to NULL.
   * @param string|null $entity_type_id
   *   (optional) The target entity type of the associations to delete. Defaults
   *   to NULL.
   * @param int[]|string[]|null $entity_ids
   *   (optional) The target entity IDs of the associations to delete. Defaults
   *   to NULL.
   * @param int[]|string[]|null $revision_ids
   *   (optional) The target entity revision IDs of the associations to delete.
   *   Defaults to NULL.
   *
   * @throws \InvalidArgumentException
   *   If neither $workspace_id nor $entity_type_id arguments were provided.
   */
  public function deleteAssociations($workspace_id = NULL, $entity_type_id = NULL, $entity_ids = NULL, $revision_ids = NULL);

  /**
   * Initializes a workspace with all the associations of its parent.
   *
   * @param \Drupal\workspaces\WorkspaceInterface $workspace
   *   The workspace to be initialized.
   */
  public function initializeWorkspace(WorkspaceInterface $workspace);

}
+5 −57
Original line number Diff line number Diff line
@@ -3,20 +3,12 @@
namespace Drupal\workspaces;

use Drupal\workspaces\Event\WorkspaceSwitchEvent;
use Drupal\workspaces\Hook\WorkspacesHooks;
use Drupal\workspaces\Negotiator\WorkspaceNegotiatorInterface;
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
use Symfony\Component\DependencyInjection\Attribute\AutowireIterator;
use Symfony\Component\DependencyInjection\Attribute\AutowireServiceClosure;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\RequestStack;

/**
 * Provides the workspace manager.
 *
 * @property iterable $negotiators
 * @property \Closure $entityTypeManager
 * @property \Closure $eventDispatcher
 */
class WorkspaceManager implements WorkspaceManagerInterface {

@@ -28,35 +20,15 @@ class WorkspaceManager implements WorkspaceManagerInterface {
   */
  protected WorkspaceInterface|false|null $activeWorkspace = NULL;

  /**
   * An array of workspace negotiator services.
   *
   * @todo Remove in drupal:12.0.0.
   */
  private array $collectedNegotiators = [];

  public function __construct(
    protected RequestStack $requestStack,
    #[AutowireIterator(tag: 'workspace_negotiator')]
    protected $negotiators,
    protected iterable $negotiators,
    #[AutowireServiceClosure('entity_type.manager')]
    protected $entityTypeManager,
    protected \Closure $entityTypeManager,
    #[AutowireServiceClosure('event_dispatcher')]
    protected $eventDispatcher,
  ) {
    if (!$negotiators instanceof \IteratorAggregate) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $negotiators argument is deprecated in drupal:11.3.0 and it will be required in drupal:12.0.0. See https://www.drupal.org/node/3532939', E_USER_DEPRECATED);
      $this->negotiators = $this->collectedNegotiators;
    }
    if (!$entityTypeManager instanceof \Closure) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $entityTypeManager argument is deprecated in drupal:11.3.0 and it will be required in drupal:12.0.0. See https://www.drupal.org/node/3532939', E_USER_DEPRECATED);
      $this->eventDispatcher = new ServiceClosureArgument(new Reference('entity_type.manager'));
    }
    if (!$eventDispatcher instanceof \Closure) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $eventDispatcher argument is deprecated in drupal:11.3.0 and it will be required in drupal:12.0.0. See https://www.drupal.org/node/3532939', E_USER_DEPRECATED);
      $this->eventDispatcher = new ServiceClosureArgument(new Reference('event_dispatcher'));
    }
  }
    protected \Closure $eventDispatcher,
  ) {}

  /**
   * {@inheritdoc}
@@ -105,9 +77,7 @@ public function getActiveWorkspace() {
  /**
   * {@inheritdoc}
   */
  public function setActiveWorkspace(WorkspaceInterface $workspace, /* bool $persist = TRUE */) {
    $persist = func_num_args() < 2 || func_get_arg(1);

  public function setActiveWorkspace(WorkspaceInterface $workspace, bool $persist = TRUE) {
    $this->doSwitchWorkspace($workspace);

    // Set the workspace on the first applicable negotiator.
@@ -211,26 +181,4 @@ public function executeOutsideWorkspace(callable $function) {
    return $result;
  }

  /**
   * {@inheritdoc}
   */
  public function purgeDeletedWorkspacesBatch() {
    @trigger_error(__METHOD__ . ' is deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. There is no replacement. See https://www.drupal.org/node/3553582', E_USER_DEPRECATED);
    \Drupal::service(WorkspacesHooks::class)->cron();
  }

  /**
   * Adds a workspace negotiator service.
   *
   * @param \Drupal\workspaces\Negotiator\WorkspaceNegotiatorInterface $negotiator
   *   The negotiator to be added.
   *
   * @todo Remove in drupal:12.0.0.
   *
   * @internal
   */
  public function addNegotiator(WorkspaceNegotiatorInterface $negotiator): void {
    $this->collectedNegotiators[] = $negotiator;
  }

}
+1 −12
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ public function getActiveWorkspace();
   *
   * @param \Drupal\workspaces\WorkspaceInterface $workspace
   *   The workspace to set as active.
   * phpcs:ignore
   * @param bool $persist
   *   (optional) Whether to persist this workspace in the first applicable
   *   negotiator. Defaults to TRUE.
@@ -38,7 +37,7 @@ public function getActiveWorkspace();
   * @throws \Drupal\workspaces\WorkspaceAccessException
   *   Thrown when the current user doesn't have access to view the workspace.
   */
  public function setActiveWorkspace(WorkspaceInterface $workspace, /* bool $persist = TRUE */);
  public function setActiveWorkspace(WorkspaceInterface $workspace, bool $persist = TRUE);

  /**
   * Unsets the active workspace.
@@ -71,14 +70,4 @@ public function executeInWorkspace($workspace_id, callable $function);
   */
  public function executeOutsideWorkspace(callable $function);

  /**
   * Deletes the revisions associated with deleted workspaces.
   *
   * @deprecated in drupal:11.3.0 and is removed from drupal:12.0.0. There is
   *   no replacement.
   *
   * @see https://www.drupal.org/node/3553582
   */
  public function purgeDeletedWorkspacesBatch();

}
Loading