composer update
This commit is contained in:
parent
f6abc3dce2
commit
71dfaca858
1753 changed files with 45274 additions and 14619 deletions
|
@ -70,4 +70,18 @@ class EntityTypeInfo implements ContainerInjectionInterface {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alters field plugin definitions.
|
||||
*
|
||||
* @param array[] $definitions
|
||||
* An array of field plugin definitions.
|
||||
*
|
||||
* @see hook_field_info_alter()
|
||||
*/
|
||||
public function fieldInfoAlter(&$definitions) {
|
||||
if (isset($definitions['entity_reference'])) {
|
||||
$definitions['entity_reference']['constraints']['EntityReferenceSupportedNewEntities'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\workspaces\Plugin\Validation\Constraint;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* The entity reference supported new entities constraint.
|
||||
*
|
||||
* @Constraint(
|
||||
* id = "EntityReferenceSupportedNewEntities",
|
||||
* label = @Translation("Entity Reference Supported New Entities", context = "Validation"),
|
||||
* )
|
||||
*/
|
||||
class EntityReferenceSupportedNewEntitiesConstraint extends Constraint {
|
||||
|
||||
/**
|
||||
* The default violation message.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $message = '%collection_label can only be created in the default workspace.';
|
||||
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\workspaces\Plugin\Validation\Constraint;
|
||||
|
||||
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\workspaces\WorkspaceManagerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
/**
|
||||
* Checks if new entities created for entity reference fields are supported.
|
||||
*/
|
||||
class EntityReferenceSupportedNewEntitiesConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
|
||||
|
||||
/**
|
||||
* The workspace manager.
|
||||
*
|
||||
* @var \Drupal\workspaces\WorkspaceManagerInterface
|
||||
*/
|
||||
protected $workspaceManager;
|
||||
|
||||
/**
|
||||
* The entity type manager.
|
||||
*
|
||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
|
||||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* Creates a new EntityReferenceSupportedNewEntitiesConstraintValidator instance.
|
||||
*/
|
||||
public function __construct(WorkspaceManagerInterface $workspaceManager, EntityTypeManagerInterface $entityTypeManager) {
|
||||
$this->workspaceManager = $workspaceManager;
|
||||
$this->entityTypeManager = $entityTypeManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function create(ContainerInterface $container) {
|
||||
return new static(
|
||||
$container->get('workspaces.manager'),
|
||||
$container->get('entity_type.manager')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function validate($value, Constraint $constraint) {
|
||||
if ($this->workspaceManager->getActiveWorkspace()->isDefaultWorkspace()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$target_entity_type_id = $value->getFieldDefinition()->getFieldStorageDefinition()->getSetting('target_type');
|
||||
$target_entity_type = $this->entityTypeManager->getDefinition($target_entity_type_id);
|
||||
|
||||
if ($value->hasNewEntity() && !$this->workspaceManager->isEntityTypeSupported($target_entity_type)) {
|
||||
$this->context->addViolation($constraint->message, ['%collection_label' => $target_entity_type->getCollectionLabel()]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\workspaces;
|
||||
|
||||
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
|
||||
use Drupal\Core\DependencyInjection\ClassResolverInterface;
|
||||
use Drupal\Core\Entity\EntityPublishedInterface;
|
||||
use Drupal\Core\Entity\EntityTypeInterface;
|
||||
|
@ -47,6 +48,13 @@ class WorkspaceManager implements WorkspaceManagerInterface {
|
|||
*/
|
||||
protected $entityTypeManager;
|
||||
|
||||
/**
|
||||
* The entity memory cache service.
|
||||
*
|
||||
* @var \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface
|
||||
*/
|
||||
protected $entityMemoryCache;
|
||||
|
||||
/**
|
||||
* The current user.
|
||||
*
|
||||
|
@ -96,6 +104,8 @@ class WorkspaceManager implements WorkspaceManagerInterface {
|
|||
* The request stack.
|
||||
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
|
||||
* The entity type manager.
|
||||
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $entity_memory_cache
|
||||
* The entity memory cache service.
|
||||
* @param \Drupal\Core\Session\AccountProxyInterface $current_user
|
||||
* The current user.
|
||||
* @param \Drupal\Core\State\StateInterface $state
|
||||
|
@ -107,9 +117,10 @@ class WorkspaceManager implements WorkspaceManagerInterface {
|
|||
* @param array $negotiator_ids
|
||||
* The workspace negotiator service IDs.
|
||||
*/
|
||||
public function __construct(RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, AccountProxyInterface $current_user, StateInterface $state, LoggerInterface $logger, ClassResolverInterface $class_resolver, array $negotiator_ids) {
|
||||
public function __construct(RequestStack $request_stack, EntityTypeManagerInterface $entity_type_manager, MemoryCacheInterface $entity_memory_cache, AccountProxyInterface $current_user, StateInterface $state, LoggerInterface $logger, ClassResolverInterface $class_resolver, array $negotiator_ids) {
|
||||
$this->requestStack = $request_stack;
|
||||
$this->entityTypeManager = $entity_type_manager;
|
||||
$this->entityMemoryCache = $entity_memory_cache;
|
||||
$this->currentUser = $current_user;
|
||||
$this->state = $state;
|
||||
$this->logger = $logger;
|
||||
|
@ -167,6 +178,31 @@ class WorkspaceManager implements WorkspaceManagerInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function setActiveWorkspace(WorkspaceInterface $workspace) {
|
||||
$this->doSwitchWorkspace($workspace);
|
||||
|
||||
// Set the workspace on the proper negotiator.
|
||||
$request = $this->requestStack->getCurrentRequest();
|
||||
foreach ($this->negotiatorIds as $negotiator_id) {
|
||||
$negotiator = $this->classResolver->getInstanceFromDefinition($negotiator_id);
|
||||
if ($negotiator->applies($request)) {
|
||||
$negotiator->setActiveWorkspace($workspace);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Switches the current workspace.
|
||||
*
|
||||
* @param \Drupal\workspaces\WorkspaceInterface $workspace
|
||||
* The workspace to set as active.
|
||||
*
|
||||
* @throws \Drupal\workspaces\WorkspaceAccessException
|
||||
* Thrown when the current user doesn't have access to view the workspace.
|
||||
*/
|
||||
protected function doSwitchWorkspace(WorkspaceInterface $workspace) {
|
||||
// If the current user doesn't have access to view the workspace, they
|
||||
// shouldn't be allowed to switch to it.
|
||||
if (!$workspace->access('view') && !$workspace->isDefaultWorkspace()) {
|
||||
|
@ -179,22 +215,30 @@ class WorkspaceManager implements WorkspaceManagerInterface {
|
|||
|
||||
$this->activeWorkspace = $workspace;
|
||||
|
||||
// Set the workspace on the proper negotiator.
|
||||
$request = $this->requestStack->getCurrentRequest();
|
||||
foreach ($this->negotiatorIds as $negotiator_id) {
|
||||
$negotiator = $this->classResolver->getInstanceFromDefinition($negotiator_id);
|
||||
if ($negotiator->applies($request)) {
|
||||
$negotiator->setActiveWorkspace($workspace);
|
||||
break;
|
||||
}
|
||||
// Clear the static entity cache for the supported entity types.
|
||||
$cache_tags_to_invalidate = array_map(function ($entity_type_id) {
|
||||
return 'entity.memory_cache:' . $entity_type_id;
|
||||
}, array_keys($this->getSupportedEntityTypes()));
|
||||
$this->entityMemoryCache->invalidateTags($cache_tags_to_invalidate);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function executeInWorkspace($workspace_id, callable $function) {
|
||||
/** @var \Drupal\workspaces\WorkspaceInterface $workspace */
|
||||
$workspace = $this->entityTypeManager->getStorage('workspace')->load($workspace_id);
|
||||
|
||||
if (!$workspace) {
|
||||
throw new \InvalidArgumentException('The ' . $workspace_id . ' workspace does not exist.');
|
||||
}
|
||||
|
||||
$supported_entity_types = $this->getSupportedEntityTypes();
|
||||
foreach ($supported_entity_types as $supported_entity_type) {
|
||||
$this->entityTypeManager->getStorage($supported_entity_type->id())->resetCache();
|
||||
}
|
||||
$previous_active_workspace = $this->getActiveWorkspace();
|
||||
$this->doSwitchWorkspace($workspace);
|
||||
$result = $function();
|
||||
$this->doSwitchWorkspace($previous_active_workspace);
|
||||
|
||||
return $this;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -49,6 +49,19 @@ interface WorkspaceManagerInterface {
|
|||
*/
|
||||
public function setActiveWorkspace(WorkspaceInterface $workspace);
|
||||
|
||||
/**
|
||||
* Executes the given callback function in the context of a workspace.
|
||||
*
|
||||
* @param string $workspace_id
|
||||
* The ID of a workspace.
|
||||
* @param callable $function
|
||||
* The callback to be executed.
|
||||
*
|
||||
* @return mixed
|
||||
* The callable's return value.
|
||||
*/
|
||||
public function executeInWorkspace($workspace_id, callable $function);
|
||||
|
||||
/**
|
||||
* Determines whether runtime entity operations should be altered.
|
||||
*
|
||||
|
|
Reference in a new issue