Problem/Motivation

We have a use case where the translator service wants to filter out content based on a set of criteria before the job is created. We couldn't find an appropriate place to do that.

Proposed resolution

Add an event and invoke it in \Drupal\tmgmt\ContinuousManager::addItem

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Primsi created an issue. See original summary.

Primsi’s picture

Status: Active » Needs review
FileSize
6.56 KB

Initial patch, no tests yet.

Primsi’s picture

Starting with tests, not sure if this is the direction we want to go.

Berdir’s picture

Status: Needs review » Needs work
  1. +++ b/src/ContinuousManager.php
    @@ -119,7 +130,12 @@ class ContinuousManager {
    +    $this->eventDispatcher->dispatch(TmgmtEvents::SHOULD_CREATE_JOB, $event);
    

    I think it makes more sense to name that class ContinuousEvents.

  2. +++ b/src/Events/ShouldCreateJobEvent.php
    @@ -0,0 +1,132 @@
    + * Implementation of SHOULD_CREATE_JOB event.
    + *
    + * This class recives the same arguments as
    + * \Drupal\tmgmt\ContinuousSourceInterface::shouldCreateContinuousItem().
    + */
    +class ShouldCreateJobEvent extends Event {
    

    I'll try to improve the docs a bit here.

  3. +++ b/src/Events/ShouldCreateJobEvent.php
    @@ -0,0 +1,132 @@
    +   * @var \Drupal\tmgmt\Entity\Job
    

    ...Interface

  4. +++ b/src/Events/ShouldCreateJobEvent.php
    @@ -0,0 +1,132 @@
    +   * The plugin name.
    

    .. ID

  5. +++ b/src/Events/ShouldCreateJobEvent.php
    @@ -0,0 +1,132 @@
    +   * EntityUsageEvents constructor.
    

    .

  6. +++ b/src/Events/ShouldCreateJobEvent.php
    @@ -0,0 +1,132 @@
    +   *   A flag stating wheter or not the job should be created.
    

    whether

  7. +++ b/src/Events/TmgmtEvents.php
    @@ -0,0 +1,17 @@
    +  /**
    +   * SHOULD_CREATE_JOB event occurs when determining if a job should be created.
    +   *
    

    improve this a bit as well.

  8. +++ b/src/Tests/TranslatorTest.php
    @@ -202,4 +202,44 @@ class TranslatorTest extends TMGMTTestBase {
    +  /**
    +   * Test tmgmt events.
    +   */
    +  public function testTmgmtEvents() {
    +    $translator = parent::createTranslator();
    

    continuous events

  9. +++ b/src/Tests/TranslatorTest.php
    @@ -202,4 +202,44 @@ class TranslatorTest extends TMGMTTestBase {
    +    // Test that SHOULD_CREATE_JOB event works.
    +    $node = [
    +      'type' => 'article',
    +      'langcode' => 'en',
    +      'title' => 'Testing SHOULD_CREATE_JOB event'
    +    ];
    +
    +    $this->createNode($node);
    +    $this->drupalGet('admin/tmgmt/job_items?state=All&source_language=All&target_language=All&job_type=All');
    +    $this->assertNoText('Testing SHOULD_CREATE_JOB event');
    

    I think it's better to avoid the UI and just check if we have any jobs here, and then create a node with a different label that will be added.

  10. +++ b/tmgmt_test/src/EventSubscriber/TestTmgmtEventsSubscriber.php
    @@ -0,0 +1,55 @@
    +
    +  /**
    +   * GloballinkTmgmtEvents constructor.
    +   */
    +  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    

    .

Berdir’s picture

Status: Needs work » Needs review
FileSize
14.95 KB
15.33 KB

Cleanup and moved the test to the existing kernel test coverage, just requires a few additional lines then.

interdiff is very big but it's mostly just comment changes and the moving the test.

Berdir’s picture

Status: Needs review » Fixed

Committed.

  • Berdir committed 458018c on 8.x-1.x
    Issue #2933917 by Primsi, Berdir: Allow other modules to prevent...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.