Skip to content
Snippets Groups Projects

Issue #3121085: Replace drupal_set_message() with messenger Service and drupal 9 compatability.

Open Issue #3121085: Replace drupal_set_message() with messenger Service and drupal 9 compatability.
Open Jaydev Bhatt requested to merge issue/hti-3121085:3121085-messenger-service into 8.x-1.x
1 file
+ 3
16
Compare changes
  • Side-by-side
  • Inline
@@ -8,7 +8,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\hierarchical_taxonomy_importer\services\ImporterService;
use Drupal\taxonomy\Entity\Vocabulary;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\File\FileSystemInterface;
/**
@@ -23,13 +22,6 @@ class TaxonomyImporterForm extends FormBase {
*/
protected $entityTypeManager;
/**
* The messenger service.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* The hierarchical taxonomy importer service.
*
@@ -51,20 +43,16 @@ class TaxonomyImporterForm extends FormBase {
* The entity type manager.
* @param \Drupal\hierarchical_taxonomy_importer\services\ImporterService $hierarchical_taxonomy_importer_importer
* The hierarchical taxonomy importer service.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The messenger service.
* @param \Drupal\Core\File\FileSystemInterface $file_system
* The file system service.
*/
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
ImporterService $hierarchical_taxonomy_importer_importer,
MessengerInterface $messenger,
FileSystemInterface $file_system,
) {
$this->entityTypeManager = $entity_type_manager;
$this->hierarchicalTaxonomyImporter = $hierarchical_taxonomy_importer_importer;
$this->messenger = $messenger;
$this->fileSystem = $file_system;
}
@@ -75,7 +63,6 @@ class TaxonomyImporterForm extends FormBase {
return new static(
$container->get('entity_type.manager'),
$container->get('hierarchical_taxonomy_importer.importer'),
$container->get('messenger'),
$container->get('file_system')
);
}
@@ -162,14 +149,14 @@ class TaxonomyImporterForm extends FormBase {
try {
$this->hierarchicalTaxonomyImporter->import($vid, $output);
$this->messenger->addStatus($this->t('All terms have been imported successfully.'));
$this->messenger()->addStatus($this->t('All terms have been imported successfully.'));
}
catch (\Exception $e) {
$this->messenger->addError($this->t('An error occurred during import: @error', ['@error' => $e->getMessage()]));
$this->messenger()->addError($this->t('An error occurred during import: @error', ['@error' => $e->getMessage()]));
}
}
else {
$this->messenger->addError($this->t('Could not open the CSV file for reading.'));
$this->messenger()->addError($this->t('Could not open the CSV file for reading.'));
}
}
Loading