Loading drupalci.yml +3 −3 Original line number Diff line number Diff line Loading @@ -5,10 +5,10 @@ build: assessment: validate_codebase: host_command: container_command: commands: # Implement a generic revision UI. See https://www.drupal.org/project/drupal/issues/2350939#comment-13699079 - sudo -u www-data curl https://www.drupal.org/files/issues/2020-06-15/2350939-96-generic-revision-ui.patch | sudo -u www-data patch -p1 --verbose # Implement a generic revision UI. See https://www.drupal.org/project/drupal/issues/2350939#comment-13095173 - cd ${SOURCE_DIR} && sudo -u www-data curl https://www.drupal.org/files/issues/2020-07-21/2350939-127.patch | sudo -u www-data patch -p1 --verbose phplint: phpcs: # phpcs will use core's specified version of Coder. Loading src/AccessControlHandler.php +13 −0 Original line number Diff line number Diff line Loading @@ -22,9 +22,22 @@ class AccessControlHandler extends EntityAccessControlHandler { return AccessResult::allowedIf($entity->isPublished()) ->orIf(AccessResult::allowedIfHasPermission($account, 'view config_revision')); } if ($operation === 'view all revisions') { return AccessResult::allowedIfHasPermission($account, 'administer config_revision'); } elseif ($operation === 'view revision') { return AccessResult::allowedIfHasPermission($account, 'administer config_revision'); } elseif ($operation === 'revert') { return AccessResult::allowedIfHasPermission($account, 'administer config_revision'); } elseif ($operation === 'delete revision') { return AccessResult::allowedIfHasPermission($account, 'administer config_revision'); } else { return parent::checkAccess($entity, $operation, $account); } } /** Loading src/Controller/VersionHistoryController.php +14 −50 Original line number Diff line number Diff line Loading @@ -4,9 +4,9 @@ declare(strict_types = 1); namespace Drupal\config_revision\Controller; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Entity\Controller\VersionHistoryController as CoreVersionHistoryController; use Drupal\Core\Entity\RevisionableInterface; use Drupal\Core\Entity\RevisionableStorageInterface; /** * Revision overview controller class. Loading @@ -16,56 +16,20 @@ class VersionHistoryController extends CoreVersionHistoryController { /** * {@inheritdoc} */ protected function revisionOverview(RevisionableInterface $entity): array { $cacheability = (new CacheableMetadata()) ->addCacheableDependency($entity); $entity_storage = $this->entityTypeManager() ->getStorage($entity->getEntityTypeId()); $header = [$this->t('Revision'), $this->t('Operations')]; $rows = []; $entity_revisions = $entity_storage->loadMultipleRevisions($this->revisionIds($entity)); foreach ($entity_revisions as $revision) { $row = []; /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */ $row[] = $this->getRevisionDescription($revision); if ($revision->isDefaultRevision()) { $row[] = [ 'data' => [ '#prefix' => '<em>', '#markup' => $this->t('Current revision'), '#suffix' => '</em>', ], ]; foreach ($row as &$current) { $current['class'] = ['revision-current']; } } else { $links = $this->getOperationLinks($revision); $row[] = [ 'data' => [ '#type' => 'operations', '#links' => $links, ], ]; protected function loadRevisions(RevisionableInterface $entity) { $entityType = $entity->getEntityType(); $entityStorage = $this->entityTypeManager()->getStorage($entity->getEntityTypeId()); assert($entityStorage instanceof RevisionableStorageInterface); $result = $entityStorage->getQuery() ->allRevisions() ->condition($entityType->getKey('id'), $entity->id()) ->sort($entityType->getKey('revision'), 'DESC') ->execute(); foreach ($entityStorage->loadMultipleRevisions(array_keys($result)) as $revision) { yield $revision; } $rows[] = $row; } $build['entity_revisions_table'] = [ '#theme' => 'table', '#rows' => $rows, '#header' => $header, ]; $cacheability->applyTo($build); return $build; } } src/Entity/ConfigRevision.php +15 −1 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ namespace Drupal\config_revision\Entity; use Drupal\Core\Entity\EditorialContentEntityBase; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; use Drupal\Core\Field\Plugin\Field\FieldType\MapItem; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslatableMarkup; Loading Loading @@ -50,6 +51,7 @@ use Drupal\user\EntityOwnerTrait; * "default" = "\Drupal\config_revision\Form\EntityForm", * "delete" = "\Drupal\Core\Entity\ContentEntityDeleteForm", * "revision-revert" = "\Drupal\config_revision\Form\RevisionRevertForm", * "revision-delete" = "\Drupal\Core\Entity\Form\RevisionDeleteForm", * }, * "storage" = "\Drupal\config_revision\Storage", * "access" = "\Drupal\config_revision\AccessControlHandler", Loading @@ -70,6 +72,7 @@ use Drupal\user\EntityOwnerTrait; * "version-history" = "/config-revision/{config_revision}/revisions", * "revision" = "/config-revision/{config_revision}/revisions/{config_revision_revision}/view", * "revision-revert-form" = "/config-revision/{config_revision}/revisions/{config_revision_revision}/revert", * "revision-delete-form" = "/config-revision/{config_revision}/revisions/{config_revision_revision}/delete", * }, * field_ui_base_route="entity.config_revision.collection" * ) Loading Loading @@ -119,7 +122,18 @@ class ConfigRevision extends EditorialContentEntityBase implements ConfigRevisio * {@inheritdoc} */ public function getConfigMap(): MapItem { return $this->config[0]; $config_map = $this->get('config')->first(); assert($config_map instanceof MapItem); return $config_map; } /** * {@inheritdoc} */ public function getConfigRevisionType(): EntityReferenceItem { $type = $this->get('type')->first(); assert($type instanceof EntityReferenceItem); return $type; } } src/Entity/ConfigRevisionInterface.php +15 −7 Original line number Diff line number Diff line Loading @@ -17,15 +17,12 @@ use Drupal\user\EntityOwnerInterface; interface ConfigRevisionInterface extends ContentEntityInterface, EntityChangedInterface, RevisionLogInterface, EntityOwnerInterface, EntityPublishedInterface { /** * Loads an config_revision by config ID. * Gets the config_revision type. * * @param string $config_id * The config ID of the entity to load. * * @return static|null * The config_revision, or NULL if there is no event with the given ID. * @return \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem * The config_revision type. */ public static function loadConfigRevisionByConfigId(string $config_id): ?ConfigRevisionInterface; public function getConfigRevisionType(); /** * Returns the config entity map. Loading @@ -35,4 +32,15 @@ interface ConfigRevisionInterface extends ContentEntityInterface, EntityChangedI */ public function getConfigMap() : MapItem; /** * Loads an config_revision by config ID. * * @param string $config_id * The config ID of the entity to load. * * @return static|null * The config_revision, or NULL if there is no event with the given ID. */ public static function loadConfigRevisionByConfigId(string $config_id): ?ConfigRevisionInterface; } Loading
drupalci.yml +3 −3 Original line number Diff line number Diff line Loading @@ -5,10 +5,10 @@ build: assessment: validate_codebase: host_command: container_command: commands: # Implement a generic revision UI. See https://www.drupal.org/project/drupal/issues/2350939#comment-13699079 - sudo -u www-data curl https://www.drupal.org/files/issues/2020-06-15/2350939-96-generic-revision-ui.patch | sudo -u www-data patch -p1 --verbose # Implement a generic revision UI. See https://www.drupal.org/project/drupal/issues/2350939#comment-13095173 - cd ${SOURCE_DIR} && sudo -u www-data curl https://www.drupal.org/files/issues/2020-07-21/2350939-127.patch | sudo -u www-data patch -p1 --verbose phplint: phpcs: # phpcs will use core's specified version of Coder. Loading
src/AccessControlHandler.php +13 −0 Original line number Diff line number Diff line Loading @@ -22,9 +22,22 @@ class AccessControlHandler extends EntityAccessControlHandler { return AccessResult::allowedIf($entity->isPublished()) ->orIf(AccessResult::allowedIfHasPermission($account, 'view config_revision')); } if ($operation === 'view all revisions') { return AccessResult::allowedIfHasPermission($account, 'administer config_revision'); } elseif ($operation === 'view revision') { return AccessResult::allowedIfHasPermission($account, 'administer config_revision'); } elseif ($operation === 'revert') { return AccessResult::allowedIfHasPermission($account, 'administer config_revision'); } elseif ($operation === 'delete revision') { return AccessResult::allowedIfHasPermission($account, 'administer config_revision'); } else { return parent::checkAccess($entity, $operation, $account); } } /** Loading
src/Controller/VersionHistoryController.php +14 −50 Original line number Diff line number Diff line Loading @@ -4,9 +4,9 @@ declare(strict_types = 1); namespace Drupal\config_revision\Controller; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Entity\Controller\VersionHistoryController as CoreVersionHistoryController; use Drupal\Core\Entity\RevisionableInterface; use Drupal\Core\Entity\RevisionableStorageInterface; /** * Revision overview controller class. Loading @@ -16,56 +16,20 @@ class VersionHistoryController extends CoreVersionHistoryController { /** * {@inheritdoc} */ protected function revisionOverview(RevisionableInterface $entity): array { $cacheability = (new CacheableMetadata()) ->addCacheableDependency($entity); $entity_storage = $this->entityTypeManager() ->getStorage($entity->getEntityTypeId()); $header = [$this->t('Revision'), $this->t('Operations')]; $rows = []; $entity_revisions = $entity_storage->loadMultipleRevisions($this->revisionIds($entity)); foreach ($entity_revisions as $revision) { $row = []; /** @var \Drupal\Core\Entity\ContentEntityInterface $revision */ $row[] = $this->getRevisionDescription($revision); if ($revision->isDefaultRevision()) { $row[] = [ 'data' => [ '#prefix' => '<em>', '#markup' => $this->t('Current revision'), '#suffix' => '</em>', ], ]; foreach ($row as &$current) { $current['class'] = ['revision-current']; } } else { $links = $this->getOperationLinks($revision); $row[] = [ 'data' => [ '#type' => 'operations', '#links' => $links, ], ]; protected function loadRevisions(RevisionableInterface $entity) { $entityType = $entity->getEntityType(); $entityStorage = $this->entityTypeManager()->getStorage($entity->getEntityTypeId()); assert($entityStorage instanceof RevisionableStorageInterface); $result = $entityStorage->getQuery() ->allRevisions() ->condition($entityType->getKey('id'), $entity->id()) ->sort($entityType->getKey('revision'), 'DESC') ->execute(); foreach ($entityStorage->loadMultipleRevisions(array_keys($result)) as $revision) { yield $revision; } $rows[] = $row; } $build['entity_revisions_table'] = [ '#theme' => 'table', '#rows' => $rows, '#header' => $header, ]; $cacheability->applyTo($build); return $build; } }
src/Entity/ConfigRevision.php +15 −1 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ namespace Drupal\config_revision\Entity; use Drupal\Core\Entity\EditorialContentEntityBase; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem; use Drupal\Core\Field\Plugin\Field\FieldType\MapItem; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\Core\StringTranslation\TranslatableMarkup; Loading Loading @@ -50,6 +51,7 @@ use Drupal\user\EntityOwnerTrait; * "default" = "\Drupal\config_revision\Form\EntityForm", * "delete" = "\Drupal\Core\Entity\ContentEntityDeleteForm", * "revision-revert" = "\Drupal\config_revision\Form\RevisionRevertForm", * "revision-delete" = "\Drupal\Core\Entity\Form\RevisionDeleteForm", * }, * "storage" = "\Drupal\config_revision\Storage", * "access" = "\Drupal\config_revision\AccessControlHandler", Loading @@ -70,6 +72,7 @@ use Drupal\user\EntityOwnerTrait; * "version-history" = "/config-revision/{config_revision}/revisions", * "revision" = "/config-revision/{config_revision}/revisions/{config_revision_revision}/view", * "revision-revert-form" = "/config-revision/{config_revision}/revisions/{config_revision_revision}/revert", * "revision-delete-form" = "/config-revision/{config_revision}/revisions/{config_revision_revision}/delete", * }, * field_ui_base_route="entity.config_revision.collection" * ) Loading Loading @@ -119,7 +122,18 @@ class ConfigRevision extends EditorialContentEntityBase implements ConfigRevisio * {@inheritdoc} */ public function getConfigMap(): MapItem { return $this->config[0]; $config_map = $this->get('config')->first(); assert($config_map instanceof MapItem); return $config_map; } /** * {@inheritdoc} */ public function getConfigRevisionType(): EntityReferenceItem { $type = $this->get('type')->first(); assert($type instanceof EntityReferenceItem); return $type; } }
src/Entity/ConfigRevisionInterface.php +15 −7 Original line number Diff line number Diff line Loading @@ -17,15 +17,12 @@ use Drupal\user\EntityOwnerInterface; interface ConfigRevisionInterface extends ContentEntityInterface, EntityChangedInterface, RevisionLogInterface, EntityOwnerInterface, EntityPublishedInterface { /** * Loads an config_revision by config ID. * Gets the config_revision type. * * @param string $config_id * The config ID of the entity to load. * * @return static|null * The config_revision, or NULL if there is no event with the given ID. * @return \Drupal\Core\Field\Plugin\Field\FieldType\EntityReferenceItem * The config_revision type. */ public static function loadConfigRevisionByConfigId(string $config_id): ?ConfigRevisionInterface; public function getConfigRevisionType(); /** * Returns the config entity map. Loading @@ -35,4 +32,15 @@ interface ConfigRevisionInterface extends ContentEntityInterface, EntityChangedI */ public function getConfigMap() : MapItem; /** * Loads an config_revision by config ID. * * @param string $config_id * The config ID of the entity to load. * * @return static|null * The config_revision, or NULL if there is no event with the given ID. */ public static function loadConfigRevisionByConfigId(string $config_id): ?ConfigRevisionInterface; }