diff --git c/core/modules/content_translation/content_translation.module w/core/modules/content_translation/content_translation.module index 01af5a0..8ae2ae6 100644 --- c/core/modules/content_translation/content_translation.module +++ w/core/modules/content_translation/content_translation.module @@ -175,15 +175,9 @@ function content_translation_menu() { ); // Delete translation callback. - $language_position = $entity_position + 3; - $args = array($entity_position, $language_position, $language_position + 1); $items["$path/translations/delete/%language"] = array( - 'title' => 'Delete', - 'page callback' => 'drupal_get_form', - 'page arguments' => array('content_translation_delete_confirm', $entity_position, $language_position), - 'access callback' => 'content_translation_delete_access', - 'access arguments' => $args, - ) + $item; + 'route_name' => "content_translation.translation_delete.$entity_type", + ); } } @@ -1046,40 +1040,3 @@ function content_translation_prepare_translation(EntityInterface $entity, Langua } } -/** - * Form constructor for the translation deletion confirmation. - */ -function content_translation_delete_confirm(array $form, array $form_state, EntityInterface $entity, Language $language) { - $langcode = $language->id; - $controller = content_translation_controller($entity->entityType()); - - return confirm_form( - $form, - t('Are you sure you want to delete the @language translation of %label?', array('@language' => $language->name, '%label' => $entity->label())), - $controller->getEditPath($entity), - t('This action cannot be undone.'), - t('Delete'), - t('Cancel') - ); -} - -/** - * Form submission handler for content_translation_delete_confirm(). - */ -function content_translation_delete_confirm_submit(array $form, array &$form_state) { - list($entity, $language) = $form_state['build_info']['args']; - $controller = content_translation_controller($entity->entityType()); - - // Remove the translated values. - $controller->removeTranslation($entity, $language->id); - $entity->save(); - - // Remove any existing path alias for the removed translation. - // @todo This should be taken care of by the Path module. - if (module_exists('path')) { - $conditions = array('source' => $controller->getViewPath($entity), 'langcode' => $language->id); - Drupal::service('path.crud')->delete($conditions); - } - - $form_state['redirect'] = $controller->getBasePath($entity) . '/translations'; -} diff --git c/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationManageAccessCheck.php w/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationManageAccessCheck.php index 92424f1..d63f949 100644 --- c/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationManageAccessCheck.php +++ w/core/modules/content_translation/lib/Drupal/content_translation/Access/ContentTranslationManageAccessCheck.php @@ -69,7 +69,7 @@ public function access(Route $route, Request $request) { && $controller->getTranslationAccess($entity, $operation)) ? static::ALLOW : static::DENY; } - elseif ($operation == 'update') { + elseif ($operation == 'update' || $operation == 'delete') { $language = $request->attributes->get('language'); $language = !empty($language) ? $language : language(Language::TYPE_CONTENT); return isset($languages[$language->id]) diff --git c/core/modules/content_translation/lib/Drupal/content_translation/Form/ContentTranslationDeleteForm.php w/core/modules/content_translation/lib/Drupal/content_translation/Form/ContentTranslationDeleteForm.php new file mode 100644 index 0000000..99d7aff --- /dev/null +++ w/core/modules/content_translation/lib/Drupal/content_translation/Form/ContentTranslationDeleteForm.php @@ -0,0 +1,168 @@ +get('entity.manager'), + $container->get('module_handler'), + $container->get('path.crud') + ); + } + + /** + * Creates a new ContentTranslationDeleteForm. + * + * @param \Drupal\Core\Entity\EntityManager $entity_manager + * The entity manager. + * @param \Drupal\Core\Path\Path $path + * Path CRUD service. + */ + public function __construct(EntityManager $entity_manager, ModuleHandlerInterface $module_handler, Path $path) { + $this->entityManager = $entity_manager; + $this->moduleHandler = $module_handler; + $this->path = $path; + } + + /** + * {@inheritdoc} + */ + public function getQuestion() { + return $this->t('Are you sure you want to delete the @language translation of %label?', array('@language' => $this->language->name, '%label' => $this->entity->label())); + } + + /** + * {@inheritdoc} + */ + public function getCancelRoute() { + $entity_type = $this->entity->entityType(); + return array( + 'route_name' => "content_translation.translation_edit.$entity_type", + 'route_parameters' => array( + 'entity' => $this->entity->id(), + ), + ); + } + + /** + * {@inheritdoc} + */ + public function getFormID() { + return 'content_translation_delete_confirm'; + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return $this->t('Delete'); + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + return $this->t('This action cannot be undone.'); + } + + /** + * Form constructor. + * + * @param array $form + * An associative array containing the structure of the form. + * @param array $form_state + * An associative array containing the current state of the form. + * @param \Drupal\Core\Entity\EntityInterface $entity + * Entity to have language deleted. + * @param \Drupal\Core\Language\Language + * Language to be deleted from entity. + * + * @return array + * The form structure. + */ + public function buildForm(array $form, array &$form_state, EntityInterface $entity = NULL, Language $language = NULL) { + $this->entity = $entity; + $this->language = $language; + $form_state['entity'] = $entity; + $form_state['language'] = $language; + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $entity = $form_state['entity']; + $language = $form_state['language']; + $entity_type = $entity->entityType(); + $controller_class = $this->entityManager->getControllerClass($entity_type, 'translation'); + $controller = new $controller_class($entity_type, $entity->entityInfo()); + + // Remove the translated values. + $controller->removeTranslation($this->entity, $language->id); + $entity->save(); + + // Remove any existing path alias for the removed translation. + if ($this->moduleHandler->moduleExists('path')) { + $conditions = array('source' => $controller->getViewPath($entity), 'langcode' => $language->id); + $this->path->delete($conditions); + } + + $form_state['redirect'] = $controller->getBasePath($entity) . '/translations'; + } + +} diff --git c/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php w/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php index 1ffd10c..5aa0f0b 100644 --- c/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php +++ w/core/modules/content_translation/lib/Drupal/content_translation/Routing/ContentTranslationRouteSubscriber.php @@ -124,6 +124,30 @@ public function routes(RouteBuildEvent $event) { ) ); $collection->add("content_translation.translation_edit.$entity_type", $route); + $route = new Route( + '/' . str_replace($entity_info['menu_path_wildcard'], '{entity}', $entity_info['menu_base_path']) . "/translations/delete/{language}", + array( + '_form' => '\Drupal\content_translation\Form\ContentTranslationDeleteForm', + 'language' => NULL, + '_title' => 'Delete', + + ), + array( + '_permission' => 'translate any entity', + '_access_content_translation_manage' => 'delete', + ), + array( + 'parameters' => array( + 'entity' => array( + 'type' => 'entity:' . $entity_type, + ), + 'language' => array( + 'type' => 'language', + ), + ), + ) + ); + $collection->add("content_translation.translation_delete.$entity_type", $route); } } }