// @todo Exploit the upcoming hook_entity_prepare() when available.
// See https://www.drupal.org/node/1810394.
$this->
prepareTranslation($entity,
$source,
$target);
// @todo Provide a way to figure out the default form operation. Maybe like
// $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default';
// See https://www.drupal.org/node/2006348.
// Use the add form handler, if available, otherwise default.
$operation =
$entity->
getEntityType()->
hasHandlerClass('form', 'add'
) ? 'add' : 'default';
$form_state_additions =
[];
$form_state_additions['langcode'
] =
$target->
getId();
$form_state_additions['content_translation'
]['source'
] =
$source;
$form_state_additions['content_translation'
]['target'
] =
$target;
$form_state_additions['content_translation'
]['translation_form'
] = !
$entity->
access('update'
);
return $this->
entityFormBuilder()->
getForm($entity,
$operation,
$form_state_additions);
} /**
* Builds the edit translation page.
*
* @param \Drupal\Core\Language\LanguageInterface $language
* The language of the translated values. Defaults to the current content
* language.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match object from which to extract the entity type.
* @param string $entity_type_id
* (optional) The entity type ID.
*
* @return array
* A processed form array ready to be rendered.
*/