Newer
Older
<?php
/**
* @file
* Contains \Drupal\node\Entity\NodeType.
*/
namespace Drupal\node\Entity;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Config\Entity\ConfigEntityBundleBase;
catch
committed
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\node\NodeTypeInterface;
/**
* Defines the Node type configuration entity.
*
Alex Pott
committed
* @ConfigEntityType(
* id = "node_type",
* label = @Translation("Content type"),
* controllers = {
* "access" = "Drupal\node\NodeTypeAccessControlHandler",
* "form" = {
Alex Pott
committed
* "add" = "Drupal\node\NodeTypeForm",
* "edit" = "Drupal\node\NodeTypeForm",
* "delete" = "Drupal\node\Form\NodeTypeDeleteConfirm"
* },
* "list_builder" = "Drupal\node\NodeTypeListBuilder",
* },
* admin_permission = "administer content types",
* config_prefix = "type",
Alex Pott
committed
* bundle_of = "node",
* entity_keys = {
* "id" = "type",
Dries Buytaert
committed
* "label" = "name"
Alex Pott
committed
* },
* links = {
Alex Pott
committed
* "edit-form" = "entity.node_type.edit_form",
* "delete-form" = "entity.node_type.delete_form"
* }
* )
*/
class NodeType extends ConfigEntityBundleBase implements NodeTypeInterface {
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* The machine name of this node type.
*
* @var string
*
* @todo Rename to $id.
*/
public $type;
/**
* The human-readable name of the node type.
*
* @var string
*
* @todo Rename to $label.
*/
public $name;
/**
* A brief description of this node type.
*
* @var string
*/
public $description;
/**
* Help information shown to the user when creating a Node of this type.
*
* @var string
*/
public $help;
/**
* Indicates whether a Body field should be created for this node type.
*
* This property affects entity creation only. It allows default configuration
* of modules and installation profiles to specify whether a Body field should
* be created for this bundle.
*
* @var bool
*
* @see \Drupal\node\Entity\NodeType::$create_body_label
*/
protected $create_body = TRUE;
/**
* The label to use for the Body field upon entity creation.
*
* @see \Drupal\node\Entity\NodeType::$create_body
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
*
* @var string
*/
protected $create_body_label = 'Body';
/**
* Module-specific settings for this node type, keyed by module name.
*
* @var array
*
* @todo Pluginify.
*/
public $settings = array();
/**
* {@inheritdoc}
*/
public function id() {
return $this->type;
}
/**
* {@inheritdoc}
*/
public function getModuleSettings($module) {
if (isset($this->settings[$module]) && is_array($this->settings[$module])) {
return $this->settings[$module];
}
return array();
}
/**
* {@inheritdoc}
*/
public function isLocked() {
$locked = \Drupal::state()->get('node.type.locked');
return isset($locked[$this->id()]) ? $locked[$this->id()] : FALSE;
}
/**
* {@inheritdoc}
*/
catch
committed
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
Angie Byron
committed
if (!$update) {
// Create a body if the create_body property is true and we're not in
// the syncing process.
if ($this->get('create_body') && !$this->isSyncing()) {
$label = $this->get('create_body_label');
node_add_body_field($this, $label);
}
}
elseif ($this->getOriginalId() != $this->id()) {
$update_count = node_type_update_nodes($this->getOriginalId(), $this->id());
if ($update_count) {
drupal_set_message(format_plural($update_count,
'Changed the content type of 1 post from %old-type to %type.',
'Changed the content type of @count posts from %old-type to %type.',
array(
'%old-type' => $this->getOriginalId(),
'%type' => $this->id(),
)));
}
}
if ($update) {
// Clear the cached field definitions as some settings affect the field
// definitions.
$this->entityManager()->clearCachedFieldDefinitions();
}
}
/**
* {@inheritdoc}
*/
catch
committed
public static function postDelete(EntityStorageInterface $storage, array $entities) {
parent::postDelete($storage, $entities);
Angie Byron
committed
// Clear the node type cache to reflect the removal.
catch
committed
$storage->resetCache(array_keys($entities));
}
/**
* {@inheritdoc}
*/
catch
committed
public static function preCreate(EntityStorageInterface $storage, array &$values) {
parent::preCreate($storage, $values);
// Ensure default values are set.
if (!isset($values['settings']['node'])) {
$values['settings']['node'] = array();
}
$values['settings']['node'] = NestedArray::mergeDeep(array(
'options' => array(
'revision' => FALSE,
),
'preview' => DRUPAL_OPTIONAL,
'submitted' => TRUE,
), $values['settings']['node']);
}