NodeType.php

Same filename in this branch
  1. 11.x core/modules/node/src/Plugin/migrate/source/d6/NodeType.php
  2. 11.x core/modules/node/src/Plugin/migrate/source/d7/NodeType.php
Same filename and directory in other branches
  1. 9 core/modules/node/src/Entity/NodeType.php
  2. 9 core/modules/node/src/Plugin/migrate/source/d6/NodeType.php
  3. 9 core/modules/node/src/Plugin/migrate/source/d7/NodeType.php
  4. 9 core/modules/node/src/Plugin/Condition/NodeType.php
  5. 8.9.x core/modules/node/src/Entity/NodeType.php
  6. 8.9.x core/modules/node/src/Plugin/migrate/source/d6/NodeType.php
  7. 8.9.x core/modules/node/src/Plugin/migrate/source/d7/NodeType.php
  8. 8.9.x core/modules/node/src/Plugin/Condition/NodeType.php
  9. 10 core/modules/node/src/Entity/NodeType.php
  10. 10 core/modules/node/src/Plugin/migrate/source/d6/NodeType.php
  11. 10 core/modules/node/src/Plugin/migrate/source/d7/NodeType.php

Namespace

Drupal\node\Entity

File

core/modules/node/src/Entity/NodeType.php

View source
<?php

namespace Drupal\node\Entity;

use Drupal\Core\Config\Action\Attribute\ActionMethod;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
use Drupal\Core\Entity\Attribute\ConfigEntityType;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\node\Form\NodeTypeDeleteConfirm;
use Drupal\node\NodeTypeAccessControlHandler;
use Drupal\node\Form\NodeTypeForm;
use Drupal\node\NodeTypeInterface;
use Drupal\node\NodeTypeListBuilder;
use Drupal\user\Entity\EntityPermissionsRouteProvider;

/**
 * Defines the Node type configuration entity.
 */
class NodeType extends ConfigEntityBundleBase implements NodeTypeInterface {
  
  /**
   * The machine name of this node type.
   *
   * @var string
   *
   * @todo Rename to $id.
   */
  protected $type;
  
  /**
   * The human-readable name of the node type.
   *
   * @var string
   *
   * @todo Rename to $label.
   */
  protected $name;
  
  /**
   * A brief description of this node type.
   *
   * @var string|null
   */
  protected $description = NULL;
  
  /**
   * Help information shown to the user when creating a Node of this type.
   *
   * @var string|null
   */
  protected $help = NULL;
  
  /**
   * Default value of the 'Create new revision' checkbox of this node type.
   *
   * @var bool
   */
  protected $new_revision = TRUE;
  
  /**
   * The preview mode.
   *
   * @var int
   */
  protected $preview_mode = DRUPAL_OPTIONAL;
  
  /**
   * Display setting for author and date Submitted by post information.
   *
   * @var bool
   */
  protected $display_submitted = TRUE;
  
  /**
   * {@inheritdoc}
   */
  public function id() {
    return $this->type;
  }
  
  /**
   * {@inheritdoc}
   */
  public function isLocked() {
    $locked = \Drupal::state()->get('node.type.locked');
    return $locked[$this->id()] ?? FALSE;
  }
  
  /**
   * {@inheritdoc}
   */
  public function setNewRevision($new_revision) {
    $this->new_revision = $new_revision;
  }
  
  /**
   * {@inheritdoc}
   */
  public function displaySubmitted() {
    return $this->display_submitted;
  }
  
  /**
   * {@inheritdoc}
   */
  public function setDisplaySubmitted($display_submitted) {
    $this->display_submitted = $display_submitted;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getPreviewMode() {
    return $this->preview_mode;
  }
  
  /**
   * {@inheritdoc}
   */
  public function setPreviewMode($preview_mode) {
    $this->preview_mode = $preview_mode;
  }
  
  /**
   * {@inheritdoc}
   */
  public function getHelp() {
    return $this->help ?? '';
  }
  
  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return $this->description ?? '';
  }
  
  /**
   * {@inheritdoc}
   */
  public function postSave(EntityStorageInterface $storage, $update = TRUE) {
    parent::postSave($storage, $update);
    if ($update) {
      // Clear the cached field definitions as some settings affect the field
      // definitions.
      \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
    }
  }
  
  /**
   * {@inheritdoc}
   */
  public static function postDelete(EntityStorageInterface $storage, array $entities) {
    parent::postDelete($storage, $entities);
    // Clear the node type cache to reflect the removal.
    $storage->resetCache(array_keys($entities));
  }
  
  /**
   * {@inheritdoc}
   */
  public function shouldCreateNewRevision() {
    return $this->new_revision;
  }

}

Classes

Title Deprecated Summary
NodeType Defines the Node type configuration entity.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.