Commit 3cb5c72d authored by catch's avatar catch

Issue #2848120 by kristiaanvandeneynde, tim.plunkett, Pavan B S, tstoeckler:...

Issue #2848120 by kristiaanvandeneynde, tim.plunkett, Pavan B S, tstoeckler: Short term fix: Make ContentTranslationController recognize 'add' and 'edit' form handlers
parent 348ff90c
......@@ -296,8 +296,10 @@ function content_translation_form_alter(array &$form, FormStateInterface $form_s
$entity = $form_object->getEntity();
$op = $form_object->getOperation();
// Let the content translation handler alter the content entity edit form.
if ($entity instanceof ContentEntityInterface && $entity->isTranslatable() && count($entity->getTranslationLanguages()) > 1 && ($op == 'edit' || $op == 'default')) {
// Let the content translation handler alter the content entity form. This can
// be the 'add' or 'edit' form. It also tries a 'default' form in case neither
// of the aforementioned forms are defined.
if ($entity instanceof ContentEntityInterface && $entity->isTranslatable() && count($entity->getTranslationLanguages()) > 1 && in_array($op, ['edit', 'add', 'default'], TRUE)) {
$controller = \Drupal::entityManager()->getHandler($entity->getEntityTypeId(), 'translation');
$controller->entityFormAlter($form, $form_state, $entity);
......
......@@ -337,7 +337,9 @@ public function add(LanguageInterface $source, LanguageInterface $target, RouteM
// @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.
$operation = 'default';
// 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();
......@@ -368,7 +370,9 @@ public function edit(LanguageInterface $language, RouteMatchInterface $route_mat
// @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.
$operation = 'default';
// Use the edit form handler, if available, otherwise default.
$operation = $entity->getEntityType()->hasHandlerClass('form', 'edit') ? 'edit' : 'default';
$form_state_additions = [];
$form_state_additions['langcode'] = $language->getId();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment