3 namespace Drupal\node\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
6 use Drupal\Core\Entity\EntityStorageInterface;
7 use Drupal\node\NodeTypeInterface;
10 * Defines the Node type configuration entity.
14 * label = @Translation("Content type"),
15 * label_collection = @Translation("Content types"),
16 * label_singular = @Translation("content type"),
17 * label_plural = @Translation("content types"),
18 * label_count = @PluralTranslation(
19 * singular = "@count content type",
20 * plural = "@count content types",
23 * "access" = "Drupal\node\NodeTypeAccessControlHandler",
25 * "add" = "Drupal\node\NodeTypeForm",
26 * "edit" = "Drupal\node\NodeTypeForm",
27 * "delete" = "Drupal\node\Form\NodeTypeDeleteConfirm"
29 * "list_builder" = "Drupal\node\NodeTypeListBuilder",
31 * admin_permission = "administer content types",
32 * config_prefix = "type",
39 * "edit-form" = "/admin/structure/types/manage/{node_type}",
40 * "delete-form" = "/admin/structure/types/manage/{node_type}/delete",
41 * "collection" = "/admin/structure/types",
50 * "display_submitted",
54 class NodeType extends ConfigEntityBundleBase implements NodeTypeInterface {
57 * The machine name of this node type.
61 * @todo Rename to $id.
66 * The human-readable name of the node type.
70 * @todo Rename to $label.
75 * A brief description of this node type.
79 protected $description;
82 * Help information shown to the user when creating a Node of this type.
89 * Default value of the 'Create new revision' checkbox of this node type.
93 protected $new_revision = TRUE;
100 protected $preview_mode = DRUPAL_OPTIONAL;
103 * Display setting for author and date Submitted by post information.
107 protected $display_submitted = TRUE;
112 public function id() {
119 public function isLocked() {
120 $locked = \Drupal::state()->get('node.type.locked');
121 return isset($locked[$this->id()]) ? $locked[$this->id()] : FALSE;
127 public function isNewRevision() {
128 return $this->new_revision;
134 public function setNewRevision($new_revision) {
135 $this->new_revision = $new_revision;
141 public function displaySubmitted() {
142 return $this->display_submitted;
148 public function setDisplaySubmitted($display_submitted) {
149 $this->display_submitted = $display_submitted;
155 public function getPreviewMode() {
156 return $this->preview_mode;
162 public function setPreviewMode($preview_mode) {
163 $this->preview_mode = $preview_mode;
169 public function getHelp() {
176 public function getDescription() {
177 return $this->description;
183 public function postSave(EntityStorageInterface $storage, $update = TRUE) {
184 parent::postSave($storage, $update);
186 if ($update && $this->getOriginalId() != $this->id()) {
187 $update_count = node_type_update_nodes($this->getOriginalId(), $this->id());
189 \Drupal::messenger()->addStatus(\Drupal::translation()->formatPlural($update_count,
190 'Changed the content type of 1 post from %old-type to %type.',
191 'Changed the content type of @count posts from %old-type to %type.',
193 '%old-type' => $this->getOriginalId(),
194 '%type' => $this->id(),
199 // Clear the cached field definitions as some settings affect the field
201 $this->entityManager()->clearCachedFieldDefinitions();
208 public static function postDelete(EntityStorageInterface $storage, array $entities) {
209 parent::postDelete($storage, $entities);
211 // Clear the node type cache to reflect the removal.
212 $storage->resetCache(array_keys($entities));
218 public function shouldCreateNewRevision() {
219 return $this->isNewRevision();