Projet

Général

Profil

Révision fc2c1c7a

Ajouté par Assos Assos il y a plus de 8 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/entity/includes/entity.inc
5 5
 * Provides a base class for entities.
6 6
 */
7 7

  
8
/**
9
 * Interface for class based entities.
10
 */
11
interface EntityInterface {
12

  
13
  /**
14
   * Returns the internal, numeric identifier.
15
   *
16
   * Returns the numeric identifier, even if the entity type has specified a
17
   * name key. In the latter case, the numeric identifier is supposed to be used
18
   * when dealing generically with entities or internally to refer to an entity,
19
   * i.e. in a relational database. If unsure, use Entity:identifier().
20
   */
21
  public function internalIdentifier();
22

  
23
  /**
24
   * Returns the entity identifier, i.e. the entities name or numeric id.
25
   *
26
   * @return
27
   *   The identifier of the entity. If the entity type makes use of a name key,
28
   *   the name is returned, else the numeric id.
29
   *
30
   * @see entity_id()
31
   */
32
  public function identifier();
33

  
34
  /**
35
   * Returns the info of the type of the entity.
36
   *
37
   * @see entity_get_info()
38
   */
39
  public function entityInfo();
40

  
41
  /**
42
   * Returns the type of the entity.
43
   */
44
  public function entityType();
45

  
46
  /**
47
   * Returns the bundle of the entity.
48
   *
49
   * @return
50
   *   The bundle of the entity. Defaults to the entity type if the entity type
51
   *   does not make use of different bundles.
52
   */
53
  public function bundle();
54

  
55
  /**
56
   * Returns the EntityMetadataWrapper of the entity.
57
   *
58
   * @return EntityDrupalWrapper
59
   *   An EntityMetadataWrapper containing the entity.
60
   */
61
  public function wrapper();
62

  
63
  /**
64
   * Returns the label of the entity.
65
   *
66
   * Modules may alter the label by specifying another 'label callback' using
67
   * hook_entity_info_alter().
68
   *
69
   * @see entity_label()
70
   */
71
  public function label();
72

  
73
  /**
74
   * Returns the uri of the entity just as entity_uri().
75
   *
76
   * Modules may alter the uri by specifying another 'uri callback' using
77
   * hook_entity_info_alter().
78
   *
79
   * @see entity_uri()
80
   */
81
  public function uri();
82

  
83
  /**
84
   * Checks if the entity has a certain exportable status.
85
   *
86
   * @param $status
87
   *   A status constant, i.e. one of ENTITY_CUSTOM, ENTITY_IN_CODE,
88
   *   ENTITY_OVERRIDDEN or ENTITY_FIXED.
89
   *
90
   * @return bool
91
   *   For exportable entities TRUE if the entity has the status, else FALSE.
92
   *   In case the entity is not exportable, NULL is returned.
93
   *
94
   * @see entity_has_status()
95
   */
96
  public function hasStatus($status);
97

  
98
  /**
99
   * Permanently saves the entity.
100
   *
101
   * @see entity_save()
102
   */
103
  public function save();
104

  
105
  /**
106
   * Permanently deletes the entity.
107
   *
108
   * @see entity_delete()
109
   */
110
  public function delete();
111

  
112
  /**
113
   * Exports the entity.
114
   *
115
   * @see entity_export()
116
   */
117
  public function export($prefix = '');
118

  
119
  /**
120
   * Generate an array for rendering the entity.
121
   *
122
   * @see entity_view()
123
   */
124
  public function view($view_mode = 'full', $langcode = NULL, $page = NULL);
125

  
126
  /**
127
   * Builds a structured array representing the entity's content.
128
   *
129
   * @see entity_build_content()
130
   */
131
  public function buildContent($view_mode = 'full', $langcode = NULL);
132

  
133
  /**
134
   * Gets the raw, translated value of a property or field.
135
   *
136
   * Supports retrieving field translations as well as i18n string translations.
137
   *
138
   * Note that this returns raw data values, which might not reflect what
139
   * has been declared for hook_entity_property_info() as no 'getter callbacks'
140
   * are invoked or no referenced entities are loaded. For retrieving values
141
   * reflecting the property info make use of entity metadata wrappers, see
142
   * entity_metadata_wrapper().
143
   *
144
   * @param $property
145
   *   The name of the property to return; e.g., 'title'.
146
   * @param $langcode
147
   *   (optional) The language code of the language to which the value should
148
   *   be translated. If set to NULL, the default display language is being
149
   *   used.
150
   *
151
   * @return
152
   *   The raw, translated property value; or the raw, un-translated value if no
153
   *   translation is available.
154
   *
155
   * @todo Implement an analogous setTranslation() method for updating.
156
   */
157
  public function getTranslation($property, $langcode = NULL);
158

  
159
  /**
160
   * Checks whether the entity is the default revision.
161
   *
162
   * @return Boolean
163
   *
164
   * @see entity_revision_is_default()
165
   */
166
  public function isDefaultRevision();
167

  
168
}
169

  
8 170
/**
9 171
 * A common class for entities.
10 172
 *
......
25 187
 *   public $count = 0;
26 188
 * @endcode
27 189
 */
