Skip to content
Snippets Groups Projects
Commit 9a1a9ed2 authored by catch's avatar catch
Browse files

Issue #3504057 by amateescu, smustgrave: The active variant of an entity in...

Issue #3504057 by amateescu, smustgrave: The active variant of an entity in the Live workspace should be the default revision
parent 8f924c8d
No related branches found
No related tags found
3 merge requests!11197Issue #3506427 by eduardo morales alberti: Remove responsive_image.ajax from hook,!2964Issue #2865710 : Dependencies from only one instance of a widget are used in display modes,!10223132456: Fix issue where views instances are emptied before an ajax request is complete
Pipeline #421011 passed with warnings
Pipeline: drupal

#421032

    Pipeline: drupal

    #421021

      Pipeline: drupal

      #421015

        <?php
        namespace Drupal\workspaces;
        use Drupal\Core\Entity\EntityInterface;
        use Drupal\Core\Entity\EntityRepositoryInterface;
        /**
        * Provides workspace-specific mechanisms for retrieving entities.
        */
        class WorkspacesEntityRepository implements EntityRepositoryInterface {
        public function __construct(
        protected EntityRepositoryInterface $inner,
        protected WorkspaceManagerInterface $workspaceManager,
        ) {}
        /**
        * {@inheritdoc}
        */
        public function loadEntityByUuid($entity_type_id, $uuid) {
        return $this->inner->loadEntityByUuid($entity_type_id, $uuid);
        }
        /**
        * {@inheritdoc}
        */
        public function loadEntityByConfigTarget($entity_type_id, $target) {
        return $this->inner->loadEntityByConfigTarget($entity_type_id, $target);
        }
        /**
        * {@inheritdoc}
        */
        public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = []) {
        return $this->inner->getTranslationFromContext($entity, $langcode, $context);
        }
        /**
        * {@inheritdoc}
        */
        public function getActive($entity_type_id, $entity_id, ?array $contexts = NULL) {
        // When there's no active workspace, the active entity variant is the
        // canonical one.
        if (!$this->workspaceManager->hasActiveWorkspace()) {
        return $this->inner->getCanonical($entity_type_id, $entity_id, $contexts);
        }
        return $this->inner->getActive($entity_type_id, $entity_id, $contexts);
        }
        /**
        * {@inheritdoc}
        */
        public function getActiveMultiple($entity_type_id, array $entity_ids, ?array $contexts = NULL) {
        // When there's no active workspace, the active entity variant is the
        // canonical one.
        if (!$this->workspaceManager->hasActiveWorkspace()) {
        return $this->inner->getCanonicalMultiple($entity_type_id, $entity_ids, $contexts);
        }
        return $this->inner->getActiveMultiple($entity_type_id, $entity_ids, $contexts);
        }
        /**
        * {@inheritdoc}
        */
        public function getCanonical($entity_type_id, $entity_id, ?array $contexts = NULL) {
        return $this->inner->getCanonical($entity_type_id, $entity_id, $contexts);
        }
        /**
        * {@inheritdoc}
        */
        public function getCanonicalMultiple($entity_type_id, array $entity_ids, ?array $contexts = NULL) {
        return $this->inner->getCanonicalMultiple($entity_type_id, $entity_ids, $contexts);
        }
        }
        ......@@ -91,6 +91,11 @@ public function testGetActive(): void {
        $active = $this->entityRepository->getActive($entity_type_id, $entity->id(), $en_contexts);
        $this->assertSame($ham_revision->getLoadedRevisionId(), $active->getLoadedRevisionId());
        // Check that the active variant in Live is still the default revision.
        $this->switchToLive();
        $active = $this->entityRepository->getActive($entity_type_id, $entity->id(), $en_contexts);
        $this->assertSame($entity->getLoadedRevisionId(), $active->getLoadedRevisionId());
        $this->switchToWorkspace('cheese');
        $cheese_revision = $storage->createRevision($entity);
        $storage->save($cheese_revision);
        ......
        ......@@ -64,6 +64,12 @@ services:
        arguments: [ '@workspaces.manager', '@plugin.manager.element_info' ]
        Drupal\workspaces\WorkspacesLazyBuilders: '@workspaces.lazy_builders'
        workspaces.entity.repository:
        decorates: entity.repository
        class: Drupal\workspaces\WorkspacesEntityRepository
        arguments: ['@.inner', '@workspaces.manager']
        public: false
        workspaces.entity.query.sql:
        decorates: entity.query.sql
        class: Drupal\workspaces\EntityQuery\QueryFactory
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Please register or to comment