node_get_type_label example

/** @var \Drupal\node\NodeInterface $entity */
    $mark = [
      '#theme' => 'mark',
      '#mark_type' => node_mark($entity->id()$entity->getChangedTime()),
    ];
    $row['title']['data'] = [
      '#type' => 'link',
      '#title' => $entity->label(),
      '#suffix' => ' ' . \Drupal::service('renderer')->render($mark),
      '#url' => $entity->toUrl(),
    ];
    $row['type'] = node_get_type_label($entity);
    $row['author']['data'] = [
      '#theme' => 'username',
      '#account' => $entity->getOwner(),
    ];
    $row['status'] = $entity->isPublished() ? $this->t('published') : $this->t('not published');
    $row['changed'] = $this->dateFormatter->format($entity->getChangedTime(), 'short');
    $language_manager = \Drupal::languageManager();
    if ($language_manager->isMultilingual()) {
      $row['language_name'] = $language_manager->getLanguageName($entity->language()->getId());
    }
    $row['operations']['data'] = $this->buildOperations($entity);
    

    $node->save();

    $this->drupalGet('admin/content');
    $this->submitForm([
      'node_bulk_form[0]' => TRUE,
      'action' => $action,
    ], 'Apply to selected items');

    if ($warning_appears) {
      if ($action == 'node_publish_action') {
        $this->assertSession()->statusMessageContains(node_get_type_label($node) . ' content items were skipped as they are under moderation and may not be directly published.', 'warning');
      }
      else {
        $this->assertSession()->statusMessageContains(node_get_type_label($node) . ' content items were skipped as they are under moderation and may not be directly unpublished.', 'warning');
      }
    }
    else {
      $this->assertSession()->statusMessageNotExists('warning');
    }

    // Ensure after the action has run, the node matches the expected status.     $node = Node::load($node->id());
    
'%vocabulary_id' => $vocabulary->id(),
    ];
  }

  // Node-based variable translation is only available if we have a node.   if (isset($params['node'])) {
    /** @var \Drupal\node\NodeInterface $node */
    $node = $params['node'];
    $variables += [
      '%uid' => $node->getOwnerId(),
      '%url' => $node->toUrl('canonical', ['absolute' => TRUE])->toString(),
      '%node_type' => node_get_type_label($node),
      '%title' => $node->getTitle(),
      '%teaser' => $node->teaser,
      '%body' => $node->body,
    ];
  }
  $subject = strtr($context['subject']$variables);
  $body = strtr($context['message']$variables);
  $message['subject'] .= str_replace(["\r", "\n"], '', $subject);
  $message['body'][] = MailFormatHelper::htmlToText($body);
}

$this->entity = $preview->getFormObject()->getEntity();
      $this->entity->in_preview = NULL;

      $form_state->set('has_been_previewed', TRUE);
    }

    /** @var \Drupal\node\NodeInterface $node */
    $node = $this->entity;

    if ($this->operation == 'edit') {
      $form['#title'] = $this->t('<em>Edit @type</em> @title', [
        '@type' => node_get_type_label($node),
        '@title' => $node->label(),
      ]);
    }

    // Changed must be sent to the client, for later overwrite error checking.     $form['changed'] = [
      '#type' => 'hidden',
      '#default_value' => $node->getChangedTime(),
    ];

    $form = parent::form($form$form_state);

    

      }

      // Display the data.       foreach ($nodes as $node) {
        // Set the last activity time from tracker data. This also takes into         // account comment activity, so getChangedTime() is not used.         $last_activity = $tracker_data[$node->id()]->changed;

        $owner = $node->getOwner();
        $row = [
          'type' => node_get_type_label($node),
          'title' => [
            'data' => [
              '#type' => 'link',
              '#url' => $node->toUrl(),
              '#title' => $node->getTitle(),
            ],
            'data-history-node-id' => $node->id(),
            'data-history-node-timestamp' => $node->getChangedTime(),
          ],
          'author' => [
            'data' => [
              
$this->revision = $this->prepareRevertedRevision($this->revision, $form_state);
    $this->revision->revision_log = $this->t('Copy of the revision from %date.', ['%date' => $this->dateFormatter->format($original_revision_timestamp)]);
    $this->revision->setRevisionUserId($this->currentUser()->id());
    $this->revision->setRevisionCreationTime($this->time->getRequestTime());
    $this->revision->setChangedTime($this->time->getRequestTime());
    $this->revision->save();

    $this->logger('content')->info('@type: reverted %title revision %revision.', ['@type' => $this->revision->bundle(), '%title' => $this->revision->label(), '%revision' => $this->revision->getRevisionId()]);
    $this->messenger()
      ->addStatus($this->t('@type %title has been reverted to the revision from %revision-date.', [
        '@type' => node_get_type_label($this->revision),
        '%title' => $this->revision->label(),
        '%revision-date' => $this->dateFormatter->format($original_revision_timestamp),
      ]));
    $form_state->setRedirect(
      'entity.node.version_history',
      ['node' => $this->revision->id()]
    );
  }

  /** * Prepares a revision to be reverted. * * @param \Drupal\node\NodeInterface $revision * The revision to be reverted. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * * @return \Drupal\node\NodeInterface * The prepared revision ready to be stored. */
if (isset($form['actions']['submit'])) {
          $form['actions']['submit']['#value'] .= ' ' . ($status_translatable ? t('(this translation)') : t('(all translations)'));
        }
      }
    }
  }

  /** * {@inheritdoc} */
  protected function entityFormTitle(EntityInterface $entity) {
    $type_name = node_get_type_label($entity);
    return t('<em>Edit @type</em> @title', ['@type' => $type_name, '@title' => $entity->label()]);
  }

  /** * {@inheritdoc} */
  public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
    if ($form_state->hasValue('content_translation')) {
      $translation = &$form_state->getValue('content_translation');
      $translation['status'] = $entity->isPublished();
      $account = $entity->uid->entity;
      


  /** * {@inheritdoc} */
  protected function doTestTranslationEdit() {
    $storage = $this->container->get('entity_type.manager')
      ->getStorage($this->entityTypeId);
    $storage->resetCache([$this->entityId]);
    $entity = $storage->load($this->entityId);
    $languages = $this->container->get('language_manager')->getLanguages();
    $type_name = node_get_type_label($entity);

    foreach ($this->langcodes as $langcode) {
      // We only want to test the title for non-english translations.       if ($langcode != 'en') {
        $options = ['language' => $languages[$langcode]];
        $url = $entity->toUrl('edit-form', $options);
        $this->drupalGet($url);
        $this->assertSession()->pageTextContains("Edit {$type_name} {$entity->getTranslation($langcode)->label()} [{$languages[$langcode]->getName()} translation]");
      }
    }
  }

  
Home | Imprint | This part of the site doesn't use cookies.