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

Gatsby references #1431

Merged
merged 4 commits into from
Oct 10, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ _core:
local_task_enabled_entity_types:
- media
- node
- taxonomy_term
track_enabled_source_entity_types:
- node
- block_content
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,26 @@ use Drupal\user\UserInterface;


function _silverback_gatsby_entity_event(EntityInterface $entity) {
\Drupal::service('silverback_gatsby.update_handler')->handle(EntityFeed::class, $entity);
/** @var \Drupal\silverback_gatsby\GatsbyUpdateHandler $updateHandler */
$updateHandler = \Drupal::service('silverback_gatsby.update_handler');
$updateHandler->handle(EntityFeed::class, $entity);

if (\Drupal::hasService('entity_usage.usage')) {
/** @var \Drupal\entity_usage\EntityUsage $entityUsage */
$entityUsage = \Drupal::service('entity_usage.usage');
foreach ($entityUsage->listSources($entity) as $sourceEntityType => $sources) {
$entities = \Drupal::entityTypeManager()
->getStorage($sourceEntityType)
->loadMultiple(array_keys($sources));
foreach ($entities as $source) {
$updateHandler->handle(EntityFeed::class, $source);
}
}
}
}

/**
* Implements hook_entity_create().
* Implements hook_entity_insert().
*/
function silverback_gatsby_entity_insert(EntityInterface $entity) {
_silverback_gatsby_entity_event($entity);
Expand All @@ -36,12 +51,24 @@ function silverback_gatsby_entity_update(EntityInterface $entity) {
}

/**
* Implements hook_entity_delete().
* Implements hook_entity_predelete().
*/
function silverback_gatsby_entity_delete(EntityInterface $entity) {
function silverback_gatsby_entity_predelete(EntityInterface $entity) {
_silverback_gatsby_entity_event($entity);
}

/**
* Implements hook_module_implements_alter().
*/
function silverback_gatsby_module_implements_alter(&$implementations, $hook) {
// Act before entity_usage module.
if (in_array($hook, ['entity_insert', 'entity_update', 'entity_predelete'], TRUE)) {
$implementations = [
'silverback_gatsby' => $implementations['silverback_gatsby'],
] + $implementations;
}
}

/**
* Implements hook_entity_type_alter().
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
drupal,
drupalLogin,
gatsby,
resetState,
waitForGatsby,
} from '@amazeelabs/silverback-playwright';
import { expect, test } from '@playwright/test';

test.beforeAll(async () => {
await resetState();
});

test('@gatsby-build references', async ({ page }) => {
Copy link
Member Author

@Leksat Leksat Oct 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should have fallen on the test commit, yet it did not. I don't know why.

Locally it fails properly. But in CI an incremental Gatsby build sources all nodes for some reason.

Another evidence that we need to get rid of @amazeelabs/silverback-playwright ASAP. Will do in a separate PR.

// Check the tag present on the page.
await page.goto(gatsby.baseUrl);
await page.click('a:text-is("With everything")');
await expect(page.locator(':text("Tag 1")')).toHaveCount(1);

// Remove the tag.
await drupalLogin(page);
await page.goto(
`${drupal.baseUrl}/admin/structure/taxonomy/manage/tag/overview`,
);
await page.click(
'.dropbutton-wrapper :text-is("Edit"):right-of(:text-is("Tag 1"))',
);
await page.click('.tabs--primary :text-is("Delete")');
await page.click('.button--primary');
await page.waitForSelector(':text("Deleted term")');
await waitForGatsby();

// Check the tag has gone.
await page.goto(gatsby.baseUrl);
await page.click('a:text-is("With everything")');
await expect(page.locator(':text("Tag 1")')).toHaveCount(0);
});
Loading