Drupal 8's entity API supports requesting a translation of an entity object and then using it the same way as the original entity with $entity->getTranslation($langcode);
. That made the $langcode
arguments useless and confusing in many places of the API. It was not necessarily clear to API consumers which language would be used, the one the entity already had or the language passed in. Therefore we removed the explicit $langcode
arguments from the following places:
Function/Method | Before | After |
---|---|---|
BlockViewBuilder::lazyBuilder() | ($entity_id, $view_mode, $langcode) | ($entity_id, $view_mode) |
EntityViewController::view() | (EntityInterface $_entity, $view_mode = 'full', $langcode = NULL) | (EntityInterface $_entity, $view_mode = 'full') |
EntityViewBuilderInterface::buildComponents() | (array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) | (array &$build, array $entities, array $displays, $view_mode) |
hook_entity_view() | (array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) | (array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) |
hook_ENTITY_TYPE_view() | (array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode, $langcode) | (array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) |
hook_entity_build_defaults_alter() | (array &$build, \Drupal\Core\Entity\EntityInterface $entity, $view_mode, $langcode) | (array &$build, \Drupal\Core\Entity\EntityInterface $entity, $view_mode) |
hook_ENTITY_TYPE_build_defaults_alter() | (array &$build, \Drupal\Core\Entity\EntityInterface $entity, $view_mode, $langcode) | (array &$build, \Drupal\Core\Entity\EntityInterface $entity, $view_mode) |
hook_node_search_result() | (\Drupal\node\NodeInterface $node, $langcode) | (\Drupal\node\NodeInterface $node) |
hook_node_update_index() | (\Drupal\node\NodeInterface $node, $langcode) | (\Drupal\node\NodeInterface $node) |
All functions/methods had the language code as the last argument, so no argument reordering was necessary. Just use getTranslation($langcode)
on the entity to set the right language code before invoking these APIs. When you implement these APIs, you no longer need to do the getTranslation($langcode)
within your implementation, because the entity will already come in the proper language code.