diff --git a/src/Controller/ChangesListController.php b/src/Controller/ChangesListController.php old mode 100644 new mode 100755 index bc48fd5..ac6967b --- a/src/Controller/ChangesListController.php +++ b/src/Controller/ChangesListController.php @@ -277,8 +277,8 @@ class ChangesListController extends ControllerBase { $row[] = $this->t('Changed'); } // Set the author. - if (method_exists($entity, 'getOwner')) { - $row[] = ($name = $entity->getOwner()->get('name')->value) ? $name : '* ' . $this->t('No author') . ' *'; + if (method_exists($entity, 'getOwner') && ($author = $entity->getOwner()) != NULL) { + $row[] = ($name = $author->get('name')->value) ? $name : '* ' . $this->t('No author') . ' *'; } else { $row[] = '* ' . $this->t('No author') . ' *'; diff --git a/src/Controller/WorkspaceController.php b/src/Controller/WorkspaceController.php old mode 100644 new mode 100755 index b161d3f..e4922bc --- a/src/Controller/WorkspaceController.php +++ b/src/Controller/WorkspaceController.php @@ -55,15 +55,20 @@ class WorkspaceController extends ControllerBase { */ public function addForm(WorkspaceTypeInterface $workspace_type) { $upstream_id = $this->workspaceSettings->get('upstream'); + if (!$upstream_id) { - $upstream_id = $this->getDefaultWorkspacePointer()->id(); + if(!empty($this->getDefaultWorkspacePointer())) { + $upstream_id = $this->getDefaultWorkspacePointer()->id(); + } } + $workspace = Workspace::create([ 'type' => $workspace_type->id(), 'upstream' => $upstream_id, 'pull_replication_settings' => $this->workspaceSettings->get('pull_replication_settings', ''), 'push_replication_settings' => $this->workspaceSettings->get('push_replication_settings', ''), ]); + return $this->entityFormBuilder()->getForm($workspace); } diff --git a/src/Entity/Form/WorkspaceDeleteForm.php b/src/Entity/Form/WorkspaceDeleteForm.php old mode 100644 new mode 100755 index 5e9f086..2a49e68 --- a/src/Entity/Form/WorkspaceDeleteForm.php +++ b/src/Entity/Form/WorkspaceDeleteForm.php @@ -60,7 +60,7 @@ class WorkspaceDeleteForm extends ContentEntityConfirmFormBase { return new static( $container->get('workspace.manager'), $container->getParameter('workspace.default'), - $container->get('entity.manager'), + $container->get('entity_type.manager'), $container->get('entity.repository'), $container->get('entity_type.bundle.info'), $container->get('datetime.time') diff --git a/src/Entity/Form/WorkspaceForm.php b/src/Entity/Form/WorkspaceForm.php old mode 100644 new mode 100755 index c2ea741..8cd35b7 --- a/src/Entity/Form/WorkspaceForm.php +++ b/src/Entity/Form/WorkspaceForm.php @@ -5,12 +5,16 @@ namespace Drupal\workspace\Entity\Form; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Entity\EntityConstraintViolationListInterface; use Drupal\Core\Entity\EntityManagerInterface; +use Drupal\Core\Entity\EntityTypeBundleInfo; use Drupal\Core\Entity\EntityTypeBundleInfoInterface; +use Drupal\Core\Entity\EntityTypeManager; +use Drupal\Core\Entity\EntityRepositoryInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\Markup; use Drupal\Core\Url; use Drupal\multiversion\Workspace\ConflictTrackerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\Component\Datetime\TimeInterface; /** * Form controller for the workspace edit forms. @@ -31,19 +35,30 @@ class WorkspaceForm extends ContentEntityForm { */ protected $entity; + /** + * The time service. + * + * @var \Drupal\Component\Datetime\TimeInterface + */ + protected $time; + /** * Constructs a ContentEntityForm object. * - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager + * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository + * The entity repository service. + * @param \Drupal\Core\Entity\EntityTypeBundleInfo $entity_type_bundle_info + * The entity type bundle service. * @param ConflictTrackerInterface $conflict_tracker * The conflict tracking service. - * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info + * @param \Drupal\Component\Datetime\TimeInterface $time + * The time service. * * @todo Add TimeInterface as parameter for constructor and use the value in * parent constructor starting with Drupal 8.4.0. */ - public function __construct(EntityManagerInterface $entity_manager, ConflictTrackerInterface $conflict_tracker, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL) { - parent::__construct($entity_manager, $entity_type_bundle_info); + public function __construct(EntityRepositoryInterface $entity_repository, EntityTypeBundleInfo $entityTypeBundleInfo, ConflictTrackerInterface $conflict_tracker, TimeInterface $time) { + parent::__construct($entity_repository, $entityTypeBundleInfo, $time); $this->conflictTracker = $conflict_tracker; } @@ -52,9 +67,10 @@ class WorkspaceForm extends ContentEntityForm { */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager'), + $container->get('entity.repository'), + $container->get('entity_type.bundle.info'), $container->get('workspace.conflict_tracker'), - $container->get('entity_type.bundle.info') + $container->get('datetime.time') ); } @@ -179,7 +195,7 @@ class WorkspaceForm extends ContentEntityForm { if ($replication_status == TRUE) { // The replication succeeded, in addition to saving the workspace. - drupal_set_message($this->t('Workspace :source has been updated and changes were pushed to :target.', [ + \Drupal::messenger()->addMessage($this->t('Workspace :source has been updated and changes were pushed to :target.', [ ':source' => $workspace->label(), ':target' => $workspace->get('upstream')->entity->label(), ]), 'status'); @@ -212,11 +228,11 @@ class WorkspaceForm extends ContentEntityForm { // installed. if ($is_new) { $logger->notice('@type: added %info.', $context); - drupal_set_message($this->t('Workspace %info has been created.', $info)); + \Drupal::messenger()->addMessage($this->t('Workspace %info has been created.', $info)); } else { $logger->notice('@type: updated %info.', $context); - drupal_set_message($this->t('Workspace %info has been updated.', $info)); + \Drupal::messenger()->addMessage($this->t('Workspace %info has been updated.', $info)); } if ($workspace->id()) { @@ -226,7 +242,7 @@ class WorkspaceForm extends ContentEntityForm { $form_state->setRedirectUrl($redirect); } else { - drupal_set_message($this->t('The workspace could not be saved.'), 'error'); + \Drupal::messenger()->addMessage($this->t('The workspace could not be saved.'), 'error'); $form_state->setRebuild(); } } diff --git a/src/Entity/Form/WorkspaceTypeForm.php b/src/Entity/Form/WorkspaceTypeForm.php old mode 100644 new mode 100755 index 8074860..d1f8c44 --- a/src/Entity/Form/WorkspaceTypeForm.php +++ b/src/Entity/Form/WorkspaceTypeForm.php @@ -48,13 +48,13 @@ class WorkspaceTypeForm extends BundleEntityFormBase { switch ($status) { case SAVED_NEW: - drupal_set_message($this->t('Created the %label Workspace type.', [ + $this->messenger()->addStatus($this->t('Created the %label Workspace type.', [ '%label' => $workspace_type->label(), ])); break; default: - drupal_set_message($this->t('Saved the %label Workspace type.', [ + $this->messenger()->addStatus($this->t('Saved the %label Workspace type.', [ '%label' => $workspace_type->label(), ])); } diff --git a/src/EventSubscriber/WorkbenchModerationSubscriber.php b/src/EventSubscriber/WorkbenchModerationSubscriber.php old mode 100644 new mode 100755 index 9475220..2d3d57c --- a/src/EventSubscriber/WorkbenchModerationSubscriber.php +++ b/src/EventSubscriber/WorkbenchModerationSubscriber.php @@ -55,9 +55,9 @@ class WorkbenchModerationSubscriber implements EventSubscriberInterface { // If there is no upstream to replicate to, abort. if (!$entity->get('upstream')->entity) { - drupal_set_message(t('The :source workspace does not have an upstream to replicate to!', [ + \Drupal::messenger()->addError(t('The :source workspace does not have an upstream to replicate to!', [ ':source' => $entity->label(), - ]), 'error'); + ])); // @todo Should we revert the workspace to its previous state? diff --git a/src/Form/ConfirmClearReplicationQueueForm.php b/src/Form/ConfirmClearReplicationQueueForm.php old mode 100644 new mode 100755 index d945331..f69a0b7 --- a/src/Form/ConfirmClearReplicationQueueForm.php +++ b/src/Form/ConfirmClearReplicationQueueForm.php @@ -33,7 +33,7 @@ class ConfirmClearReplicationQueueForm extends ConfirmFormBase { */ public static function create(ContainerInterface $container) { return new static( - $container->get('entity.manager') + $container->get('entity_type.manager') ); } diff --git a/src/Form/UpdateForm.php b/src/Form/UpdateForm.php old mode 100644 new mode 100755 index ec431bd..0de2e50 --- a/src/Form/UpdateForm.php +++ b/src/Form/UpdateForm.php @@ -185,7 +185,7 @@ class UpdateForm extends ConfirmFormBase { ->getAll(); if ($conflicts) { - drupal_set_message($this->t( + $this->messenger()->addError($this->t( '%workspace has been updated with content from %upstream, but there are @count conflict(s) with the %target workspace.', [ '%upstream' => $upstream->label(), @@ -194,10 +194,10 @@ class UpdateForm extends ConfirmFormBase { '@count' => count($conflicts), '%target' => $upstream->label(), ] - ), 'error'); + )); } else { - drupal_set_message($this->t('An update of %workspace has been queued with content from %upstream.', ['%upstream' => $upstream->label(), '%workspace' => $active->label()])); + $this->messenger()->addStatus($this->t('An update of %workspace has been queued with content from %upstream.', ['%upstream' => $upstream->label(), '%workspace' => $active->label()])); if (\Drupal::moduleHandler()->moduleExists('deploy')) { $input = $form_state->getUserInput(); if (!isset($input['_drupal_ajax'])) { @@ -207,12 +207,12 @@ class UpdateForm extends ConfirmFormBase { } } else { - drupal_set_message($this->t('Error updating %workspace from %upstream.', ['%upstream' => $upstream->label(), '%workspace' => $active->label()]), 'error'); + $this->messenger()->addError($this->t('Error updating %workspace from %upstream.', ['%upstream' => $upstream->label(), '%workspace' => $active->label()])); } } catch (\Exception $e) { watchdog_exception('Workspace', $e); - drupal_set_message($e->getMessage(), 'error'); + $this->messenger()->addError($e->getMessage()); } } diff --git a/src/Form/WorkspaceActivateFormBase.php b/src/Form/WorkspaceActivateFormBase.php old mode 100644 new mode 100755 index caa5cec..8158c65 --- a/src/Form/WorkspaceActivateFormBase.php +++ b/src/Form/WorkspaceActivateFormBase.php @@ -75,7 +75,7 @@ abstract class WorkspaceActivateFormBase extends FormBase { } catch(\Exception $e) { watchdog_exception('Workspace', $e); - drupal_set_message($e->getMessage(), 'error'); + $this->messenger()->addError($e->getMessage()); } } diff --git a/src/InternalReplicator.php b/src/InternalReplicator.php old mode 100644 new mode 100755 index 1c85991..081acd3 --- a/src/InternalReplicator.php +++ b/src/InternalReplicator.php @@ -114,7 +114,7 @@ class InternalReplicator implements ReplicatorInterface { } catch (\Throwable $e) { $this->logger->error('%type: @message in %function (line %line of %file).', Error::decodeException($e)); - drupal_set_message($e->getMessage(), 'error'); + \Drupal::messenger()->addError($e->getMessage()); } // Fetch the site time. $start_time = new \DateTime(); diff --git a/src/Plugin/Block/WorkspaceBlock.php b/src/Plugin/Block/WorkspaceBlock.php old mode 100644 new mode 100755 index e2274ad..65e47e9 --- a/src/Plugin/Block/WorkspaceBlock.php +++ b/src/Plugin/Block/WorkspaceBlock.php @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\multiversion\Workspace\WorkspaceManagerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\workspace\Toolbar; /** * @Block( @@ -54,7 +55,7 @@ class WorkspaceBlock extends BlockBase implements ContainerFactoryPluginInterfac public function build() { $build = [ // @todo the block depending on the toolbar is obscure; find a better way to generate this form - '#pre_render' => ['workspace.toolbar:preRenderWorkspaceSwitcherForms'], + '#pre_render' => [Toolbar::class, 'preRenderWorkspaceSwitcherForms'], // This wil get filled in via pre-render. 'workspace_forms' => [], '#attached' => [ diff --git a/src/Plugin/EntityReferenceSelection/WorkspacePointerSelection.php b/src/Plugin/EntityReferenceSelection/WorkspacePointerSelection.php old mode 100644 new mode 100755 index 6aedb85..099a0a9 --- a/src/Plugin/EntityReferenceSelection/WorkspacePointerSelection.php +++ b/src/Plugin/EntityReferenceSelection/WorkspacePointerSelection.php @@ -51,8 +51,9 @@ class WorkspacePointerSelection extends DefaultSelection { } $options = []; - $entities = $this->entityManager->getStorage($target_type)->loadMultiple($result); + $entities = $this->entityTypeManager->getStorage($target_type)->loadMultiple($result); foreach ($entities as $entity_id => $entity) { + //var_dump($this); /** @var WorkspaceInterface $workspace */ if ($workspace = $entity->getWorkspace()) { if (!$workspace->isPublished() || $workspace->getQueuedForDelete()) { @@ -60,7 +61,7 @@ class WorkspacePointerSelection extends DefaultSelection { } } $bundle = $entity->bundle(); - $options[$bundle][$entity_id] = Html::escape($this->entityManager->getTranslationFromContext($entity)->label()); + $options[$bundle][$entity_id] = Html::escape($this->entityRepository->getTranslationFromContext($entity)->label()); } return $options; diff --git a/src/Toolbar.php b/src/Toolbar.php old mode 100644 new mode 100755 index 5facf4c..11cfc00 --- a/src/Toolbar.php +++ b/src/Toolbar.php @@ -132,7 +132,7 @@ class Toolbar { $items['workspace_switcher']['tray'] = [ '#heading' => $this->t('Switch to workspace'), - '#pre_render' => ['workspace.toolbar:preRenderWorkspaceSwitcherForms'], + '#pre_render' => '::preRenderWorkspaceSwitcherForms', // This wil get filled in via pre-render. 'workspace_forms' => [], 'create_link' => $create_link, diff --git a/src/WorkspaceListBuilder.php b/src/WorkspaceListBuilder.php old mode 100644 new mode 100755 index a0df3ce..aaafdba --- a/src/WorkspaceListBuilder.php +++ b/src/WorkspaceListBuilder.php @@ -22,7 +22,7 @@ class WorkspaceListBuilder extends EntityListBuilder { public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { return new static( $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), + $container->get('entity_type.manager')->getStorage($entity_type->id()), $container->get('workspace.manager') ); } diff --git a/tests/src/Functional/ReplicationSettingsTest.php b/tests/src/Functional/ReplicationSettingsTest.php old mode 100644 new mode 100755 index afd2260..86fc86c --- a/tests/src/Functional/ReplicationSettingsTest.php +++ b/tests/src/Functional/ReplicationSettingsTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\workspace\Functional; -use Drupal\simpletest\BlockCreationTrait; +use Drupal\Tests\block\Traits\BlockCreationTrait; use Drupal\Tests\BrowserTestBase; /** diff --git a/tests/src/Functional/ReplicatorAliasTest.php b/tests/src/Functional/ReplicatorAliasTest.php old mode 100644 new mode 100755 index dc958b7..f6eb8e8 --- a/tests/src/Functional/ReplicatorAliasTest.php +++ b/tests/src/Functional/ReplicatorAliasTest.php @@ -2,11 +2,11 @@ namespace Drupal\Tests\workspace\Functional; +use Drupal\Tests\pathauto\Functional\PathautoTestHelperTrait; use Drupal\Tests\block\Traits\BlockCreationTrait; use Drupal\replication\ReplicationTask\ReplicationTask; use Drupal\Tests\BrowserTestBase; use Drupal\taxonomy\Entity\Vocabulary; -use Drupal\Tests\pathauto\Functional\PathautoTestHelperTrait; /** * Test the workspace entity with EventSubscriber alias change. @@ -90,7 +90,7 @@ class ReplicatorAliasTest extends BrowserTestBase { $this->setupWorkspaceSwitcherBlock(); $this->entityTypeManager = \Drupal::entityTypeManager(); - $this->aliasManager = \Drupal::service('path.alias_manager'); + $this->aliasManager = \Drupal::service('path_alias.manager'); $this->pathAutoGenerator = \Drupal::service('pathauto.generator'); } diff --git a/tests/src/Functional/WorkspaceBypassTest.php b/tests/src/Functional/WorkspaceBypassTest.php old mode 100644 new mode 100755 index ad46ee9..2059961 --- a/tests/src/Functional/WorkspaceBypassTest.php +++ b/tests/src/Functional/WorkspaceBypassTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\workspace\Functional; -use Drupal\simpletest\BlockCreationTrait; +use Drupal\Tests\block\Traits\BlockCreationTrait; use Drupal\Tests\BrowserTestBase; /** diff --git a/tests/src/Functional/WorkspaceSwitcherTest.php b/tests/src/Functional/WorkspaceSwitcherTest.php old mode 100644 new mode 100755 index 42e13d2..6e7dc6e --- a/tests/src/Functional/WorkspaceSwitcherTest.php +++ b/tests/src/Functional/WorkspaceSwitcherTest.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\workspace\Functional; -use Drupal\simpletest\BlockCreationTrait; +use Drupal\Tests\block\Traits\BlockCreationTrait; use Drupal\Tests\BrowserTestBase; /** diff --git a/workspace.info.yml b/workspace.info.yml old mode 100644 new mode 100755 index ed0cba4..dde2bed --- a/workspace.info.yml +++ b/workspace.info.yml @@ -1,11 +1,11 @@ name: Workspace type: module description: Provides the ability to have multiple workspaces on a single site to facilitate things like full-site preview and content staging. -core: 8.x +core_version_requirement: ^8 || ^9 dependencies: - drupal:options - drupal:datetime - replication:replication test_dependencies: - - pathauto:pathauto + - pathauto:pathauto \ No newline at end of file diff --git a/workspace.module b/workspace.module old mode 100644 new mode 100755 index a2be16f..3f10fa9 --- a/workspace.module +++ b/workspace.module @@ -1,5 +1,6 @@ entityBaseFieldInfo($entity_type); } @@ -84,7 +85,7 @@ function workspace_workspace_insert(WorkspaceInterface $workspace) { } function workspace_pointer_allowed_values(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL, &$cacheable) { - return \Drupal\workspace\Entity\Replication::getPointerAllowedValues($definition, $entity, $cacheable); + return Replication::getPointerAllowedValues($definition, $entity, $cacheable); } /**