forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentity-content.php.twig
More file actions
189 lines (171 loc) · 5.55 KB
/
Copy pathentity-content.php.twig
File metadata and controls
189 lines (171 loc) · 5.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
86
87
88
89
90
91
92
93
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
{% extends "base/class.php.twig" %}
{% block file_path %}
Drupal\{{ module }}\Entity\{{ entity_class }}.
{% endblock %}
{% block namespace_class %}
namespace Drupal\{{ module }}\Entity;
{% endblock %}
{% block use_class %}
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\{{ module }}\{{ entity_class }}Interface;
use Drupal\user\UserInterface;
{% endblock %}
{% block class_declaration %}
/**
* Defines the {{ entity_class }} entity.
*
* @ingroup {{ module }}
*
* @ContentEntityType(
* id = "{{ entity_name }}",
* label = @Translation("{{ entity_class }} entity"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\{{ module }}\Entity\Controller\{{ entity_class }}ListController",
* "views_data" = "Drupal\{{ module }}\Entity\{{ entity_class }}ViewsData",
*
* "form" = {
* "default" = "Drupal\{{ module }}\Entity\Form\{{ entity_class }}Form",
* "add" = "Drupal\{{ module }}\Entity\Form\{{ entity_class }}Form",
* "edit" = "Drupal\{{ module }}\Entity\Form\{{ entity_class }}Form",
* "delete" = "Drupal\{{ module }}\Entity\Form\{{ entity_class }}DeleteForm",
* },
* "access" = "Drupal\{{ module }}\{{ entity_class }}AccessControlHandler",
* },
* base_table = "{{ entity_name }}",
* admin_permission = "administer {{ entity_class }} entity",
* fieldable = TRUE,
* entity_keys = {
* "id" = "id",
* "label" = "name",
* "uuid" = "uuid"
* },
* links = {
* "canonical" = "/entity.{{ entity_name }}.canonical",
* "edit-form" = "/entity.{{ entity_name }}.edit_form",
* "delete-form" = "/entity.{{ entity_name }}.delete_form",
* "collection" = "/entity.{{ entity_name }}.collection"
* },
* field_ui_base_route = "{{ entity_name }}.settings"
* )
*/
class {{ entity_class }} extends ContentEntityBase implements {{ entity_class }}Interface {% endblock %}
{% block class_methods %}
/**
* {@inheritdoc}
*/
public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
parent::preCreate($storage_controller, $values);
$values += array(
'user_id' => \Drupal::currentUser()->id(),
);
}
/**
* {@inheritdoc}
*/
public function getCreatedTime() {
return $this->get('created')->value;
}
/**
* {@inheritdoc}
*/
public function getChangedTime() {
return $this->get('changed')->value;
}
/**
* {@inheritdoc}
*/
public function getOwner() {
return $this->get('user_id')->entity;
}
/**
* {@inheritdoc}
*/
public function getOwnerId() {
return $this->get('user_id')->target_id;
}
/**
* {@inheritdoc}
*/
public function setOwnerId($uid) {
$this->set('user_id', $uid);
return $this;
}
/**
* {@inheritdoc}
*/
public function setOwner(UserInterface $account) {
$this->set('user_id', $account->id());
return $this;
}
/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields['id'] = BaseFieldDefinition::create('integer')
->setLabel(t('ID'))
->setDescription(t('The ID of the {{ entity_class }} entity.'))
->setReadOnly(TRUE);
$fields['uuid'] = BaseFieldDefinition::create('uuid')
->setLabel(t('UUID'))
->setDescription(t('The UUID of the {{ entity_class }} entity.'))
->setReadOnly(TRUE);
$fields['user_id'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Authored by'))
->setDescription(t('The user ID of the {{ entity_class }} entity author.'))
->setRevisionable(TRUE)
->setSetting('target_type', 'user')
->setSetting('handler', 'default')
->setDefaultValueCallback('Drupal\node\Entity\Node::getCurrentUserId')
->setTranslatable(TRUE)
->setDisplayOptions('view', array(
'label' => 'hidden',
'type' => 'author',
'weight' => 0,
))
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'weight' => 5,
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => '60',
'autocomplete_type' => 'tags',
'placeholder' => '',
),
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['name'] = BaseFieldDefinition::create('string')
->setLabel(t('Name'))
->setDescription(t('The name of the {{ entity_class }} entity.'))
->setSettings(array(
'default_value' => '',
'max_length' => 50,
'text_processing' => 0,
))
->setDisplayOptions('view', array(
'label' => 'above',
'type' => 'string',
'weight' => -4,
))
->setDisplayOptions('form', array(
'type' => 'string_textfield',
'weight' => -4,
))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$fields['langcode'] = BaseFieldDefinition::create('language')
->setLabel(t('Language code'))
->setDescription(t('The language code of {{ entity_class }} entity.'));
$fields['created'] = BaseFieldDefinition::create('created')
->setLabel(t('Created'))
->setDescription(t('The time that the entity was created.'));
$fields['changed'] = BaseFieldDefinition::create('changed')
->setLabel(t('Changed'))
->setDescription(t('The time that the entity was last edited.'));
return $fields;
}
{% endblock %}