isPromoted example

// Make unsticky action.     $edit = [
      'node_bulk_form[0]' => TRUE,
      'action' => 'node_make_unsticky_action',
    ];
    $this->submitForm($edit, 'Apply to selected items');
    $node = $this->loadNode($node->id());
    $this->assertFalse($node->isSticky(), 'Node is not sticky anymore');

    // Promote to front page.     $this->assertFalse($node->isPromoted(), 'Node is not promoted to the front page');
    $this->assertFalse($node->getTranslation('en-gb')->isPromoted(), 'Node translation is not promoted to the front page');
    $this->assertFalse($node->getTranslation('it')->isPromoted(), 'Node translation is not promoted to the front page');
    $edit = [
      'node_bulk_form[0]' => TRUE,
      'action' => 'node_promote_action',
    ];
    $this->submitForm($edit, 'Apply to selected items');
    $node = $this->loadNode($node->id());
    $this->assertTrue($node->isPromoted(), 'Node has been promoted to the front page');
    $this->assertFalse($node->getTranslation('en-gb')->isPromoted(), 'Node translation has not been promoted to the front page');
    $this->assertFalse($node->getTranslation('it')->isPromoted(), 'Node translation has not been promoted to the front page');

    
private function getDocBlockFromProperty(string $class, string $property): ?array
    {
        // Use a ReflectionProperty instead of $class to get the parent class if applicable         try {
            $reflectionProperty = new \ReflectionProperty($class$property);
        } catch (\ReflectionException) {
            return null;
        }

        $source = self::PROPERTY;

        if ($reflectionProperty->isPromoted()) {
            $constructor = new \ReflectionMethod($class, '__construct');
            $rawDocNode = $constructor->getDocComment();
            $source = self::MUTATOR;
        } else {
            $rawDocNode = $reflectionProperty->getDocComment();
        }

        if (!$rawDocNode) {
            return null;
        }

        


        try {
            $reflectionProperty = new \ReflectionProperty($class$property);
        } catch (\ReflectionException) {
            $reflectionProperty = null;
        }

        $ucFirstProperty = ucfirst($property);

        switch (true) {
            case $reflectionProperty?->isPromoted() && $docBlock = $this->getDocBlockFromConstructor($class$property):
                $data = [$docBlock, self::MUTATOR, null];
                break;

            case $docBlock = $this->getDocBlockFromProperty($class$property):
                $data = [$docBlock, self::PROPERTY, null];
                break;

            case [$docBlock] = $this->getDocBlockFromMethod($class$ucFirstProperty, self::ACCESSOR):
                $data = [$docBlock, self::ACCESSOR, null];
                break;

            
$node = Node::load($id);
    $this->assertInstanceOf(NodeInterface::class$node);
    $this->assertEquals($type$node->getType());
    $this->assertEquals($langcode$node->langcode->value);
    $this->assertEquals($title$node->getTitle());
    $this->assertEquals($uid$node->getOwnerId());
    $this->assertEquals($status$node->isPublished());
    $this->assertEquals($created$node->getCreatedTime());
    if (isset($changed)) {
      $this->assertEquals($changed$node->getChangedTime());
    }
    $this->assertEquals($promoted$node->isPromoted());
    $this->assertEquals($sticky$node->isSticky());
  }

  /** * Asserts various aspects of a node revision. * * @param int $id * The revision ID. * @param string $title * The expected title. * @param int $uid * The revision author ID. * @param string|null $log * The revision log message. * @param int $timestamp * The revision's time stamp. * * @internal */
$this->submitForm($edit$this->getFormSubmitAction($entity$langcode));
    }

    $storage->resetCache([$this->entityId]);
    $entity = $storage->load($this->entityId);
    foreach ($this->langcodes as $langcode) {
      $translation = $entity->getTranslation($langcode);
      $metadata = $this->manager->getTranslationMetadata($translation);
      $this->assertEquals($values[$langcode]['uid']$metadata->getAuthor()->id(), 'Translation author correctly stored.');
      $this->assertEquals($values[$langcode]['created']$metadata->getCreatedTime(), 'Translation date correctly stored.');
      $this->assertEquals($values[$langcode]['sticky']$translation->isSticky(), 'Sticky of Translation correctly stored.');
      $this->assertEquals($values[$langcode]['promote']$translation->isPromoted(), 'Promoted of Translation correctly stored.');
    }
  }

  /** * Tests that translation page inherits admin status of edit page. */
  public function testTranslationLinkTheme() {
    $this->drupalLogin($this->administrator);
    $article = $this->drupalCreateNode(['type' => 'article', 'langcode' => $this->langcodes[0]]);

    // Set up the default admin theme and use it for node editing.
Home | Imprint | This part of the site doesn't use cookies.