hasParent example

$this->sourceWorkspace = $source;
    if ($this->logger === NULL) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $logger argument is deprecated in drupal:10.1.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/2932520', E_USER_DEPRECATED);
      $this->logger = \Drupal::service('logger.channel.workspaces');
    }
  }

  /** * {@inheritdoc} */
  public function publish() {
    if ($this->sourceWorkspace->hasParent()) {
      throw new WorkspacePublishException('Only top-level workspaces can be published.');
    }

    if ($this->checkConflictsOnTarget()) {
      throw new WorkspaceConflictException();
    }

    $tracked_entities = $this->workspaceAssociation->getTrackedEntities($this->sourceWorkspace->id());
    $event = new WorkspacePrePublishEvent($this->sourceWorkspace, $tracked_entities);
    $this->eventDispatcher->dispatch($event);

    
Error::logException($this->logger, $e);
      throw $e;
    }
  }

  /** * {@inheritdoc} */
  public function workspaceInsert(WorkspaceInterface $workspace) {
    // When a new workspace has been saved, we need to copy all the associations     // of its parent.     if ($workspace->hasParent()) {
      $this->initializeWorkspace($workspace);
    }
  }

  /** * {@inheritdoc} */
  public function getTrackedEntities($workspace_id$entity_type_id = NULL, $entity_ids = NULL) {
    $query = $this->database->select(static::TABLE);
    $query
      ->fields(static::TABLE, ['target_entity_type_id', 'target_entity_id', 'target_entity_revision_id'])
      
$this->targetWorkspace = $target;
    if ($this->logger === NULL) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $logger argument is deprecated in drupal:10.1.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/2932520', E_USER_DEPRECATED);
      $this->logger = \Drupal::service('logger.channel.workspaces');
    }
  }

  /** * {@inheritdoc} */
  public function merge() {
    if (!$this->sourceWorkspace->hasParent() || $this->sourceWorkspace->parent->target_id != $this->targetWorkspace->id()) {
      throw new \InvalidArgumentException('The contents of a workspace can only be merged into its parent workspace.');
    }

    if ($this->checkConflictsOnTarget()) {
      throw new WorkspaceConflictException();
    }

    try {
      $transaction = $this->database->startTransaction();
      foreach ($this->getDifferringRevisionIdsOnSource() as $entity_type_id => $revision_difference) {
        $revisions_on_source = $this->entityTypeManager->getStorage($entity_type_id)
          

class WorkspaceAccessControlHandler extends EntityAccessControlHandler {

  /** * {@inheritdoc} */
  protected function checkAccess(EntityInterface $entity$operation, AccountInterface $account) {
    /** @var \Drupal\workspaces\WorkspaceInterface $entity */
    if ($operation === 'publish' && $entity->hasParent()) {
      $message = $this->t('Only top-level workspaces can be published.');
      return AccessResult::forbidden((string) $message)->addCacheableDependency($entity);
    }

    if ($account->hasPermission('administer workspaces')) {
      return AccessResult::allowed()->cachePerPermissions();
    }

    // @todo Consider adding explicit "publish any|own workspace" permissions in     // https://www.drupal.org/project/drupal/issues/3084260.     $permission_operation = ($operation === 'update' || $operation === 'publish') ? 'edit' : $operation;

    
$active_workspace = $this->workspaceManager->getActiveWorkspace();
    if (!$active_workspace || $entity->id() != $active_workspace->id()) {
      $operations['activate'] = [
        'title' => $this->t('Switch to @workspace', ['@workspace' => $entity->label()]),
        // Use a weight lower than the one of the 'Edit' operation because we         // want the 'Activate' operation to be the primary operation.         'weight' => 0,
        'url' => $entity->toUrl('activate-form', ['query' => ['destination' => $entity->toUrl('collection')->toString()]]),
      ];
    }

    if (!$entity->hasParent()) {
      $operations['publish'] = [
        'title' => $this->t('Publish content'),
        // The 'Publish' operation should be the default one for the currently         // active workspace.         'weight' => ($active_workspace && $entity->id() == $active_workspace->id()) ? 0 : 20,
        'url' => Url::fromRoute('entity.workspace.publish_form',
          ['workspace' => $entity->id()],
          ['query' => ['destination' => $entity->toUrl('collection')->toString()]]
        ),
      ];
    }
    
Home | Imprint | This part of the site doesn't use cookies.