Chris@0: entityManager = $entity_manager; Chris@0: $this->fieldTypeManager = $field_type_manager; Chris@14: $this->deletedFieldsRepository = $deleted_fields_repository; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { Chris@0: return new static( Chris@0: $entity_type, Chris@0: $container->get('config.factory'), Chris@0: $container->get('uuid'), Chris@0: $container->get('language_manager'), Chris@0: $container->get('entity.manager'), Chris@14: $container->get('plugin.manager.field.field_type'), Chris@17: $container->get('entity_field.deleted_fields_repository'), Chris@17: $container->get('entity.memory_cache') Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function importDelete($name, Config $new_config, Config $old_config) { Chris@0: // If the field storage has been deleted in the same import, the field will Chris@0: // be deleted by then, and there is nothing left to do. Just return TRUE so Chris@0: // that the file does not get written to active store. Chris@0: if (!$old_config->get()) { Chris@0: return TRUE; Chris@0: } Chris@0: return parent::importDelete($name, $new_config, $old_config); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function loadByProperties(array $conditions = []) { Chris@0: // Include deleted fields if specified in the $conditions parameters. Chris@0: $include_deleted = isset($conditions['include_deleted']) ? $conditions['include_deleted'] : FALSE; Chris@0: unset($conditions['include_deleted']); Chris@0: Chris@0: $fields = []; Chris@0: Chris@0: // Get fields stored in configuration. If we are explicitly looking for Chris@0: // deleted fields only, this can be skipped, because they will be Chris@14: // retrieved from the deleted fields repository below. Chris@0: if (empty($conditions['deleted'])) { Chris@0: if (isset($conditions['entity_type']) && isset($conditions['bundle']) && isset($conditions['field_name'])) { Chris@0: // Optimize for the most frequent case where we do have a specific ID. Chris@0: $id = $conditions['entity_type'] . '.' . $conditions['bundle'] . '.' . $conditions['field_name']; Chris@0: $fields = $this->loadMultiple([$id]); Chris@0: } Chris@0: else { Chris@0: // No specific ID, we need to examine all existing fields. Chris@0: $fields = $this->loadMultiple(); Chris@0: } Chris@0: } Chris@0: Chris@14: // Merge deleted fields from the deleted fields repository if needed. Chris@0: if ($include_deleted || !empty($conditions['deleted'])) { Chris@14: $deleted_field_definitions = $this->deletedFieldsRepository->getFieldDefinitions(); Chris@14: foreach ($deleted_field_definitions as $id => $field_definition) { Chris@14: if ($field_definition instanceof FieldConfigInterface) { Chris@14: $fields[$id] = $field_definition; Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: // Collect matching fields. Chris@0: $matching_fields = []; Chris@0: foreach ($fields as $field) { Chris@0: // Some conditions are checked against the field storage. Chris@0: $field_storage = $field->getFieldStorageDefinition(); Chris@0: Chris@0: // Only keep the field if it matches all conditions. Chris@0: foreach ($conditions as $key => $value) { Chris@0: // Extract the actual value against which the condition is checked. Chris@0: switch ($key) { Chris@0: case 'field_name': Chris@0: $checked_value = $field_storage->getName(); Chris@0: break; Chris@0: Chris@0: case 'field_id': Chris@0: case 'field_storage_uuid': Chris@0: $checked_value = $field_storage->uuid(); Chris@0: break; Chris@0: Chris@0: case 'uuid'; Chris@0: $checked_value = $field->uuid(); Chris@0: break; Chris@0: Chris@0: case 'deleted'; Chris@0: $checked_value = $field->isDeleted(); Chris@0: break; Chris@0: Chris@0: default: Chris@0: $checked_value = $field->get($key); Chris@0: break; Chris@0: } Chris@0: Chris@0: // Skip to the next field as soon as one condition does not match. Chris@0: if ($checked_value != $value) { Chris@0: continue 2; Chris@0: } Chris@0: } Chris@0: Chris@0: // When returning deleted fields, key the results by UUID since they Chris@0: // can include several fields with the same ID. Chris@0: $key = $include_deleted ? $field->uuid() : $field->id(); Chris@0: $matching_fields[$key] = $field; Chris@0: } Chris@0: Chris@0: return $matching_fields; Chris@0: } Chris@0: Chris@0: }