Newer
Older
Angie Byron
committed
<?php
/**
* @file
* Contains \Drupal\Core\Entity\EntityManagerInterface.
*/
namespace Drupal\Core\Entity;
use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
Angie Byron
committed
use Drupal\Component\Plugin\PluginManagerInterface;
Alex Pott
committed
use Drupal\Core\Field\FieldStorageDefinitionListenerInterface;
Angie Byron
committed
/**
* Provides an interface for entity type managers.
*/
interface EntityManagerInterface extends PluginManagerInterface, EntityTypeListenerInterface, EntityBundleListenerInterface, FieldStorageDefinitionListenerInterface, CachedDiscoveryInterface {
Angie Byron
committed
/**
* Builds a list of entity type labels suitable for a Form API options list.
*
Angie Byron
committed
* @param bool $group
* (optional) Whether to group entity types by plugin group (e.g. 'content',
* 'config'). Defaults to FALSE.
*
Angie Byron
committed
* @return array
* An array of entity type labels, keyed by entity type name.
*/
Angie Byron
committed
public function getEntityTypeLabels($group = FALSE);
Angie Byron
committed
/**
* Gets the base field definitions for a content entity type.
Angie Byron
committed
*
* Only fields that are not specific to a given bundle or set of bundles are
* returned. This excludes configurable fields, as they are always attached
* to a specific bundle.
Angie Byron
committed
*
Alex Pott
committed
* @param string $entity_type_id
* The entity type ID. Only entity types that implement
Alex Pott
committed
* \Drupal\Core\Entity\FieldableEntityInterface are supported.
Angie Byron
committed
*
Angie Byron
committed
* @return \Drupal\Core\Field\FieldDefinitionInterface[]
* The array of base field definitions for the entity type, keyed by field
* name.
*
* @throws \LogicException
* Thrown if one of the entity keys is flagged as translatable.
*/
public function getBaseFieldDefinitions($entity_type_id);
/**
* Gets the field definitions for a specific bundle.
Angie Byron
committed
*
* @param string $entity_type_id
* The entity type ID. Only entity types that implement
Alex Pott
committed
* \Drupal\Core\Entity\FieldableEntityInterface are supported.
* @param string $bundle
* The bundle.
*
* @return \Drupal\Core\Field\FieldDefinitionInterface[]
* The array of field definitions for the bundle, keyed by field name.
Angie Byron
committed
*/
public function getFieldDefinitions($entity_type_id, $bundle);
Angie Byron
committed
Alex Pott
committed
/**
* Gets the field storage definitions for a content entity type.
*
* This returns all field storage definitions for base fields and bundle
* fields of an entity type. Note that field storage definitions of a base
* field equal the full base field definition (i.e. they implement
* FieldDefinitionInterface), while the storage definitions for bundle fields
* may implement FieldStorageDefinitionInterface only.
*
* @param string $entity_type_id
* The entity type ID. Only content entities are supported.
*
* @return \Drupal\Core\Field\FieldStorageDefinitionInterface[]
* The array of field storage definitions for the entity type, keyed by
* field name.
*
* @see \Drupal\Core\Field\FieldStorageDefinitionInterface
*/
public function getFieldStorageDefinitions($entity_type_id);
Alex Pott
committed
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
/**
* Gets the entity type's most recently installed field storage definitions.
*
* During the application lifetime, field storage definitions can change. For
* example, updated code can be deployed. The getFieldStorageDefinitions()
* method will always return the definitions as determined by the current
* codebase. This method, however, returns what the definitions were when the
* last time that one of the
* \Drupal\Core\Field\FieldStorageDefinitionListenerInterface events was last
* fired and completed successfully. In other words, the definitions that
* the entity type's handlers have incorporated into the application state.
* For example, if the entity type's storage handler is SQL-based, the
* definitions for which database tables were created.
*
* Application management code can check if getFieldStorageDefinitions()
* differs from getLastInstalledFieldStorageDefinitions() and decide whether
* to:
* - Invoke the appropriate
* \Drupal\Core\Field\FieldStorageDefinitionListenerInterface
* events so that handlers react to the new definitions.
* - Raise a warning that the application state is incompatible with the
* codebase.
* - Perform some other action.
*
* @param string $entity_type_id
* The entity type ID.
*
* @return \Drupal\Core\Field\FieldStorageDefinitionInterface[]
* The array of installed field storage definitions for the entity type,
* keyed by field name.
*
* @see \Drupal\Core\Entity\EntityTypeListenerInterface
*/
public function getLastInstalledFieldStorageDefinitions($entity_type_id);
Alex Pott
committed
/**
* Returns a lightweight map of fields across bundles.
Alex Pott
committed
*
* @return array
* An array keyed by entity type. Each value is an array which keys are
* field names and value is an array with two entries:
* - type: The field type.
* - bundles: The bundles in which the field appears.
*/
public function getFieldMap();
/**
* Returns a lightweight map of fields across bundles filtered by field type.
*
* @param string $field_type
* The field type to filter by.
*
* @return array
* An array keyed by entity type. Each value is an array which keys are
* field names and value is an array with two entries:
* - type: The field type.
* - bundles: The bundles in which the field appears.
*/
public function getFieldMapByFieldType($field_type);
Angie Byron
committed
/**
* Creates a new access control handler instance.
Angie Byron
committed
*
* @param string $entity_type
* The entity type for this access control handler.
Angie Byron
committed
*
* @return \Drupal\Core\Entity\EntityAccessControlHandlerInterface.
* A access control handler instance.
Angie Byron
committed
*/
public function getAccessControlHandler($entity_type);
Angie Byron
committed
/**
catch
committed
* Creates a new storage instance.
Angie Byron
committed
*
* @param string $entity_type
catch
committed
* The entity type for this storage.
Angie Byron
committed
*
catch
committed
* @return \Drupal\Core\Entity\EntityStorageInterface
* A storage instance.
Angie Byron
committed
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
Angie Byron
committed
*/
catch
committed
public function getStorage($entity_type);
Angie Byron
committed
/**
* Get the bundle info of all entity types.
*
* @return array
* An array of all bundle information.
*/
public function getAllBundleInfo();
/**
* {@inheritdoc}
*/
public function clearCachedDefinitions();
/**
* Clears static and persistent field definition caches.
*/
public function clearCachedFieldDefinitions();
/**
* Clears static and persistent bundles.
*/
public function clearCachedBundles();
Angie Byron
committed
/**
* Creates a new view builder instance.
*
* @param string $entity_type
* The entity type for this view builder.
*
* @return \Drupal\Core\Entity\EntityViewBuilderInterface.
Alex Pott
committed
* A view builder instance.
Angie Byron
committed
*/
public function getViewBuilder($entity_type);
/**
* Creates a new entity list builder.
Angie Byron
committed
*
* @param string $entity_type
* The entity type for this list builder.
Angie Byron
committed
*
* @return \Drupal\Core\Entity\EntityListBuilderInterface
* An entity list builder instance.
Angie Byron
committed
*/
public function getListBuilder($entity_type);
Angie Byron
committed
/**
Alex Pott
committed
* Creates a new form instance.
Angie Byron
committed
*
* @param string $entity_type
Alex Pott
committed
* The entity type for this form.
Angie Byron
committed
* @param string $operation
* The name of the operation to use, e.g., 'default'.
*
Alex Pott
committed
* @return \Drupal\Core\Entity\EntityFormInterface
* A form instance.
Angie Byron
committed
*/
Alex Pott
committed
public function getFormObject($entity_type, $operation);
Angie Byron
committed
/**
* Gets all route provider instances.
*
* @param string $entity_type
* The entity type for this route providers.
*
* @return \Drupal\Core\Entity\Routing\EntityRouteProviderInterface[]
*/
public function getRouteProviders($entity_type);
Angie Byron
committed
/**
Alex Pott
committed
* Checks whether a certain entity type has a certain handler.
Angie Byron
committed
*
* @param string $entity_type
* The name of the entity type.
Alex Pott
committed
* @param string $handler_type
* The name of the handler.
Angie Byron
committed
*
* @return bool
Alex Pott
committed
* Returns TRUE if the entity type has the handler, else FALSE.
Angie Byron
committed
*/
Alex Pott
committed
public function hasHandler($entity_type, $handler_type);
Angie Byron
committed
/**
* Creates a new handler instance for a entity type and handler type.
*
* @param string $entity_type
* The entity type for this controller.
Alex Pott
committed
* @param string $handler_type
* The controller type to create an instance for.
*
* @return object
Alex Pott
committed
* A handler instance.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
Alex Pott
committed
public function getHandler($entity_type, $handler_type);
/**
* Creates new handler instance.
*
* Usually \Drupal\Core\Entity\EntityManagerInterface::getHandler() is
* preferred since that method has additional checking that the class exists
* and has static caches.
*
* @param mixed $class
* The handler class to instantiate.
* @param \Drupal\Core\Entity\EntityTypeInterface $definition
* The entity type definition.
*
* @return object
* A handler instance.
*/
public function createHandlerInstance($class, EntityTypeInterface $definition = null);
Angie Byron
committed
/**
* Get the bundle info of an entity type.
*
* @param string $entity_type
* The entity type.
*
* @return array
* Returns the bundle information for the specified entity type.
*/
public function getBundleInfo($entity_type);
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/**
* Retrieves the "extra fields" for a bundle.
*
* @param string $entity_type_id
* The entity type ID.
* @param string $bundle
* The bundle name.
*
* @return array
* A nested array of 'pseudo-field' elements. Each list is nested within the
* following keys: entity type, bundle name, context (either 'form' or
* 'display'). The keys are the name of the elements as appearing in the
* renderable array (either the entity form or the displayed entity). The
* value is an associative array:
* - label: The human readable name of the element. Make sure you sanitize
* this appropriately.
* - description: A short description of the element contents.
* - weight: The default weight of the element.
* - visible: (optional) The default visibility of the element. Defaults to
* TRUE.
* - edit: (optional) String containing markup (normally a link) used as the
* element's 'edit' operation in the administration interface. Only for
* 'form' context.
* - delete: (optional) String containing markup (normally a link) used as the
* element's 'delete' operation in the administration interface. Only for
* 'form' context.
*/
public function getExtraFields($entity_type_id, $bundle);
/**
* Returns the entity translation to be used in the given context.
*
* This will check whether a translation for the desired language is available
* and if not, it will fall back to the most appropriate translation based on
* the provided context.
*
* @param \Drupal\Core\Entity\EntityInterface $entity
* The entity whose translation will be returned.
* @param string $langcode
* (optional) The language of the current context. Defaults to the current
* content language.
* @param array $context
* (optional) An associative array of arbitrary data that can be useful to
* determine the proper fallback sequence.
*
* @return \Drupal\Core\Entity\EntityInterface
* An entity object for the translated data.
*
* @see \Drupal\Core\Language\LanguageManagerInterface::getFallbackCandidates()
*/
public function getTranslationFromContext(EntityInterface $entity, $langcode = NULL, $context = array());
Alex Pott
committed
/**
* {@inheritdoc}
Alex Pott
committed
*
* @return \Drupal\Core\Entity\EntityTypeInterface|null
*/
public function getDefinition($entity_type_id, $exception_on_invalid = TRUE);
Alex Pott
committed
Alex Pott
committed
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
/**
* Returns the entity type definition in its most recently installed state.
*
* During the application lifetime, entity type definitions can change. For
* example, updated code can be deployed. The getDefinition() method will
* always return the definition as determined by the current codebase. This
* method, however, returns what the definition was when the last time that
* one of the \Drupal\Core\Entity\EntityTypeListenerInterface events was last
* fired and completed successfully. In other words, the definition that
* the entity type's handlers have incorporated into the application state.
* For example, if the entity type's storage handler is SQL-based, the
* definition for which database tables were created.
*
* Application management code can check if getDefinition() differs from
* getLastInstalledDefinition() and decide whether to:
* - Invoke the appropriate \Drupal\Core\Entity\EntityTypeListenerInterface
* event so that handlers react to the new definition.
* - Raise a warning that the application state is incompatible with the
* codebase.
* - Perform some other action.
*
* @param string $entity_type_id
* The entity type ID.
*
* @return \Drupal\Core\Entity\EntityTypeInterface|null
* The installed entity type definition, or NULL if the entity type has
* not yet been installed via onEntityTypeCreate().
*
* @see \Drupal\Core\Entity\EntityTypeListenerInterface
*/
public function getLastInstalledDefinition($entity_type_id);
Alex Pott
committed
/**
* {@inheritdoc}
Alex Pott
committed
*
* @return \Drupal\Core\Entity\EntityTypeInterface[]
*/
public function getDefinitions();
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
/**
* Returns the entity view mode info for all entity types.
*
* @return array
* The view mode info for all entity types.
*/
public function getAllViewModes();
/**
* Returns the entity view mode info for a specific entity type.
*
* @param string $entity_type_id
* The entity type whose view mode info should be returned.
*
* @return array
* The view mode info for a specific entity type.
*/
public function getViewModes($entity_type_id);
/**
* Returns the entity form mode info for all entity types.
*
* @return array
* The form mode info for all entity types.
*/
public function getAllFormModes();
/**
* Returns the entity form mode info for a specific entity type.
*
* @param string $entity_type_id
* The entity type whose form mode info should be returned.
*
* @return array
* The form mode info for a specific entity type.
*/
public function getFormModes($entity_type_id);
/**
* Returns an array of view mode options.
*
* @param string $entity_type_id
* The entity type whose view mode options should be returned.
* @param bool $include_disabled
* Force to include disabled view modes. Defaults to FALSE.
*
* @return array
* An array of view mode labels, keyed by the display mode ID.
*/
public function getViewModeOptions($entity_type_id, $include_disabled = FALSE);
/**
* Returns an array of form mode options.
*
* @param string $entity_type_id
* The entity type whose form mode options should be returned.
* @param bool $include_disabled
* Force to include disabled form modes. Defaults to FALSE.
*
* @return array
* An array of form mode labels, keyed by the display mode ID.
*/
public function getFormModeOptions($entity_type_id, $include_disabled = FALSE);
Alex Pott
committed
/**
* Loads an entity by UUID.
*
* Note that some entity types may not support UUIDs.
*
* @param string $entity_type_id
* The entity type ID to load from.
* @param string $uuid
* The UUID of the entity to load.
*
Alex Pott
committed
* @return \Drupal\Core\Entity\EntityInterface|null
* The entity object, or NULL if there is no entity with the given UUID.
Alex Pott
committed
*
* @throws \Drupal\Core\Entity\EntityStorageException
* Thrown in case the requested entity type does not support UUIDs.
*/
public function loadEntityByUuid($entity_type_id, $uuid);
Alex Pott
committed
/**
* Loads an entity by the config target identifier.
*
* @param string $entity_type_id
* The entity type ID to load from.
* @param string $target
* The configuration target to load, as returned from
* \Drupal\Core\Entity\EntityInterface::getConfigTarget().
*
Alex Pott
committed
* @return \Drupal\Core\Entity\EntityInterface|null
* The entity object, or NULL if there is no entity with the given config
* target identifier.
Alex Pott
committed
*
* @throws \Drupal\Core\Entity\EntityStorageException
* Thrown if the target identifier is a UUID but the entity type does not
* support UUIDs.
*
* @see \Drupal\Core\Entity\EntityInterface::getConfigTarget()
*/
public function loadEntityByConfigTarget($entity_type_id, $target);
Alex Pott
committed
/**
* Returns the entity type ID based on the class that is called on.
*
* Compares the class this is called on against the known entity classes
* and returns the entity type ID of a direct match or a subclass as fallback,
* to support entity type definitions that were altered.
*
* @param string $class_name
* Class name to use for searching the entity type ID.
*
* @return string
* The entity type ID.
*
* @throws \Drupal\Core\Entity\Exception\AmbiguousEntityClassException
* Thrown when multiple subclasses correspond to the called class.
* @throws \Drupal\Core\Entity\Exception\NoCorrespondingEntityClassException
* Thrown when no entity class corresponds to the called class.
*
* @see \Drupal\Core\Entity\Entity::load()
* @see \Drupal\Core\Entity\Entity::loadMultiple()
*/
public function getEntityTypeFromClass($class_name);