Chris@0: fieldStorageConfigStorage = $entity_type_manager->getStorage('field_storage_config'); Chris@0: $this->stringTranslation = $string_translation; Chris@0: $this->fieldTypeManager = $field_type_manager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function validate($module) { Chris@0: $reasons = []; Chris@0: if ($field_storages = $this->getFieldStoragesByModule($module)) { Chris@0: // Provide an explanation message (only mention pending deletions if there Chris@0: // remain no actual, non-deleted fields.) Chris@0: $fields_in_use = []; Chris@0: foreach ($field_storages as $field_storage) { Chris@0: if (!$field_storage->isDeleted()) { Chris@0: $fields_in_use[$field_storage->getType()][] = $field_storage->getLabel(); Chris@0: } Chris@0: } Chris@0: if (!empty($fields_in_use)) { Chris@0: foreach ($fields_in_use as $field_type => $field_storages) { Chris@0: $field_type_label = $this->getFieldTypeLabel($field_type); Chris@0: $reasons[] = $this->formatPlural(count($fields_in_use[$field_type]), 'The %field_type_label field type is used in the following field: @fields', 'The %field_type_label field type is used in the following fields: @fields', ['%field_type_label' => $field_type_label, '@fields' => implode(', ', $field_storages)]); Chris@0: } Chris@0: } Chris@0: else { Chris@0: $reasons[] = $this->t('Fields pending deletion'); Chris@0: } Chris@0: } Chris@0: return $reasons; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns all field storages for a specified module. Chris@0: * Chris@0: * @param string $module Chris@0: * The module to filter field storages by. Chris@0: * Chris@0: * @return \Drupal\field\FieldStorageConfigInterface[] Chris@0: * An array of field storages for a specified module. Chris@0: */ Chris@0: protected function getFieldStoragesByModule($module) { Chris@0: return $this->fieldStorageConfigStorage->loadByProperties(['module' => $module, 'include_deleted' => TRUE]); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns the label for a specified field type. Chris@0: * Chris@0: * @param string $field_type Chris@0: * The field type. Chris@0: * Chris@0: * @return string Chris@0: * The field type label. Chris@0: */ Chris@0: protected function getFieldTypeLabel($field_type) { Chris@0: return $this->fieldTypeManager->getDefinitions()[$field_type]['label']; Chris@0: } Chris@0: Chris@0: }