Skip to content

The queue

Changing a whole entity type at once can take a long time. The drush ecdl:dlet command therefore does not change anything itself. It adds one item per entity to a queue named entity_change_default_language, and a queue worker changes the entities later, one item at a time.

The demo site has an English article, Latest news, with a Spanish translation. A fourth article, Hidden gems, has no Spanish translation.

The translations table of the Latest news article with English as the original language

Queue every article for Spanish.

$ drush ecdl:dlet node es --bundle=article -y
// Are you sure you want to change the default language of these entities to
// Spanish?: yes.
[OK] Entities enqueued

The queue now holds one item for each article. Drush lists the queues and their sizes.

$ drush queue:list
-------------------------------- ------- ---------------------------------
Queue Items Class
-------------------------------- ------- ---------------------------------
entity_change_default_language 4 Drupal\Core\Queue\DatabaseQueue
-------------------------------- ------- ---------------------------------

Cron runs the worker for up to 60 seconds per run. To run it by hand, use the queue command.

$ drush queue:run entity_change_default_language
[notice] Skipped node 4: it has no es translation and the item does not ask to create it.
[success] Processed 4 items from the entity_change_default_language queue in 0.09 sec.

The translations table of the Latest news article with Spanish as the original language

Hidden gems was skipped, and the module logged why. To create the missing translation, queue the type again with --create-missing. Only the entities not yet in Spanish are queued.

$ drush ecdl:dlet node es --create-missing -y
$ drush queue:run entity_change_default_language
[success] Processed 1 items from the entity_change_default_language queue in 0.09 sec.

Your own code can add items to the same queue. An item is an array.

Key Meaning
entity_type Required. The entity type id.
entity_id Required. The id of the entity to load.
default_langcode Required. The new default language.
preserve_languages The languages to keep. A missing key or NULL keeps every translation, and an empty array keeps only the new default.
preserve_legacy_default_language Whether to keep the old default language as a translation.
create Whether to create the new default translation when the entity has none.
follow_fields Names of reference fields to follow, on top of the entity reference revisions fields.
attempts How many times the item failed before. The worker sets it. A missing key counts as 0.

Items queued by 1.0.x are still processed as they were.

The worker logs everything it does not change, in the entity_change_default_language channel.

  • A skipped item is logged at notice level, with the entity and the reason, and deleted. The reasons are an entity type that does not exist or is not enabled in the settings, an entity that no longer loads, an entity that is not translatable, an entity already in the target language, and an entity without a translation in the target language when the item does not ask to create it.
  • A failed item is logged at error level and queued again with one more attempts. Retries run in the same cron or queue:run pass.
  • After 5 attempts the item is given up, with a last error log entry, and it is not queued again.

A change that fails stores nothing, so a retry starts clean. Read the recent log entries with Drush.

Terminal window
drush watchdog:show --type=entity_change_default_language