From f565d9f639b789d7019aa5d8000fada23c1e910f Mon Sep 17 00:00:00 2001 From: Kristiaan Van den Eynde Date: Thu, 23 Feb 2017 14:57:08 +0100 Subject: [PATCH] Issue #2848120 by kristiaanvandeneynde, tim.plunkett: Short term fix: Make ContentTranslationController recognize 'add' and 'edit' form handlers --- core/modules/content_translation/content_translation.module | 2 +- .../src/Controller/ContentTranslationController.php | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module index a8416db..8cbe30b 100644 --- a/core/modules/content_translation/content_translation.module +++ b/core/modules/content_translation/content_translation.module @@ -297,7 +297,7 @@ function content_translation_form_alter(array &$form, FormStateInterface $form_s $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')) { + if ($entity instanceof ContentEntityInterface && $entity->isTranslatable() && count($entity->getTranslationLanguages()) > 1 && ($op == 'edit' || $op == 'add' || $op == 'default')) { $controller = \Drupal::entityManager()->getHandler($entity->getEntityTypeId(), 'translation'); $controller->entityFormAlter($form, $form_state, $entity); diff --git a/core/modules/content_translation/src/Controller/ContentTranslationController.php b/core/modules/content_translation/src/Controller/ContentTranslationController.php index 43b59aa..f838ff1 100644 --- a/core/modules/content_translation/src/Controller/ContentTranslationController.php +++ b/core/modules/content_translation/src/Controller/ContentTranslationController.php @@ -338,6 +338,10 @@ public function add(LanguageInterface $source, LanguageInterface $target, RouteM // $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. + if ($entity->getEntityType()->getFormClass('add')) { + $operation = 'add'; + } $form_state_additions = array(); $form_state_additions['langcode'] = $target->getId(); @@ -369,6 +373,10 @@ public function edit(LanguageInterface $language, RouteMatchInterface $route_mat // $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. + if ($entity->getEntityType()->getFormClass('edit')) { + $operation = 'edit'; + } $form_state_additions = array(); $form_state_additions['langcode'] = $language->getId(); -- 2.8.1