I am using the ‘Path Redirect Import module along with the Redirect module.
I am trying to override its service ‘path_redirect_import.importer’
To do this, I have added a service provider and a custom class that extends the service class that I want to override.
however, the overridden function is not getting called.
Followed this tutorial:
Any suggestions?
inside my custom module's src folder, I created MyModuleServiceProvider.php, which contains the following:
namespace Drupal\my_module;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ServiceModifierInterface;
use Drupal\Core\DependencyInjection\ServiceProviderBase;
class MyModuleServiceProvider extends ServiceProviderBase implements ServiceModifierInterface {
public function alter(ContainerBuilder $container) {
if ($container->hasDefinition('path_redirect_import.importer')) {
$definition = $container->getDefinition('path_redirect_import.importer');
$definition->setClass('Drupal\my_module\MyTestProv');
}
}
}
in the MyTestProv.php
namespace Drupal\my_module;
use Drupal\path_redirect_import\ImporterService;
/**
* Class ImporterService.
*
* @package Drupal\path_redirect_import
*/
class MyTestProv extends ImporterService {
public static function import($file, array $options) {
// If I put something here nothing happens
\Drupal::messenger()->addMessage(t('Lorem ipsum.'));
}
}