/** * Gets a list of changes to entity type and field storage definitions. * * @return array * An associative array keyed by entity type id of change descriptors. Every * entry is an associative array with the following optional keys: * - entity_type: a scalar having only the DEFINITION_UPDATED value. * - field_storage_definitions: an associative array keyed by field name of * scalars having one value among: * - DEFINITION_CREATED * - DEFINITION_UPDATED * - DEFINITION_DELETED */ protected function getChangeList() { $this->entityManager->useCaches(FALSE); $change_list = array(); foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { $original = $this->entityManager->getLastInstalledDefinition($entity_type_id); // @todo Support non-storage-schema-changing definition updates too: // https://www.drupal.org/node/2336895. if (!$original) { $change_list[$entity_type_id]['entity_type'] = static::DEFINITION_CREATED; } else { if ($this->requiresEntityStorageSchemaChanges($entity_type, $original)) { $change_list[$entity_type_id]['entity_type'] = static::DEFINITION_UPDATED; } if ($this->entityManager->getStorage($entity_type_id) instanceof DynamicallyFieldableEntityStorageInterface) { $field_changes = array(); $storage_definitions = $this->entityManager->getFieldStorageDefinitions($entity_type_id); $original_storage_definitions = $this->entityManager->getLastInstalledFieldStorageDefinitions($entity_type_id); // Detect created field storage definitions. foreach (array_diff_key($storage_definitions, $original_storage_definitions) as $field_name => $storage_definition) { $field_changes[$field_name] = static::DEFINITION_CREATED; } // Detect deleted field storage definitions. foreach (array_diff_key($original_storage_definitions, $storage_definitions) as $field_name => $original_storage_definition) { $field_changes[$field_name] = static::DEFINITION_DELETED; } // Detect updated field storage definitions. foreach (array_intersect_key($storage_definitions, $original_storage_definitions) as $field_name => $storage_definition) { // @todo Support non-storage-schema-changing definition updates too: // https://www.drupal.org/node/2336895. So long as we're checking // based on schema change requirements rather than definition // equality, skip the check if the entity type itself needs to be // updated, since that can affect the schema of all fields, so we // want to process that update first without reporting false // positives here. if (!isset($change_list[$entity_type_id]['entity_type']) && $this->requiresFieldStorageSchemaChanges($storage_definition, $original_storage_definitions[$field_name])) { $field_changes[$field_name] = static::DEFINITION_UPDATED; } } if ($field_changes) { $change_list[$entity_type_id]['field_storage_definitions'] = $field_changes; } } } } // @todo Support deleting entity definitions when we support base field // purging. See https://www.drupal.org/node/2282119. $this->entityManager->useCaches(TRUE); return array_filter($change_list); }
/** * Reloads the specified entity. * * @param \Drupal\entity_test\Entity\EntityTest $entity * An entity object. * * @return \Drupal\entity_test\Entity\EntityTest * The reloaded entity object. */ protected function reloadEntity(EntityTest $entity) { $this->entityManager->useCaches(FALSE); $this->entityManager->getStorage('entity_test')->resetCache([$entity->id()]); return EntityTest::load($entity->id()); }
/** * {@inheritdoc} */ public function useCaches($use_caches = FALSE) { $this->entityManager->useCaches($use_caches = FALSE); }