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"),
16 * "access" = "Drupal\node\NodeTypeAccessControlHandler",
18 * "add" = "Drupal\node\NodeTypeForm",
19 * "edit" = "Drupal\node\NodeTypeForm",
20 * "delete" = "Drupal\node\Form\NodeTypeDeleteConfirm"
22 * "list_builder" = "Drupal\node\NodeTypeListBuilder",
24 * admin_permission = "administer content types",
25 * config_prefix = "type",
32 * "edit-form" = "/admin/structure/types/manage/{node_type}",
33 * "delete-form" = "/admin/structure/types/manage/{node_type}/delete",
34 * "collection" = "/admin/structure/types",
43 * "display_submitted",
47 class NodeType extends ConfigEntityBundleBase implements NodeTypeInterface {
50 * The machine name of this node type.
54 * @todo Rename to $id.
59 * The human-readable name of the node type.
63 * @todo Rename to $label.
68 * A brief description of this node type.
72 protected $description;
75 * Help information shown to the user when creating a Node of this type.
82 * Default value of the 'Create new revision' checkbox of this node type.
86 protected $new_revision = TRUE;
93 protected $preview_mode = DRUPAL_OPTIONAL;
96 * Display setting for author and date Submitted by post information.
100 protected $display_submitted = TRUE;
105 public function id() {
112 public function isLocked() {
113 $locked = \Drupal::state()->get('node.type.locked');
114 return isset($locked[$this->id()]) ? $locked[$this->id()] : FALSE;
120 public function isNewRevision() {
121 return $this->new_revision;
127 public function setNewRevision($new_revision) {
128 $this->new_revision = $new_revision;
134 public function displaySubmitted() {
135 return $this->display_submitted;
141 public function setDisplaySubmitted($display_submitted) {
142 $this->display_submitted = $display_submitted;
148 public function getPreviewMode() {
149 return $this->preview_mode;
155 public function setPreviewMode($preview_mode) {
156 $this->preview_mode = $preview_mode;
162 public function getHelp() {
169 public function getDescription() {
170 return $this->description;
176 public function postSave(EntityStorageInterface $storage, $update = TRUE) {
177 parent::postSave($storage, $update);
179 if ($update && $this->getOriginalId() != $this->id()) {
180 $update_count = node_type_update_nodes($this->getOriginalId(), $this->id());
182 drupal_set_message(\Drupal::translation()->formatPlural($update_count,
183 'Changed the content type of 1 post from %old-type to %type.',
184 'Changed the content type of @count posts from %old-type to %type.',
186 '%old-type' => $this->getOriginalId(),
187 '%type' => $this->id(),
192 // Clear the cached field definitions as some settings affect the field
194 $this->entityManager()->clearCachedFieldDefinitions();
201 public static function postDelete(EntityStorageInterface $storage, array $entities) {
202 parent::postDelete($storage, $entities);
204 // Clear the node type cache to reflect the removal.
205 $storage->resetCache(array_keys($entities));
211 public function shouldCreateNewRevision() {
212 return $this->isNewRevision();