comparison core/lib/Drupal/Core/Entity/entity.api.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children 1fec387a4317
comparison
equal deleted inserted replaced
11:bfffd8d7479a 12:7a779792577d
285 * If you are defining a content entity type, it is recommended to extend the 285 * If you are defining a content entity type, it is recommended to extend the
286 * \Drupal\Core\Entity\EditorialContentEntityBase base class in order to get 286 * \Drupal\Core\Entity\EditorialContentEntityBase base class in order to get
287 * out-of-the-box support for Entity API's revisioning and publishing 287 * out-of-the-box support for Entity API's revisioning and publishing
288 * features, which will allow your entity type to be used with Drupal's 288 * features, which will allow your entity type to be used with Drupal's
289 * editorial workflow provided by the Content Moderation module. 289 * editorial workflow provided by the Content Moderation module.
290 * - The 'id' annotation gives the entity type ID, and the 'label' annotation 290 * - In the annotation, the 'id' property gives the entity type ID, and the
291 * gives the human-readable name of the entity type. If you are defining a 291 * 'label' property gives the human-readable name of the entity type. If you
292 * content entity type that uses bundles, the 'bundle_label' annotation gives 292 * are defining a content entity type that uses bundles, the 'bundle_label'
293 * the human-readable name to use for a bundle of this entity type (for 293 * property gives the human-readable name to use for a bundle of this entity
294 * example, "Content type" for the Node entity). 294 * type (for example, "Content type" for the Node entity).
295 * - The annotation will refer to several handler classes, which you will also 295 * - The annotation will refer to several handler classes, which you will also
296 * need to define: 296 * need to define:
297 * - list_builder: Define a class that extends 297 * - list_builder: Define a class that extends
298 * \Drupal\Core\Config\Entity\ConfigEntityListBuilder (for configuration 298 * \Drupal\Core\Config\Entity\ConfigEntityListBuilder (for configuration
299 * entities) or \Drupal\Core\Entity\EntityListBuilder (for content 299 * entities) or \Drupal\Core\Entity\EntityListBuilder (for content
308 * - view_builder: For content entities and config entities that need to be 308 * - view_builder: For content entities and config entities that need to be
309 * viewed, define a class that implements 309 * viewed, define a class that implements
310 * \Drupal\Core\Entity\EntityViewBuilderInterface (usually extending 310 * \Drupal\Core\Entity\EntityViewBuilderInterface (usually extending
311 * \Drupal\Core\Entity\EntityViewBuilder), to display a single entity. 311 * \Drupal\Core\Entity\EntityViewBuilder), to display a single entity.
312 * - translation: For translatable content entities (if the 'translatable' 312 * - translation: For translatable content entities (if the 'translatable'
313 * annotation has value TRUE), define a class that extends 313 * annotation property has value TRUE), define a class that extends
314 * \Drupal\content_translation\ContentTranslationHandler, to translate 314 * \Drupal\content_translation\ContentTranslationHandler, to translate
315 * the content. Configuration translation is handled automatically by the 315 * the content. Configuration translation is handled automatically by the
316 * Configuration Translation module, without the need of a handler class. 316 * Configuration Translation module, without the need of a handler class.
317 * - access: If your configuration entity has complex permissions, you might 317 * - access: If your configuration entity has complex permissions, you might
318 * need an access control handling, implementing 318 * need an access control handling, implementing
319 * \Drupal\Core\Entity\EntityAccessControlHandlerInterface, but most entities 319 * \Drupal\Core\Entity\EntityAccessControlHandlerInterface, but most
320 * can just use the 'admin_permission' annotation instead. Note that if you 320 * entities can just use the 'admin_permission' annotation property
321 * are creating your own access control handler, you should override the 321 * instead. Note that if you are creating your own access control handler,
322 * checkAccess() and checkCreateAccess() methods, not access(). 322 * you should override the checkAccess() and checkCreateAccess() methods,
323 * not access().
323 * - storage: A class implementing 324 * - storage: A class implementing
324 * \Drupal\Core\Entity\EntityStorageInterface. If not specified, content 325 * \Drupal\Core\Entity\EntityStorageInterface. If not specified, content
325 * entities will use \Drupal\Core\Entity\Sql\SqlContentEntityStorage, and 326 * entities will use \Drupal\Core\Entity\Sql\SqlContentEntityStorage, and
326 * config entities will use \Drupal\Core\Config\Entity\ConfigEntityStorage. 327 * config entities will use \Drupal\Core\Config\Entity\ConfigEntityStorage.
327 * You can extend one of these classes to provide custom behavior. 328 * You can extend one of these classes to provide custom behavior.
350 * - canonical: Default link, either to view (if entities are viewed on their 351 * - canonical: Default link, either to view (if entities are viewed on their
351 * own pages) or edit the entity. 352 * own pages) or edit the entity.
352 * - delete-form: Confirmation form to delete the entity. 353 * - delete-form: Confirmation form to delete the entity.
353 * - edit-form: Editing form. 354 * - edit-form: Editing form.
354 * - Other link types specific to your entity type can also be defined. 355 * - Other link types specific to your entity type can also be defined.
355 * - If your content entity is fieldable, provide 'field_ui_base_route' 356 * - If your content entity is fieldable, provide the 'field_ui_base_route'
356 * annotation, giving the name of the route that the Manage Fields, Manage 357 * annotation property, giving the name of the route that the Manage Fields,
357 * Display, and Manage Form Display pages from the Field UI module will be 358 * Manage Display, and Manage Form Display pages from the Field UI module
358 * attached to. This is usually the bundle settings edit page, or an entity 359 * will be attached to. This is usually the bundle settings edit page, or an
359 * type settings page if there are no bundles. 360 * entity type settings page if there are no bundles.
360 * - If your content entity has bundles, you will also need to define a second 361 * - If your content entity has bundles, you will also need to define a second
361 * plugin to handle the bundles. This plugin is itself a configuration entity 362 * plugin to handle the bundles. This plugin is itself a configuration entity
362 * type, so follow the steps here to define it. The machine name ('id' 363 * type, so follow the steps here to define it. The machine name ('id'
363 * annotation) of this configuration entity class goes into the 364 * annotation property) of this configuration entity class goes into the
364 * 'bundle_entity_type' annotation on the entity type class. For example, for 365 * 'bundle_entity_type' annotation property on the entity type class. For
365 * the Node entity, the bundle class is \Drupal\node\Entity\NodeType, whose 366 * example, for the Node entity, the bundle class is
366 * machine name is 'node_type'. This is the annotation value for 367 * \Drupal\node\Entity\NodeType, whose machine name is 'node_type'. This is
367 * 'bundle_entity_type' on the \Drupal\node\Entity\Node class. Also, the 368 * the annotation property 'bundle_entity_type' on the
368 * bundle config entity type annotation must have a 'bundle_of' entry, 369 * \Drupal\node\Entity\Node class. Also, the
370 * bundle config entity type annotation must have a 'bundle_of' property,
369 * giving the machine name of the entity type it is acting as a bundle for. 371 * giving the machine name of the entity type it is acting as a bundle for.
370 * These machine names are considered permanent, they may not be renamed. 372 * These machine names are considered permanent, they may not be renamed.
371 * - Additional annotations can be seen on entity class examples such as 373 * - Additional annotation properties can be seen on entity class examples such
372 * \Drupal\node\Entity\Node (content) and \Drupal\user\Entity\Role 374 * as \Drupal\node\Entity\Node (content) and \Drupal\user\Entity\Role
373 * (configuration). These annotations are documented on 375 * (configuration). These annotation properties are documented on
374 * \Drupal\Core\Entity\EntityType. 376 * \Drupal\Core\Entity\EntityType.
375 * 377 *
376 * @section sec_routes Entity routes 378 * @section sec_routes Entity routes
377 * Entity routes can be defined in *.routing.yml files, like any other route: 379 * Entity routes can be defined in *.routing.yml files, like any other route:
378 * see the @link routing Routing API @endlink topic for more information. 380 * see the @link routing Routing API @endlink topic for more information.
454 * $storage = \Drupal::entityManager()->getStorage('your_entity_type'); 456 * $storage = \Drupal::entityManager()->getStorage('your_entity_type');
455 * // Or if you have a $container variable: 457 * // Or if you have a $container variable:
456 * $storage = $container->get('entity.manager')->getStorage('your_entity_type'); 458 * $storage = $container->get('entity.manager')->getStorage('your_entity_type');
457 * @endcode 459 * @endcode
458 * Here, 'your_entity_type' is the machine name of your entity type ('id' 460 * Here, 'your_entity_type' is the machine name of your entity type ('id'
459 * annotation on the entity class), and note that you should use dependency 461 * annotation property on the entity class), and note that you should use
460 * injection to retrieve this object if possible. See the 462 * dependency injection to retrieve this object if possible. See the
461 * @link container Services and Dependency Injection topic @endlink for more 463 * @link container Services and Dependency Injection topic @endlink for more
462 * about how to properly retrieve services. 464 * about how to properly retrieve services.
463 * 465 *
464 * To query to find entities to load, use an entity query, which is a object 466 * To query to find entities to load, use an entity query, which is a object
465 * implementing \Drupal\Core\Entity\Query\QueryInterface that you can retrieve 467 * implementing \Drupal\Core\Entity\Query\QueryInterface that you can retrieve