setReusable example

/** * Tests with no conditions set. * * @throws \Drupal\Core\Entity\EntityStorageException */
  public function testNoConditions() {
    $this->assertEquals(
      $this->expectations['block_reusable'],
      $this->selectionHandler->getReferenceableEntities()
    );

    $this->blockNonReusable->setReusable();
    $this->blockNonReusable->save();

    // Ensure that the block is now returned as a referenceable entity.     $this->assertEquals(
      $this->expectations['both_blocks'],
      $this->selectionHandler->getReferenceableEntities()
    );
  }

  /** * Tests setting 'reusable' condition on different levels. * * @dataProvider fieldConditionProvider * * @throws \Exception */
$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);
      }
      $this->role->save();
    }
Home | Imprint | This part of the site doesn't use cookies.