setUnpublished example

$this->installConfig(['user']);
    $this->setCurrentUser($this->createUser(['access content']));
    $view = Views::getView('test_taxonomy_name_argument');
    $view->initHandlers();

    // Enable access checking on validator.     $view->argument['name']->options['validate_options']['access'] = TRUE;
    // Allow all bundles.     $view->argument['name']->options['validate_options']['bundles'] = [];

    // A uniquely named unpublished term in an allowed bundle.     $this->terms[0]->setUnpublished()->save();
    $this->assertFalse($view->argument['name']->setArgument($this->names[0]));
    $view->argument['name']->validated_title = NULL;
    $view->argument['name']->argument_validated = NULL;

    // A name used by two terms in a single vocabulary. One is unpublished.     // We re-name the second term to match the first one.     $this->terms[1]->set('name', $this->names[0])->save();
    $this->names[1] = $this->terms[1]->label();
    $this->assertTrue($view->argument['name']->setArgument($this->names[0]));
    $this->assertEquals($this->names[0]$view->argument['name']->getTitle());
    $view->argument['name']->validated_title = NULL;
    

  }

  /** * {@inheritdoc} */
  public function execute($comment = NULL) {
    $build = $this->viewBuilder->view($comment);
    $text = $this->renderer->renderPlain($build);
    foreach ($this->configuration['keywords'] as $keyword) {
      if (str_contains($text$keyword)) {
        $comment->setUnpublished();
        $comment->save();
        break;
      }
    }
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return [
      


    // Create a "Llama" content block.     $block_content = BlockContent::create([
      'info' => 'Llama',
      'type' => 'basic',
      'body' => [
        'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
        'format' => 'plain_text',
      ],
    ])
      ->setUnpublished();
    $block_content->save();
    return $block_content;
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    return [
      'id' => [
        [
          


    // Create a "Llama" content block.     $block_content = BlockContent::create([
      'info' => 'Llama',
      'type' => 'basic',
      'body' => [
        'value' => 'The name "llama" was adopted by European settlers from native Peruvians.',
        'format' => 'plain_text',
      ],
    ])
      ->setUnpublished();
    $block_content->save();
    return $block_content;
  }

  /** * {@inheritdoc} */
  protected function getExpectedDocument() {
    $base_url = Url::fromUri('base:/jsonapi/block_content/basic/' . $this->entity->uuid())->setAbsolute();
    $self_url = clone $base_url;
    $version_identifier = 'id:' . $this->entity->getRevisionId();
    
    // because they can view the published node. Even though they can't view     // the unpublished node.     $this->drupalGet($published_node->toUrl());
    $this->assertSession()->statusCodeEquals(200);
    $this->drupalGet($unpublished_node->toUrl());
    $this->assertSession()->statusCodeEquals(403);
    $this->drupalGet($src);
    $this->assertSession()->statusCodeEquals(200);

    // When the published node is also unpublished, the image should also     // become inaccessible to anonymous users.     $published_node->setUnpublished()->save();

    $this->drupalGet($published_node->toUrl());
    $this->assertSession()->statusCodeEquals(403);
    $this->drupalGet($src);
    $this->assertSession()->statusCodeEquals(403);

    // Disallow anonymous users to view the entity, which then should also     // disallow them to view the image.     $published_node->setPublished()->save();
    Role::load(RoleInterface::ANONYMOUS_ID)
      ->revokePermission('access content')
      

  protected function setUp($import_test_views = TRUE, $modules = ['comment_test_views']): void {
    parent::setUp($import_test_views$modules);
  }

  /** * Tests that "approve comment" link exists and works as expected. */
  public function testCommentApproveLink() {
    $this->drupalLogin($this->drupalCreateUser(['administer comments']));
    // Set the comment status to unpublished.     $this->comment->setUnpublished();
    $this->comment->save();
    $this->drupalGet('/admin/moderate-comments');
    $this->assertSession()->pageTextContains($this->comment->getSubject());
    $this->assertSession()->linkExists('Approve');
    $this->clickLink('Approve');
    $this->drupalGet('/admin/moderate-comments');
    $this->assertSession()->linkNotExists('Approve');
    // Ensure that "published" column in table is marked as yes.     $this->assertSession()->elementTextContains('xpath', "//table/tbody/tr/td[3]", 'Yes');
  }

}
// When a new published entity is inserted in a non-default workspace, we     // actually want two revisions to be saved:     // - An unpublished default revision in the default ('live') workspace.     // - A published pending revision in the current workspace.     if ($entity->isNew() && $entity->isPublished()) {
      // Keep track of the publishing status in a dynamic property for       // ::entityInsert(), then unpublish the default revision.       // @todo Remove this dynamic property once we have an API for associating       // temporary data with an entity: https://www.drupal.org/node/2896474.       $entity->_initialPublished = TRUE;
      $entity->setUnpublished();
    }
  }

  /** * Responds to the creation of a new entity. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity that was just saved. * * @see hook_entity_insert() */
  
