Pull merge.
[yaffs-website] / web / core / modules / workspaces / src / Negotiator / DefaultWorkspaceNegotiator.php
1 <?php
2
3 namespace Drupal\workspaces\Negotiator;
4
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
7 use Drupal\workspaces\WorkspaceInterface;
8 use Symfony\Component\HttpFoundation\Request;
9
10 /**
11  * Defines the default workspace negotiator.
12  */
13 class DefaultWorkspaceNegotiator implements WorkspaceNegotiatorInterface {
14
15   /**
16    * The workspace storage handler.
17    *
18    * @var \Drupal\Core\Entity\EntityStorageInterface
19    */
20   protected $workspaceStorage;
21
22   /**
23    * The default workspace entity.
24    *
25    * @var \Drupal\workspaces\WorkspaceInterface
26    */
27   protected $defaultWorkspace;
28
29   /**
30    * Constructor.
31    *
32    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
33    *   The entity type manager.
34    */
35   public function __construct(EntityTypeManagerInterface $entity_type_manager) {
36     $this->workspaceStorage = $entity_type_manager->getStorage('workspace');
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public function applies(Request $request) {
43     return TRUE;
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function getActiveWorkspace(Request $request) {
50     if (!$this->defaultWorkspace) {
51       $default_workspace = $this->workspaceStorage->create([
52         'id' => WorkspaceInterface::DEFAULT_WORKSPACE,
53         'label' => Unicode::ucwords(WorkspaceInterface::DEFAULT_WORKSPACE),
54       ]);
55       $default_workspace->enforceIsNew(FALSE);
56
57       $this->defaultWorkspace = $default_workspace;
58     }
59
60     return $this->defaultWorkspace;
61   }
62
63   /**
64    * {@inheritdoc}
65    */
66   public function setActiveWorkspace(WorkspaceInterface $workspace) {}
67
68 }