Skip to content
This repository has been archived by the owner on Nov 16, 2021. It is now read-only.

Commit

Permalink
Issue #2831550 by phenaproxima: Lightning Core Entity Load creating i…
Browse files Browse the repository at this point in the history
…nfinite loop on Taxonomy
  • Loading branch information
phenaproxima authored and Phéna Proxima committed Dec 1, 2016
1 parent efa1381 commit 8f96673
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,5 @@ script:
- composer validate --no-check-all --ansi
- behat --strict --stop-on-failure

after_script:
- cat ../../../tmp/selenium.log

matrix:
fast_finish: true
19 changes: 17 additions & 2 deletions modules/lightning_features/lightning_core/lightning_core.module
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,29 @@ function lightning_core_modules_installed(array $modules) {
/**
* Implements hook_entity_load().
*/
function lightning_core_entity_load(array $entities, $entity_type_id) {
function lightning_core_entity_load(array $entities) {
// Maintain a list of entity UUIDs whose aliases we've already looked up.
// We only want to look up a particular entity's alias once per request in
// order to prevent infinite loops (see issue #2831550).
static $looked_up = [];

/** @var \Drupal\Core\Path\AliasStorageInterface $alias_storage */
$alias_storage = \Drupal::service('path.alias_storage');

foreach ($entities as $entity) {
$uuid = $entity->uuid();

// If the entity has an empty path field, try to set its value. Amazingly,
// Path does not do this on its freaking own.
if ($entity instanceof FieldableEntityInterface && $entity->hasField('path') && $entity->path instanceof PathFieldItemList && $entity->path->isEmpty()) {
if (
empty($looked_up[$uuid]) &&
$entity instanceof FieldableEntityInterface &&
$entity->hasField('path') &&
$entity->path instanceof PathFieldItemList &&
$entity->path->isEmpty()
) {
$looked_up[$uuid] = TRUE;

$alias = $alias_storage->load([
'source' => '/' . $entity->toUrl()->getInternalPath(),
]);
Expand Down

0 comments on commit 8f96673

Please sign in to comment.