28
class Entity {
190
class Entity implements EntityInterface {
29 191

  
30 192
  protected $entityType;
31 193
  protected $entityInfo;
......
34 196
  protected $wrapper;
35 197

  
36 198
  /**
37
   * Creates a new entity.
38
   *
39
   * @see entity_create()
199
   * {@inheritdoc}
40 200
   */
41 201
  public function __construct(array $values = array(), $entityType = NULL) {
42 202
    if (empty($entityType)) {
......
61 221
  }
62 222

  
63 223
  /**
64
   * Returns the internal, numeric identifier.
65
   *
66
   * Returns the numeric identifier, even if the entity type has specified a
67
   * name key. In the latter case, the numeric identifier is supposed to be used
68
   * when dealing generically with entities or internally to refer to an entity,
69
   * i.e. in a relational database. If unsure, use Entity:identifier().
224
   * {@inheritdoc}
70 225
   */
71 226
  public function internalIdentifier() {
72 227
    return isset($this->{$this->idKey}) ? $this->{$this->idKey} : NULL;
73 228
  }
74 229

  
75 230
  /**
76
   * Returns the entity identifier, i.e. the entities name or numeric id.
77
   *
78
   * @return
79
   *   The identifier of the entity. If the entity type makes use of a name key,
80
   *   the name is returned, else the numeric id.
81
   *
82
   * @see entity_id()
231
   * {@inheritdoc}
83 232
   */
84 233
  public function identifier() {
85 234
    return isset($this->{$this->nameKey}) ? $this->{$this->nameKey} : NULL;
86 235
  }
87 236

  
88 237
  /**
89
   * Returns the info of the type of the entity.
90
   *
91
   * @see entity_get_info()
238
   * {@inheritdoc}
92 239
   */
93 240
  public function entityInfo() {
94 241
    return $this->entityInfo;
95 242
  }
96 243

  
97 244
  /**
98
   * Returns the type of the entity.
245
   * {@inheritdoc}
99 246
   */
100 247
  public function entityType() {
101 248
    return $this->entityType;
102 249
  }
103 250

  
104 251
  /**
105
   * Returns the bundle of the entity.
106
   *
107
   * @return
108
   *   The bundle of the entity. Defaults to the entity type if the entity type
109
   *   does not make use of different bundles.
252
   * {@inheritdoc}
110 253
   */
111 254
  public function bundle() {
112 255
    return !empty($this->entityInfo['entity keys']['bundle']) ? $this->{$this->entityInfo['entity keys']['bundle']} : $this->entityType;
113 256
  }
114 257

  
115 258
  /**
116
   * Returns the EntityMetadataWrapper of the entity.
117
   *
118
   * @return EntityDrupalWrapper
119
   *   An EntityMetadataWrapper containing the entity.
259
   * {@inheritdoc}
120 260
   */
121 261
  public function wrapper() {
122 262
    if (empty($this->wrapper)) {
......
130 270
  }
131 271

  
132 272
  /**
133
   * Returns the label of the entity.
134
   *
135
   * Modules may alter the label by specifying another 'label callback' using
136
   * hook_entity_info_alter().
137
   *
138
   * @see entity_label()
273
   * {@inheritdoc}
139 274
   */
140 275
  public function label() {
141 276
    // If the default label flag is enabled, this is being invoked recursively.
......
165 300
  }
166 301

  
167 302
  /**
168
   * Returns the uri of the entity just as entity_uri().
169
   *
170
   * Modules may alter the uri by specifying another 'uri callback' using
171
   * hook_entity_info_alter().
172
   *
173
   * @see entity_uri()
303
   * {@inheritdoc}
174 304
   */
175 305
  public function uri() {
176 306
    if (isset($this->entityInfo['uri callback']) && $this->entityInfo['uri callback'] == 'entity_class_uri') {
......
188 318
  }
189 319

  
190 320
  /**
191
   * Checks if the entity has a certain exportable status.
192
   *
193
   * @param $status
194
   *   A status constant, i.e. one of ENTITY_CUSTOM, ENTITY_IN_CODE,
195
   *   ENTITY_OVERRIDDEN or ENTITY_FIXED.
196
   *
197
   * @return
198
   *   For exportable entities TRUE if the entity has the status, else FALSE.
199
   *   In case the entity is not exportable, NULL is returned.
200
   *
201
   * @see entity_has_status()
321
   * {@inheritdoc}
202 322
   */
203 323
  public function hasStatus($status) {
204 324
    if (!empty($this->entityInfo['exportable'])) {
......
207 327
  }
208 328

  
209 329
  /**
210
   * Permanently saves the entity.
211
   *
212
   * @see entity_save()
330
   * {@inheritdoc}
213 331
   */
214 332
  public function save() {
215 333
    return entity_get_controller($this->entityType)->save($this);
216 334
  }
217 335

  
218 336
  /**
219
   * Permanently deletes the entity.
220
   *
221
   * @see entity_delete()
337
   * {@inheritdoc}
222 338
   */
223 339
  public function delete() {
224 340
    $id = $this->identifier();
......
228 344
  }
229 345

  
230 346
  /**
231
   * Exports the entity.
232
   *
233
   * @see entity_export()
347
   * {@inheritdoc}
234 348
   */
235 349
  public function export($prefix = '') {
236 350
    return entity_get_controller($this->entityType)->export($this, $prefix);
237 351
  }
238 352

  
239 353
  /**
240
   * Generate an array for rendering the entity.
241
   *
242
   * @see entity_view()
354
   * {@inheritdoc}
243 355
   */
244 356
  public function view($view_mode = 'full', $langcode = NULL, $page = NULL) {
245 357
    return entity_get_controller($this->entityType)->view(array($this), $view_mode, $langcode, $page);
246 358
  }
247 359

  
248 360
  /**
249
   * Builds a structured array representing the entity's content.
250
   *
251
   * @see entity_build_content()
361
   * {@inheritdoc}
252 362
   */
253 363
  public function buildContent($view_mode = 'full', $langcode = NULL) {
254 364
    return entity_get_controller($this->entityType)->buildContent($this, $view_mode, $langcode);
255 365
  }
256 366

  
257 367
  /**
258
   * Gets the raw, translated value of a property or field.
259
   *
260
   * Supports retrieving field translations as well as i18n string translations.
261
   *
262
   * Note that this returns raw data values, which might not reflect what
263
   * has been declared for hook_entity_property_info() as no 'getter callbacks'
264
   * are invoked or no referenced entities are loaded. For retrieving values
265
   * reflecting the property info make use of entity metadata wrappers, see
266
   * entity_metadata_wrapper().
267
   *
268
   * @param $property_name
269
   *   The name of the property to return; e.g., 'title'.
270
   * @param $langcode
271
   *   (optional) The language code of the language to which the value should
272
   *   be translated. If set to NULL, the default display language is being
273
   *   used.
274
   *
275
   * @return
276
   *   The raw, translated property value; or the raw, un-translated value if no
277
   *   translation is available.
278
   *
279
   * @todo Implement an analogous setTranslation() method for updating.
368
   * {@inheritdoc}
280 369
   */
281 370
  public function getTranslation($property, $langcode = NULL) {
282 371
    $all_info = entity_get_all_property_info($this->entityType);
......
296 385
  }
297 386

  
298 387
  /**
299
   * Checks whether the entity is the default revision.
300
   *
301
   * @return Boolean
302
   *
303
   * @see entity_revision_is_default()
388
   * {@inheritdoc}
304 389
   */
305 390
  public function isDefaultRevision() {
306 391
    if (!empty($this->entityInfo['entity keys']['revision'])) {

Formats disponibles : Unified diff