Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event action on entity translation delete #780

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions modules/next/next.module
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,11 @@ function next_entity_predelete(EntityInterface $entity) {
$event = EntityActionEvent::createFromEntity($entity, EntityActionEventInterface::DELETE_ACTION);
\Drupal::service('next.entity_action_event_dispatcher')->addEvent($event);
}

/**
* Implements hook_entity_translation_delete().
*/
function next_entity_translation_delete(EntityInterface $translation) {
$event = EntityActionEvent::createFromEntity($translation, EntityActionEventInterface::DELETE_ACTION);
\Drupal::service('next.entity_action_event_dispatcher')->addEvent($event);
}
15 changes: 14 additions & 1 deletion modules/next/tests/src/Kernel/Event/EntityActionEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\Core\Database\Database;
use Drupal\dblog\Controller\DbLogController;
use Drupal\KernelTests\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -30,6 +31,8 @@ class EntityActionEventTest extends KernelTestBase {
'system',
'user',
'dblog',
'content_translation',
'language',
];

/**
Expand All @@ -40,7 +43,7 @@ protected function setUp(): void {

$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installConfig(['filter', 'next', 'system', 'user']);
$this->installConfig(['filter', 'next', 'system', 'user', 'language']);
$this->installSchema('dblog', ['watchdog']);
$this->installSchema('system', ['sequences']);
$this->installSchema('node', ['node_access']);
Expand All @@ -52,13 +55,17 @@ protected function setUp(): void {
'label' => 'Page',
]);
$page_type->save();

// Set up multilingual.
ConfigurableLanguage::createFromLangcode('nl')->save();
}

/**
* Test entity action events.
*/
public function testEntityActionEvents() {
$page = $this->createNode(['type' => 'page', 'title' => 'A page']);
$page->addTranslation('nl', ['title' => 'Translation']);

// Insert.
$page->save();
Expand All @@ -70,6 +77,12 @@ public function testEntityActionEvents() {
$this->container->get('kernel')->terminate(Request::create('/'), new Response());
$this->assertLogsContains("Event next.entity.action dispatched for entity A page updated and action update.");

// Delete translation.
$page->removeTranslation('nl');
$page->save();
$this->container->get('kernel')->terminate(Request::create('/'), new Response());
$this->assertLogsContains("Event next.entity.action dispatched for entity Translation and action delete.");

// Delete.
$page->delete();
$this->container->get('kernel')->terminate(Request::create('/'), new Response());
Expand Down
13 changes: 13 additions & 0 deletions modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\Core\Database\Database;
use Drupal\dblog\Controller\DbLogController;
use Drupal\KernelTests\KernelTestBase;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\next\Entity\NextEntityTypeConfig;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -30,6 +31,8 @@ class EntityRevalidatedEventTest extends KernelTestBase {
'system',
'user',
'dblog',
'content_translation',
'language',
];

/**
Expand All @@ -47,6 +50,9 @@ protected function setUp(): void {
$this->installSchema('node', ['node_access']);
$this->installSchema('user', ['users_data']);

// Set up multilingual.
ConfigurableLanguage::createFromLangcode('nl')->save();

// Create entity type config.
$entity_type_config = NextEntityTypeConfig::create([
'id' => 'node.page',
Expand All @@ -69,6 +75,7 @@ protected function setUp(): void {
*/
public function testEntityRevalidatedEvents() {
$page = $this->createNode(['type' => 'page', 'title' => 'A page']);
$page->addTranslation('nl', ['title' => 'Translation']);

// Insert.
$page->save();
Expand All @@ -80,6 +87,12 @@ public function testEntityRevalidatedEvents() {
$this->container->get('kernel')->terminate(Request::create('/'), new Response());
$this->assertLogsContains("Entity A page updated, action update, revalidated 0.");

// Delete translation.
$page->removeTranslation('nl');
$page->save();
$this->container->get('kernel')->terminate(Request::create('/'), new Response());
$this->assertLogsContains("Entity Translation, action delete, revalidated 0.");

// Delete.
$page->delete();
$this->container->get('kernel')->terminate(Request::create('/'), new Response());
Expand Down