More robust token generation for books

Created on 23 January 2023, over 1 year ago

Problem/Motivation

Cannot load the "node" entity with NULL ID.
#1 /var/www/html/web/core/lib/Drupal/Core/Entity/EntityBase.php(488): Drupal\Core\Entity\EntityStorageBase->load(NULL)
#2 /var/www/html/web/modules/contrib/token/token.tokens.inc(1229): Drupal\Core\Entity\EntityBase::load(NULL)
#3 [internal function]: book_tokens('node', Array, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#4 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(426): call_user_func_array(Object(Closure), Array)
#5 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(405): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object(Closure), 'book')
#6 /var/www/html/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(433): Drupal\Core\Extension\ModuleHandler->invokeAllWith('tokens', Object(Closure))
#7 /var/www/html/web/core/lib/Drupal/Core/Utility/Token.php(357): Drupal\Core\Extension\ModuleHandler->invokeAll('tokens', Array)
#8 /var/www/html/web/core/lib/Drupal/Core/Utility/Token.php(239): Drupal\Core\Utility\Token->generate('node', Array, Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#9 /var/www/html/web/core/lib/Drupal/Core/Utility/Token.php(189): Drupal\Core\Utility\Token->doReplace(true, '[node:book:titl...', Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))
#10 /var/www/html/web/modules/contrib/auto_entitylabel/src/AutoEntityLabelManager.php(299): Drupal\Core\Utility\Token->replace(Object(Drupal\Core\StringTranslation\TranslatableMarkup), Array, Array, Object(Drupal\Core\Render\BubbleableMetadata))

Upon creation of books with migrate (or in another programmatic way), it might happen that the book information is incomplete.

Proposed resolution

Token module should not fail on such data, but move on and do not generate tokens.

📌 Task
Status

Needs review

Version

1.0

Component

Code

Created by

🇭🇺Hungary Aron Novak Hungary, Budapest

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024