DynamicallyFieldableEntityStorageInterface.php 3.4 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\Core\Entity\DynamicallyFieldableEntityStorageInterface.
6 7 8 9
 */

namespace Drupal\Core\Entity;

10 11
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
12
use Drupal\Core\Field\FieldStorageDefinitionListenerInterface;
13

14 15 16 17 18 19 20 21 22 23
/**
 * A storage that supports entity types with dynamic field definitions.
 *
 * A storage that implements this interface can react to the entity type's field
 * definitions changing, due to modules being installed or uninstalled, or via
 * field UI, or via code changes to the entity class.
 *
 * For example, configurable fields defined and exposed by field.module.
 */
interface DynamicallyFieldableEntityStorageInterface extends EntityStorageInterface, FieldStorageDefinitionListenerInterface {
24
  /**
25
   * Reacts to the creation of a field.
26
   *
27 28
   * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
   *   The field definition created.
29
   */
30
  public function onFieldDefinitionCreate(FieldDefinitionInterface $field_definition);
31 32

  /**
33
   * Reacts to the update of a field.
34
   *
35 36
   * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
   *   The field definition being updated.
37
   * @param \Drupal\Core\Field\FieldDefinitionInterface $original
38
   *   The original field definition; i.e., the definition before the update.
39
   */
40
  public function onFieldDefinitionUpdate(FieldDefinitionInterface $field_definition, FieldDefinitionInterface $original);
41 42

  /**
43
   * Reacts to the deletion of a field.
44 45 46 47
   *
   * Stored values should not be wiped at once, but marked as 'deleted' so that
   * they can go through a proper purge process later on.
   *
48 49
   * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
   *   The field definition being deleted.
50
   *
51
   * @see purgeFieldData()
52
   */
53
  public function onFieldDefinitionDelete(FieldDefinitionInterface $field_definition);
54 55

  /**
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
   * Purges a batch of field data.
   *
   * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
   *   The deleted field whose data is being purged.
   * @param $batch_size
   *   The maximum number of field data records to purge before returning,
   *   relating to the count of field data records returned by
   *   \Drupal\Core\Entity\FieldableEntityStorageInterface::countFieldData().
   *
   * @return int
   *   The number of field data records that have been purged.
   */
  public function purgeFieldData(FieldDefinitionInterface $field_definition, $batch_size);

  /**
   * Determines the number of entities with values for a given field.
   *
   * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
   *   The field for which to count data records.
   * @param bool $as_bool
   *   (Optional) Optimises the query for checking whether there are any records
   *   or not. Defaults to FALSE.
78
   *
79 80 81
   * @return bool|int
   *   The number of entities. If $as_bool parameter is TRUE then the
   *   value will either be TRUE or FALSE.
82
   *
83
   * @see \Drupal\Core\Entity\FieldableEntityStorageInterface::purgeFieldData()
84
   */
85
  public function countFieldData($storage_definition, $as_bool = FALSE);
86 87

  /**
88
   * Performs final cleanup after all data of a field has been purged.
89
   *
90
   * @param \Drupal\Core\Field\FieldStorageDefinitionInterface $storage_definition
91 92
   *   The field being purged.
   */
93
  public function finalizePurge(FieldStorageDefinitionInterface $storage_definition);
94 95

}