diff --git a/integer_to_decimal.info.yml b/integer_to_decimal.info.yml index e638d32c2fd0d78117e40cb1642c64014f36f102..ba3c79d7b382e4903ec6b344605f9da9bd557962 100644 --- a/integer_to_decimal.info.yml +++ b/integer_to_decimal.info.yml @@ -2,6 +2,6 @@ name: Field Updater type: module description: 'Changes field type numeric with data to field type decimal.' package: Other -core_version_requirement: ^8 || ^9 +core_version_requirement: ^8 || ^9 || ^10 dependencies: - - node + - drupal:node diff --git a/integer_to_decimal.services.yml b/integer_to_decimal.services.yml index a000d9a712786aa60d61f354c3f7f6b131055b74..d1687f27631bac9f1606873f4e35acf90afb4014 100644 --- a/integer_to_decimal.services.yml +++ b/integer_to_decimal.services.yml @@ -1,4 +1,4 @@ services: field_updater: class: Drupal\integer_to_decimal\Service\FieldUpdaterService - arguments: ['@database', '@entity_type.manager', '@config.factory', '@messenger'] \ No newline at end of file + arguments: ['@database', '@entity_type.manager', '@config.factory', '@messenger', '@entity_field.manager'] diff --git a/src/Service/FieldUpdaterService.php b/src/Service/FieldUpdaterService.php index a3efd544894c90e60478d1fcaf51cb041fecb125..f283b457a7939b3ada7481a33f74879abf898485 100644 --- a/src/Service/FieldUpdaterService.php +++ b/src/Service/FieldUpdaterService.php @@ -2,6 +2,7 @@ namespace Drupal\integer_to_decimal\Service; +use Drupal\Core\Entity\EntityFieldManagerInterface; use Drupal\Core\Messenger\MessengerInterface; use Drupal\Core\StringTranslation\StringTranslationTrait; use Drupal\field\Entity\FieldConfig; @@ -18,40 +19,28 @@ use Drupal\Core\Config\ConfigFactoryInterface; */ class FieldUpdaterService implements FieldUpdaterServiceInterface { use StringTranslationTrait; - - /** - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - /** - * @var \Drupal\Core\Database\Connection - */ - protected $connection; - - /** - * @var \Drupal\Core\Config\ConfigFactoryInterface - */ - protected $configFactory; - /** - * @var \Drupal\Core\Messenger\MessengerInterface $messenger - */ - protected $messenger; + protected EntityTypeManagerInterface $entityTypeManager; + protected Connection $connection; + protected ConfigFactoryInterface $configFactory; + protected MessengerInterface $messenger; + protected EntityFieldManagerInterface $entityFieldManager; /** * FieldUpdaterService constructor. * - * @param \Drupal\Core\Database\Connection $connection - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager - * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory - * @param \Drupal\Core\Messenger\MessengerInterface $messenger + * @param Connection $connection + * @param EntityTypeManagerInterface $entityTypeManager + * @param ConfigFactoryInterface $configFactory + * @param MessengerInterface $messenger + * @param EntityFieldManagerInterface $entityFieldManager */ public function __construct(Connection $connection, EntityTypeManagerInterface $entityTypeManager, - ConfigFactoryInterface $configFactory, MessengerInterface $messenger) { + ConfigFactoryInterface $configFactory, MessengerInterface $messenger, EntityFieldManagerInterface $entityFieldManager) { $this->connection = $connection; $this->entityTypeManager = $entityTypeManager; $this->configFactory = $configFactory; $this->messenger = $messenger; + $this->entityFieldManager = $entityFieldManager; } /** @@ -62,11 +51,11 @@ class FieldUpdaterService implements FieldUpdaterServiceInterface { $database = $this->connection; $existingData = []; $tables = []; - - $entity_type_manager = \Drupal::getContainer()->get('entity_type.manager'); + //$entity_type_manager = \Drupal::getContainer()->get('entity_type.manager'); + //$entity_field_manager = \Drupal::getContainer()->get('entity_field.manager'); // Get an instance of Drupal\Core\Entity\Sql\DefaultTableMapping class - $table_mapping = $entity_type_manager->getStorage('node')->getTableMapping(); - $storage_definitions = $entity_type_manager->getFieldStorageDefinitions($entity_type); + $table_mapping = $this->entityTypeManager->getStorage($entity_type)->getTableMapping(); + $storage_definitions = $this->entityFieldManager->getFieldStorageDefinitions($entity_type); $data_table = $table_mapping->getDedicatedDataTableName($storage_definitions[$field]); if ($data_table) { $tables[] = $data_table; diff --git a/src/Service/FieldUpdaterServiceInterface.php b/src/Service/FieldUpdaterServiceInterface.php index 27860f63ab736068d365f85da55ef311feca2c17..8e7a2bfabbaab8fe9563e42523d44e8a2e1ffd41 100644 --- a/src/Service/FieldUpdaterServiceInterface.php +++ b/src/Service/FieldUpdaterServiceInterface.php @@ -2,6 +2,8 @@ namespace Drupal\integer_to_decimal\Service; +use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; + /** * provides an interface for Field Updater services. * @@ -17,14 +19,20 @@ interface FieldUpdaterServiceInterface * @param string $type * Field type such as integer, decimal * + * @param $entity_type + * The entity machine name + * * @param string $bundle * The bundle to which the converted field is associated with * - * @param integer $precision precision associated with decimal field type + * @param integer $precision + * precision associated with decimal field type + * + * @param integer $scale + * scale associated with decimal field type * - *@param integer $scale scale associated with decimal field type * - * @return mixed + * @throws InvalidPluginDefinitionException */ public function fieldUpdater($field, $type, $entity_type, $bundle, $precision, $scale); }