Skip to content
Snippets Groups Projects

Issue #3298245: Hook to allow modules to alter translation entity being created

Open Edouard Cunibil requested to merge issue/tmgmt-3298245:3298245-hook-to-allow into 8.x-1.x
Files
2
@@ -24,6 +24,9 @@ use Drupal\tmgmt\TMGMTException;
use Drupal\Core\Render\Element;
use Drupal\Core\Form\FormStateInterface;
use Drupal\tmgmt\Entity\Job;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Content entity source plugin controller.
@@ -35,7 +38,44 @@ use Drupal\tmgmt\Entity\Job;
* ui = "Drupal\tmgmt_content\ContentEntitySourcePluginUi"
* )
*/
class ContentEntitySource extends SourcePluginBase implements SourcePreviewInterface, ContinuousSourceInterface {
class ContentEntitySource extends SourcePluginBase implements ContainerFactoryPluginInterface, SourcePreviewInterface, ContinuousSourceInterface {
/**
* The module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Construct an instance of the content entity source plugin.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->moduleHandler = $module_handler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('module_handler')
);
}
/**
* Returns the entity for the given job item.
@@ -624,6 +664,12 @@ class ContentEntitySource extends SourcePluginBase implements SourcePreviewInter
}
}
$this->moduleHandler->invokeAll('tmgmt_content_presave_translation', [
$translation,
$entity,
$data,
]);
if ($save) {
$translation->save();
}
Loading