You are here

class DefaultWorkspaceNegotiator in Workspace 8.2

Defines the default workspace negotiator.

Hierarchy

Expanded class hierarchy of DefaultWorkspaceNegotiator

1 string reference to 'DefaultWorkspaceNegotiator'
workspace.services.yml in ./workspace.services.yml
workspace.services.yml
1 service uses DefaultWorkspaceNegotiator
workspace.negotiator.default in ./workspace.services.yml
Drupal\workspace\Negotiator\DefaultWorkspaceNegotiator

File

src/Negotiator/DefaultWorkspaceNegotiator.php, line 13

Namespace

Drupal\workspace\Negotiator
View source
class DefaultWorkspaceNegotiator implements WorkspaceNegotiatorInterface {

  /**
   * The workspace storage handler.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $workspaceStorage;

  /**
   * The default workspace entity.
   *
   * @var \Drupal\workspace\WorkspaceInterface
   */
  protected $defaultWorkspace;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->workspaceStorage = $entity_type_manager
      ->getStorage('workspace');
  }

  /**
   * {@inheritdoc}
   */
  public function applies(Request $request) {
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function getActiveWorkspace(Request $request) {
    if (!$this->defaultWorkspace) {
      $default_workspace = $this->workspaceStorage
        ->create([
        'id' => WorkspaceInterface::DEFAULT_WORKSPACE,
        'label' => Unicode::ucwords(WorkspaceInterface::DEFAULT_WORKSPACE),
        'target' => '',
      ]);
      $default_workspace
        ->enforceIsNew(FALSE);
      $this->defaultWorkspace = $default_workspace;
    }
    return $this->defaultWorkspace;
  }

  /**
   * {@inheritdoc}
   */
  public function setActiveWorkspace(WorkspaceInterface $workspace) {
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DefaultWorkspaceNegotiator::$defaultWorkspace protected property The default workspace entity.
DefaultWorkspaceNegotiator::$workspaceStorage protected property The workspace storage handler.
DefaultWorkspaceNegotiator::applies public function Checks whether the negotiator applies to the current request or not. Overrides WorkspaceNegotiatorInterface::applies
DefaultWorkspaceNegotiator::getActiveWorkspace public function Gets the negotiated workspace, if any. Overrides WorkspaceNegotiatorInterface::getActiveWorkspace
DefaultWorkspaceNegotiator::setActiveWorkspace public function Sets the negotiated workspace. Overrides WorkspaceNegotiatorInterface::setActiveWorkspace
DefaultWorkspaceNegotiator::__construct public function Constructor.