class WorkspaceAssociation

Provides a class for CRUD operations on workspace associations.

Hierarchy

Expanded class hierarchy of WorkspaceAssociation

Deprecated

in drupal:11.3.0 and is removed from drupal:12.0.0. Use \Drupal\workspaces\WorkspaceTracker instead.

See also

https://www.drupal.org/node/3551450

1 file declares its use of WorkspaceAssociation
WorkspaceAssociationTest.php in core/modules/workspaces/tests/src/Kernel/WorkspaceAssociationTest.php
1 string reference to 'WorkspaceAssociation'
workspaces.services.yml in core/modules/workspaces/workspaces.services.yml
core/modules/workspaces/workspaces.services.yml
1 service uses WorkspaceAssociation
workspaces.association in core/modules/workspaces/workspaces.services.yml
Drupal\workspaces\WorkspaceAssociation

File

core/modules/workspaces/src/WorkspaceAssociation.php, line 16

Namespace

Drupal\workspaces
View source
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);
  }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
WorkspaceAssociation::deleteAssociations public function Deletes all the workspace association records for the given workspace. Overrides WorkspaceAssociationInterface::deleteAssociations
WorkspaceAssociation::getAssociatedInitialRevisions public function Retrieves all content revisions that were created in a given workspace. Overrides WorkspaceAssociationInterface::getAssociatedInitialRevisions
WorkspaceAssociation::getAssociatedRevisions public function Retrieves all content revisions tracked by a given workspace. Overrides WorkspaceAssociationInterface::getAssociatedRevisions
WorkspaceAssociation::getEntityTrackingWorkspaceIds public function Gets a list of workspace IDs in which an entity is tracked. Overrides WorkspaceAssociationInterface::getEntityTrackingWorkspaceIds
WorkspaceAssociation::getIdField public static function Determines the target ID field name for an entity type.
WorkspaceAssociation::getSubscribedEvents public static function
WorkspaceAssociation::getTrackedEntities public function Retrieves the entities tracked by a given workspace. Overrides WorkspaceAssociationInterface::getTrackedEntities
WorkspaceAssociation::getTrackedEntitiesForListing public function Retrieves a paged list of entities tracked by a given workspace. Overrides WorkspaceAssociationInterface::getTrackedEntitiesForListing
WorkspaceAssociation::initializeWorkspace public function Initializes a workspace with all the associations of its parent. Overrides WorkspaceAssociationInterface::initializeWorkspace
WorkspaceAssociation::trackEntity public function Updates or creates the association for a given entity and a workspace. Overrides WorkspaceAssociationInterface::trackEntity
WorkspaceAssociation::workspaceInsert public function Responds to the creation of a new workspace entity. Overrides WorkspaceAssociationInterface::workspaceInsert
WorkspaceAssociation::__construct public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.