$this->assertSame($doc['data']['attributes']['data'], Json::decode((string) $response->getBody())['data']['attributes']['data']);
  }

  /** * Ensure EntityAccessDeniedHttpException cacheability is taken into account. */
  public function testLeakCacheMetadataInOmitted() {
    $term = Term::create([
      'name' => 'Llama term',
      'vid' => 'tags',
    ]);
    $term->setUnpublished();
    $term->save();

    $node = Node::create([
      'type' => 'article',
      'title' => 'Llama node',
      'field_tags' => ['target_id' => $term->id()],
    ]);
    $node->save();

    $user = $this->drupalCreateUser([
      'access content',
    ]);
    \Drupal::service('module_installer')->uninstall(['node_access_test']);

    // Create a new book.     $nodes = $this->createBook();

    // Load the book page and assert the created book title is displayed.     $this->drupalGet('book');
    $this->assertSession()->pageTextContains($this->book->label());

    // Unpublish the top book page and confirm that the created book title is     // not displayed for anonymous.     $this->book->setUnpublished();
    $this->book->save();

    $this->drupalGet('book');
    $this->assertSession()->pageTextNotContains($this->book->label());

    // Publish the top book page and unpublish a page in the book and confirm     // that the created book title is displayed for anonymous.     $this->book->setPublished();
    $this->book->save();
    $nodes[0]->setUnpublished();
    $nodes[0]->save();

    
$assert_session->statusCodeEquals(200);
    user_role_revoke_permissions($role->id()$permissions);
    $role = Role::load(RoleInterface::AUTHENTICATED_ID);

    // Verify the author can not view the unpublished media item without     // 'view own unpublished media' permission.     $this->grantPermissions($role['view media']);
    $this->drupalGet('media/' . $user_media->id());
    $this->assertNoCacheContext('user');
    $this->assertCacheContext('user.permissions');
    $assert_session->statusCodeEquals(200);
    $user_media->setUnpublished()->save();
    $this->drupalGet('media/' . $user_media->id());
    $this->assertCacheContext('user.permissions');
    $assert_session->statusCodeEquals(403);
    $access_result = $user_media->access('view', NULL, TRUE);
    $this->assertSame("The user must be the owner and the 'view own unpublished media' permission is required when the media item is unpublished.", $access_result->getReason());
    $this->grantPermissions($role['view own unpublished media']);
    $this->drupalGet('media/' . $user_media->id());
    $this->assertCacheContext('user');
    $assert_session->statusCodeEquals(200);

    // Test 'create media' permission.
$entity = EntityTestRevPub::create();
    $entity->setName('delete revision');
    $entity->save();

    $entity->isDefaultRevision(TRUE);
    $entity->setPublished();
    $entity->setNewRevision();
    $entity->save();
    $revisionId = $entity->getRevisionId();

    $entity->isDefaultRevision(FALSE);
    $entity->setUnpublished();
    $entity->setNewRevision();
    $entity->save();

    // Reload the entity.     /** @var \Drupal\entity_test\Entity\EntityTestRevPub $revision */
    $revision = \Drupal::entityTypeManager()->getStorage('entity_test_revpub')
      ->loadRevision($revisionId);
    // Check default but not latest.     $this->assertTrue($revision->isDefaultRevision());
    $this->assertFalse($revision->isLatestRevision());
    $this->drupalGet($entity->toUrl('revision-delete-form'));
    
/** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $operation = $form_state->getValue('operation');
    $cids = $form_state->getValue('comments');
    /** @var \Drupal\comment\CommentInterface[] $comments */
    $comments = $this->commentStorage->loadMultiple($cids);
    if ($operation != 'delete') {
      foreach ($comments as $comment) {
        if ($operation == 'unpublish') {
          $comment->setUnpublished();
        }
        elseif ($operation == 'publish') {
          $comment->setPublished();
        }
        $comment->save();
      }
      $this->messenger()->addStatus($this->t('The update has been performed.'));
      $form_state->setRedirect('comment.admin');
    }
    else {
      $info = [];
      
/** @var \Drupal\Core\Entity\RevisionableStorageInterface $entityStorage */
    $entityStorage = \Drupal::entityTypeManager()->getStorage('block_content');

    $loadRevisionId = NULL;
    if (!$isLatest) {
      // Save a historical revision, then setup for a new revision to be saved.       $this->blockEntity->save();
      $loadRevisionId = $this->blockEntity->getRevisionId();
      $this->blockEntity = $entityStorage->createRevision($this->blockEntity);
    }

    $published ? $this->blockEntity->setPublished() : $this->blockEntity->setUnpublished();
    $reusable ? $this->blockEntity->setReusable() : $this->blockEntity->setNonReusable();

    $user = User::create([
      'name' => 'Someone',
      'mail' => 'hi@example.com',
    ]);

    if ($permissions) {
      foreach ($permissions as $permission) {
        $this->role->grantPermission($permission);
      }
      


    $workflow = $this->createEditorialWorkflow();
    $this->addEntityTypeAndBundleToWorkflow($workflow, 'node', 'example');

    $english_node = Node::create([
      'type' => 'example',
      'title' => 'Test title',
    ]);
    // Revision 1 (en).     $english_node
      ->setUnpublished()
      ->save();
    $this->assertEquals('draft', $english_node->moderation_state->value);
    $this->assertFalse($english_node->isPublished());

    // Create a French translation.     $french_node = $english_node->addTranslation('fr', ['title' => 'French title']);
    $french_node->setUnpublished();
    // Revision 2 (fr).     $french_node->save();
    $french_node = $this->reloadEntity($english_node)->getTranslation('fr');
    $this->assertEquals('draft', $french_node->moderation_state->value);
    
/** * {@inheritdoc} */
  public function execute($node = NULL) {
    $elements = \Drupal::entityTypeManager()
      ->getViewBuilder('node')
      ->view(clone $node);
    $render = \Drupal::service('renderer')->render($elements);
    foreach ($this->configuration['keywords'] as $keyword) {
      if (str_contains($render$keyword) || str_contains($node->label()$keyword)) {
        $node->setUnpublished();
        $node->save();
        break;
      }
    }
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return [
      
Home | Imprint | This part of the site doesn't use cookies.