diff --git a/core/modules/content_translation/content_translation.module b/core/modules/content_translation/content_translation.module
index 4e29f4c..25ad375 100644
--- a/core/modules/content_translation/content_translation.module
+++ b/core/modules/content_translation/content_translation.module
@@ -287,7 +287,7 @@ function content_translation_get_config_key($entity_type, $bundle, $setting) {
* @param string $setting
* The name of the setting.
*
- * @returns mixed
+ * @return mixed
* The stored value for the given setting.
*/
function content_translation_get_config($entity_type, $bundle, $setting) {
@@ -321,7 +321,7 @@ function content_translation_set_config($entity_type, $bundle, $setting, $value)
* (optional) The bundle of the entity. If no bundle is provided, all the
* available bundles are checked.
*
- * @returns
+ * @return bool
* TRUE if the specified bundle is translatable. If no bundle is provided
* returns TRUE if at least one of the entity bundles is translatable.
*
diff --git a/core/modules/content_translation/content_translation.pages.inc b/core/modules/content_translation/content_translation.pages.inc
deleted file mode 100644
index d4a7c48..0000000
--- a/core/modules/content_translation/content_translation.pages.inc
+++ /dev/null
@@ -1,251 +0,0 @@
-getEntityTypeId());
- $languages = \Drupal::languageManager()->getLanguages();
- $original = $entity->getUntranslated()->language()->id;
- $translations = $entity->getTranslationLanguages();
- $administrator = \Drupal::currentUser()->hasPermission('administer languages');
-
- $rel = array();
- foreach (array('canonical', 'edit-form', 'drupal:content-translation-overview') as $name) {
- $rel[$name] = $entity->getSystemPath($name);
- }
-
- $rows = array();
- $show_source_column = FALSE;
-
- if (\Drupal::languageManager()->isMultilingual()) {
- // Determine whether the current entity is translatable.
- $translatable = FALSE;
- foreach (\Drupal::entityManager()->getFieldDefinitions($entity->getEntityTypeId(), $entity->bundle()) as $field_definition) {
- if ($field_definition->isTranslatable()) {
- $translatable = TRUE;
- break;
- }
- }
-
- // Show source-language column if there are non-original source langcodes.
- $additional_source_langcodes = array_filter($entity->translation, function ($translation) use ($original) {
- return !empty($translation['source']) && $translation['source'] != $original;
- });
- $show_source_column = !empty($additional_source_langcodes);
-
- foreach ($languages as $language) {
- $language_name = $language->name;
- $langcode = $language->id;
-
- $add_path = $rel['drupal:content-translation-overview'] . '/add/' . $original . '/' . $langcode;
- $translate_path = $rel['drupal:content-translation-overview'] . '/edit/' . $langcode;
-
- $add_links = _content_translation_get_switch_links($add_path);
- $edit_links = _content_translation_get_switch_links($rel['edit-form']);
- $translate_links = _content_translation_get_switch_links($translate_path);
- $delete_links = _content_translation_get_switch_links($rel['drupal:content-translation-overview'] . '/delete/' . $langcode);
-
- $operations = array(
- 'data' => array(
- '#type' => 'operations',
- '#links' => array(),
- ),
- );
- $links = &$operations['data']['#links'];
-
- if (isset($translations[$langcode])) {
- // Existing translation in the translation set: display status.
- $source = isset($entity->translation[$langcode]['source']) ? $entity->translation[$langcode]['source'] : '';
- $is_original = $langcode == $original;
- $label = $entity->getTranslation($langcode)->label();
- $link = isset($links->links[$langcode]['href']) ? $links->links[$langcode] : array('href' => $rel['canonical'], 'language' => $language);
- $row_title = l($label, $link['href'], $link);
-
- if (empty($link['href'])) {
- $row_title = $is_original ? $label : t('n/a');
- }
-
- // If the user is allowed to edit the entity we point the edit link to
- // the entity form, otherwise if we are not dealing with the original
- // language we point the link to the translation form.
- if ($entity->access('update')) {
- $links['edit'] = isset($edit_links->links[$langcode]['href']) ? $edit_links->links[$langcode] : array('href' => $rel['edit-form'], 'language' => $language);
- }
- elseif (!$is_original && $controller->getTranslationAccess($entity, 'update')) {
- $links['edit'] = isset($translate_links->links[$langcode]['href']) ? $translate_links->links[$langcode] : array('href' => $translate_path, 'language' => $language);
- }
-
- if (isset($links['edit'])) {
- $links['edit']['title'] = t('Edit');
- }
-
- $translation = $entity->translation[$langcode];
- $status = !empty($translation['status']) ? t('Published') : t('Not published');
- // @todo Add a theming function here.
- $status = '' . $status . '' . (!empty($translation['outdated']) ? ' ' . t('outdated') . '' : '');
-
- if ($is_original) {
- $language_name = t('@language_name (Original language)', array('@language_name' => $language_name));
- $source_name = t('n/a');
- }
- else {
- $source_name = isset($languages[$source]) ? $languages[$source]->name : t('n/a');
- if ($controller->getTranslationAccess($entity, 'delete')) {
- $links['delete'] = isset($delete_links->links[$langcode]['href']) ? $delete_links->links[$langcode] : array('href' => $delete_links, 'language' => $language);
- $links['delete']['title'] = t('Delete');
- }
- }
- }
- else {
- // No such translation in the set yet: help user to create it.
- $row_title = $source_name = t('n/a');
- $source = $entity->language()->id;
-
- if ($source != $langcode && $controller->getTranslationAccess($entity, 'create')) {
- if ($translatable) {
- $links['add'] = isset($add_links->links[$langcode]['href']) ? $add_links->links[$langcode] : array('href' => $add_path, 'language' => $language);
- $links['add']['title'] = t('Add');
- }
- elseif ($administrator) {
- $links['nofields'] = array('title' => t('No translatable fields'), 'route_name' => 'language.content_settings_page', 'language' => $language);
- }
- }
-
- $status = t('Not translated');
- }
-
- if ($show_source_column) {
- $rows[] = array($language_name, $row_title, $source_name, $status, $operations);
- }
- else {
- $rows[] = array($language_name, $row_title, $status, $operations);
- }
- }
- }
-
- $build['#title'] = t('Translations of %label', array('%label' => $entity->label()));
-
- // Add metadata to the build render array to let other modules know about
- // which entity this is.
- $build['#entity'] = $entity;
-
- if ($show_source_column) {
- $header = array(t('Language'), t('Translation'), t('Source language'), t('Status'), t('Operations'));
- }
- else {
- $header = array(t('Language'), t('Translation'), t('Status'), t('Operations'));
- }
-
- $build['content_translation_overview'] = array(
- '#type' => 'table',
- '#header' => $header,
- '#rows' => $rows,
- );
-
- return $build;
-}
-
-/**
- * Returns the localized links for the given path.
- *
- * @param string $path
- * The path for which language switch links should be provided.
- *
- * @returns
- * A renderable array of language switch links.
- */
-function _content_translation_get_switch_links($path) {
- $links = \Drupal::languageManager()->getLanguageSwitchLinks(Language::TYPE_CONTENT, $path);
- if (empty($links)) {
- // If content language is set up to fall back to the interface language,
- // then there will be no switch links for Language::TYPE_CONTENT, ergo we
- // also need to use interface switch links.
- $links = \Drupal::languageManager()->getLanguageSwitchLinks(Language::TYPE_INTERFACE, $path);
- }
- return $links;
-}
-
-/**
- * Page callback for the translation addition page.
- *
- * @param EntityInterface $entity
- * The entity being translated.
- * @param Language $source
- * (optional) The language of the values being translated. Defaults to the
- * entity language.
- * @param Language $target
- * (optional) The language of the translated values. Defaults to the current
- * content language.
- *
- * @return array
- * A processed form array ready to be rendered.
- *
- * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
- * Use \Drupal\content_translation\Controller\ContentTranslationController::add().
- */
-function content_translation_add_page(EntityInterface $entity, Language $source = NULL, Language $target = NULL) {
- $source = !empty($source) ? $source : $entity->language();
- $target = !empty($target) ? $target : \Drupal::languageManager()->getCurrentLanguage(Language::TYPE_CONTENT);
- // @todo Exploit the upcoming hook_entity_prepare() when available.
- content_translation_prepare_translation($entity, $source, $target);
- $form_state['langcode'] = $target->id;
- $form_state['content_translation']['source'] = $source;
- $form_state['content_translation']['target'] = $target;
- $form_state['content_translation']['translation_form'] = !$entity->access('update');
- return \Drupal::service('entity.form_builder')->getForm($entity, 'default', $form_state);
-}
-
-/**
- * Page callback for the translation edit page.
- *
- * @param \Drupal\Core\Entity\EntityInterface $entity
- * The entity being translated.
- * @param \Drupal\Core\Language\Language $language
- * (optional) The language of the translated values. Defaults to the current
- * content language.
- *
- * @return array
- * A processed form array ready to be rendered.
- *
- * @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
- * Use \Drupal\content_translation\Controller\ContentTranslationController::edit().
- */
-function content_translation_edit_page(EntityInterface $entity, Language $language = NULL) {
- $language = !empty($language) ? $language : \Drupal::languageManager()->getCurrentLanguage(Language::TYPE_CONTENT);
- $form_state['langcode'] = $language->id;
- $form_state['content_translation']['translation_form'] = TRUE;
- return \Drupal::service('entity.form_builder')->getForm($entity, 'default', $form_state);
-}
-
-/**
- * Populates target values with the source values.
- *
- * @param \Drupal\Core\Entity\EntityInterface $entity
- * The entitiy being translated.
- * @param \Drupal\Core\Language\Language $source
- * The language to be used as source.
- * @param \Drupal\Core\Language\Language $target
- * The language to be used as target.
- */
-function content_translation_prepare_translation(EntityInterface $entity, Language $source, Language $target) {
- if ($entity instanceof ContentEntityInterface) {
- $source_translation = $entity->getTranslation($source->id);
- $entity->addTranslation($target->id, $source_translation->toArray());
- }
-}
diff --git a/core/modules/content_translation/content_translation.services.yml b/core/modules/content_translation/content_translation.services.yml
index da2acb2..8d4740f 100644
--- a/core/modules/content_translation/content_translation.services.yml
+++ b/core/modules/content_translation/content_translation.services.yml
@@ -17,7 +17,7 @@ services:
content_translation.manage_access:
class: Drupal\content_translation\Access\ContentTranslationManageAccessCheck
- arguments: ['@entity.manager']
+ arguments: ['@entity.manager', '@language_manager']
tags:
- { name: access_check, applies_to: _access_content_translation_manage }
diff --git a/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php b/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php
index b0e0fb6..c5d0ac4 100644
--- a/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php
+++ b/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php
@@ -9,6 +9,7 @@
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Language\Language;
+use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\Routing\Route;
@@ -27,13 +28,23 @@ class ContentTranslationManageAccessCheck implements AccessInterface {
protected $entityManager;
/**
+ * The language manager.
+ *
+ * @var \Drupal\Core\Language\LanguageManagerInterface
+ */
+ protected $languageManager;
+
+ /**
* Constructs a ContentTranslationManageAccessCheck object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $manager
* The entity type manager.
+ * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
+ * The language manager.
*/
- public function __construct(EntityManagerInterface $manager) {
+ public function __construct(EntityManagerInterface $manager, LanguageManagerInterface $language_manager) {
$this->entityManager = $manager;
+ $this->languageManager = $language_manager;
}
/**
@@ -58,19 +69,19 @@ public function __construct(EntityManagerInterface $manager) {
*/
public function access(Route $route, Request $request, AccountInterface $account, $source = NULL, $target = NULL, $language = NULL) {
$entity_type = $request->attributes->get('_entity_type_id');
- /** @var $entity \Drupal\Core\Entity\EntityInterface */
+ /* @var $entity \Drupal\Core\Entity\ContentEntityInterface */
if ($entity = $request->attributes->get($entity_type)) {
$operation = $route->getRequirement('_access_content_translation_manage');
$controller = content_translation_controller($entity_type, $account);
// Load translation.
$translations = $entity->getTranslationLanguages();
- $languages = language_list();
+ $languages = $this->languageManager->getLanguages();
switch ($operation) {
case 'create':
- $source = language_load($source) ?: $entity->language();
- $target = language_load($target) ?: \Drupal::languageManager()->getCurrentLanguage(Language::TYPE_CONTENT);
+ $source = $request->attributes->get('source') ? : $entity->language();
+ $target = $request->attributes->get('target') ? : $this->languageManager->getCurrentLanguage(Language::TYPE_CONTENT);
return ($source->id != $target->id
&& isset($languages[$source->id])
&& isset($languages[$target->id])
@@ -80,7 +91,7 @@ public function access(Route $route, Request $request, AccountInterface $account
case 'update':
case 'delete':
- $language = language_load($language) ?: \Drupal::languageManager()->getCurrentLanguage(Language::TYPE_CONTENT);
+ $language = $request->attributes->get('language') ? : $this->languageManager->getCurrentLanguage(Language::TYPE_CONTENT);
return isset($languages[$language->id])
&& $language->id != $entity->getUntranslated()->language()->id
&& isset($translations[$language->id])
diff --git a/core/modules/content_translation/src/ContentTranslationHandler.php b/core/modules/content_translation/src/ContentTranslationHandler.php
index 76723c2..2a58ddb 100644
--- a/core/modules/content_translation/src/ContentTranslationHandler.php
+++ b/core/modules/content_translation/src/ContentTranslationHandler.php
@@ -197,8 +197,12 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac
// A new translation is not available in the translation metadata, hence
// it should count as one more.
$published = $new_translation;
- foreach ($entity->translation as $translation) {
- $published += $translation['status'];
+ // When creating a brand new translation, $entity->translation is not
+ // set.
+ if (!($new_translation)) {
+ foreach ($entity->translation as $translation) {
+ $published += $translation['status'];
+ }
}
$enabled = $published > 1;
}
diff --git a/core/modules/content_translation/src/Controller/ContentTranslationController.php b/core/modules/content_translation/src/Controller/ContentTranslationController.php
index 31a33d2..40e7f28 100644
--- a/core/modules/content_translation/src/Controller/ContentTranslationController.php
+++ b/core/modules/content_translation/src/Controller/ContentTranslationController.php
@@ -7,41 +7,325 @@
namespace Drupal\content_translation\Controller;
+use Drupal\Core\Controller\ControllerBase;
+use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
+use Drupal\Core\Entity\ContentEntityInterface;
+use Drupal\Core\Entity\EntityInterface;
+use Drupal\Core\Entity\EntityManagerInterface;
+use Drupal\Core\Language\LanguageInterface;
+use Drupal\Core\Language\LanguageManagerInterface;
+use Drupal\Core\Url;
+use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Base class for entity translation controllers.
*/
-class ContentTranslationController {
+class ContentTranslationController extends ControllerBase implements ContainerInjectionInterface {
/**
- * @todo Remove content_translation_overview().
+ * The field info service.
+ *
+ * @var \Drupal\Core\Entity\EntityManagerInterface
+ */
+ protected $entityManager;
+
+ /**
+ * The language manager.
+ *
+ * @var \Drupal\Core\Language\LanguageManagerInterface
+ */
+ protected $languageManager;
+
+ /**
+ * Constructs a ContentTranslationController object.
+ *
+ * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
+ * The entity manager service.
+ * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
+ * The language manager.
+ */
+ public function __construct(EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager) {
+ $this->entityManager = $entity_manager;
+ $this->languageManager = $language_manager;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public static function create(ContainerInterface $container) {
+ return new static(
+ $container->get('entity.manager'),
+ $container->get('language_manager')
+ );
+ }
+
+ /**
+ * Populates target values with the source values.
+ *
+ * @param \Drupal\Core\Entity\EntityInterface $entity
+ * The entity being translated.
+ * @param \Drupal\Core\Language\LanguageInterface $source
+ * The language to be used as source.
+ * @param \Drupal\Core\Language\LanguageInterface $target
+ * The language to be used as target.
+ */
+ public function prepareTranslation(EntityInterface $entity, LanguageInterface $source, LanguageInterface $target) {
+ if ($entity instanceof ContentEntityInterface) {
+ /* @var \Drupal\Core\Entity\ContentEntityInterface $source_translation */
+ $source_translation = $entity->getTranslation($source->getId());
+ $entity->addTranslation($target->getId(), $source_translation->toArray());
+ }
+ }
+
+ /**
+ * Builds the translations overview page.
+ *
+ * @param \Symfony\Component\HttpFoundation\Request $request
+ * The request object from which to extract the entity type.
+ *
+ * @return array
+ * Array of page elements to render.
*/
public function overview(Request $request) {
- $entity = $request->attributes->get($request->attributes->get('_entity_type_id'));
- module_load_include('pages.inc', 'content_translation');
- return content_translation_overview($entity);
+ $entity_type = $request->attributes->get('_entity_type_id');
+ $entity = $request->attributes->get($entity_type);
+ $account = $this->currentUser();
+ $controller = $this->entityManager()
+ ->getController($entity_type, 'translation');
+
+ $languages = $this->languageManager->getLanguages();
+ $original = $entity->getUntranslated()->language()->id;
+ $translations = $entity->getTranslationLanguages();
+ $field_ui = $this->moduleHandler()
+ ->moduleExists('field_ui') && $account->hasPermission('administer ' . $entity_type . ' fields');
+
+ $rows = array();
+ $show_source_column = FALSE;
+
+ if ($this->languageManager()->isMultilingual()) {
+ // Determine whether the current entity is translatable.
+ $translatable = FALSE;
+ foreach ($this->entityManager->getFieldDefinitions($entity_type, $entity->bundle()) as $instance) {
+ if ($instance->isTranslatable()) {
+ $translatable = TRUE;
+ break;
+ }
+ }
+
+ // Show source-language column if there are non-original source langcodes.
+ $additional_source_langcodes = array_filter($entity->translation, function ($translation) use ($original) {
+ return !empty($translation['source']) && $translation['source'] != $original;
+ });
+ $show_source_column = !empty($additional_source_langcodes);
+
+ foreach ($languages as $language) {
+ $language_name = $language->name;
+ $langcode = $language->id;
+
+ $add_url = new Url(
+ 'content_translation.translation_add_' . $entity_type,
+ array(
+ 'source' => $original,
+ 'target' => $language->id,
+ $entity_type => $entity->id(),
+ )
+ );
+
+ $translate_url = new Url(
+ 'content_translation.translation_edit_' . $entity_type,
+ array(
+ 'language' => $language->id,
+ $entity_type => $entity->id(),
+ )
+ );
+ $delete_url = new Url(
+ 'content_translation.translation_edit_' . $entity_type,
+ array(
+ 'language' => $language->id,
+ $entity_type => $entity->id(),
+ )
+ );
+ $operations = array(
+ 'data' => array(
+ '#type' => 'operations',
+ '#links' => array(),
+ ),
+ );
+
+ $links = & $operations['data']['#links'];
+ if (array_key_exists($langcode, $translations)) {
+ // Existing translation in the translation set: display status.
+ $source = isset($entity->translation[$langcode]['source']) ? $entity->translation[$langcode]['source'] : '';
+ $is_original = $langcode == $original;
+ $label = $entity->getTranslation($langcode)->label();
+ $link = isset($links->links[$langcode]['href']) ? $links->links[$langcode] : array('href' => $entity->getSystemPath());
+ $row_title = l($label, $link['href'], $link);
+
+ if (empty($link['href'])) {
+ $row_title = $is_original ? $label : $this->t('n/a');
+ }
+
+ // If the user is allowed to edit the entity we point the edit link to
+ // the entity form, otherwise if we are not dealing with the original
+ // language we point the link to the translation form.
+ if ($entity->access('update')) {
+ $links['edit'] = array(
+ 'href' => $entity->getSystemPath('edit-form'),
+ );
+ }
+ elseif (!$is_original && $controller->getTranslationAccess($entity, 'update')) {
+ $links['edit'] = $translate_url->toArray();
+ }
+
+ if (isset($links['edit'])) {
+ $links['edit']['title'] = $this->t('Edit');
+ }
+ $translation = $entity->translation[$langcode];
+ $status = !empty($translation['status']) ? $this->t('Published') : $this->t('Not published');
+ // @todo Remove as part of https://drupal.org/node/2250841.
+ $status = '' . $status . '' . (!empty($translation['outdated']) ? ' ' . $this->t('outdated') . '' : '');
+
+ if ($is_original) {
+ $language_name = $this->t('@language_name (Original language)', array('@language_name' => $language_name));
+ $source_name = $this->t('n/a');
+ }
+ else {
+ $source_name = isset($languages[$source]) ? $languages[$source]->name : $this->t('n/a');
+ if ($controller->getTranslationAccess($entity, 'delete')) {
+ $links['delete'] = array(
+ 'title' => $this->t('Delete'),
+ ) + $delete_url->toArray();
+ }
+ }
+ }
+ else {
+ // No such translation in the set yet: help user to create it.
+ $row_title = $source_name = $this->t('n/a');
+ $source = $entity->language()->id;
+
+ if ($source != $langcode && $controller->getTranslationAccess($entity, 'create')) {
+ if ($translatable) {
+ $links['add'] = array(
+ 'title' => $this->t('Add'),
+ ) + $add_url->toArray();
+ }
+ elseif ($field_ui) {
+ $url = new Url('language.content_settings_page');
+
+ // Link directly to the fields tab to make it easier to find the
+ // setting to enable translation on fields.
+ $links['nofields'] = array(
+ 'title' => $this->t('No translatable fields'),
+ ) + $url->toArray();
+ }
+ }
+
+ $status = $this->t('Not translated');
+ }
+ if ($show_source_column) {
+ $rows[] = array(
+ $language_name,
+ $row_title,
+ $source_name,
+ $status,
+ $operations,
+ );
+ }
+ else {
+ $rows[] = array($language_name, $row_title, $status, $operations);
+ }
+ }
+ }
+ if ($show_source_column) {
+ $header = array(
+ $this->t('Language'),
+ $this->t('Translation'),
+ $this->t('Source language'),
+ $this->t('Status'),
+ $this->t('Operations'),
+ );
+ }
+ else {
+ $header = array(
+ $this->t('Language'),
+ $this->t('Translation'),
+ $this->t('Status'),
+ $this->t('Operations'),
+ );
+ }
+
+ $build['#title'] = $this->t('Translations of %label', array('%label' => $entity->label()));
+
+ // Add metadata to the build render array to let other modules know about
+ // which entity this is.
+ $build['#entity'] = $entity;
+
+ $build['content_translation_overview'] = array(
+ '#theme' => 'table',
+ '#header' => $header,
+ '#rows' => $rows,
+ );
+
+ return $build;
}
/**
- * @todo Remove content_translation_add_page().
+ * Builds an add translation page.
+ *
+ * @param \Drupal\Core\Language\LanguageInterface $source
+ * The language of the values being translated. Defaults to the entity
+ * language.
+ * @param \Drupal\Core\Language\LanguageInterface $target
+ * The language of the translated values. Defaults to the current content
+ * language.
+ * @param \Symfony\Component\HttpFoundation\Request $request
+ * The request object from which to extract the entity type.
+ *
+ * @return array
+ * A processed form array ready to be rendered.
*/
- public function add(Request $request, $source, $target) {
+ public function add(LanguageInterface $source, LanguageInterface $target, Request $request) {
$entity = $request->attributes->get($request->attributes->get('_entity_type_id'));
- module_load_include('pages.inc', 'content_translation');
- $source = language_load($source);
- $target = language_load($target);
- return content_translation_add_page($entity, $source, $target);
+
+ // @todo Exploit the upcoming hook_entity_prepare() when available.
+ $this->prepareTranslation($entity, $source, $target);
+
+ // @todo: $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default';
+ $operation = 'default';
+ $form_state['langcode'] = $target->id;
+ $form_state['content_translation']['source'] = $source;
+ $form_state['content_translation']['target'] = $target;
+ $form_state['content_translation']['translation_form'] = !$entity->access('update');
+
+ return $this->entityFormBuilder()
+ ->getForm($entity, $operation, $form_state);
}
/**
- * @todo Remove content_translation_edit_page().
+ * Builds the edit translation page.
+ *
+ * @param \Drupal\Core\Language\LanguageInterface $language
+ * The language of the translated values. Defaults to the current content
+ * language.
+ * @param \Symfony\Component\HttpFoundation\Request $request
+ * The request object from which to extract the entity type.
+ *
+ * @return array
+ * A processed form array ready to be rendered.
*/
- public function edit(Request $request, $language) {
+ public function edit(LanguageInterface $language, Request $request) {
$entity = $request->attributes->get($request->attributes->get('_entity_type_id'));
- module_load_include('pages.inc', 'content_translation');
- $language = language_load($language);
- return content_translation_edit_page($entity, $language);
+
+ // @todo Provide a way to figure out the default form operation. One way
+ // could be a default_operation annotation on the entity.
+
+ $operation = 'default';
+ $form_state['langcode'] = $language->id;
+ $form_state['content_translation']['translation_form'] = TRUE;
+
+ return $this->entityFormBuilder()
+ ->getForm($entity, $operation, $form_state);
}
}
diff --git a/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php b/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php
index 51731b6..dca0771 100644
--- a/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php
+++ b/core/modules/content_translation/src/Routing/ContentTranslationRouteSubscriber.php
@@ -87,6 +87,12 @@ protected function alterRoutes(RouteCollection $collection) {
'entity' => array(
'type' => 'entity:' . $entity_type_id,
),
+ 'source' => array(
+ 'type' => 'language',
+ ),
+ 'target' => array(
+ 'type' => 'language',
+ ),
),
)
);
@@ -110,6 +116,9 @@ protected function alterRoutes(RouteCollection $collection) {
'entity' => array(
'type' => 'entity:' . $entity_type_id,
),
+ 'language' => array(
+ 'type' => 'language',
+ ),
),
)
);
@@ -132,6 +141,9 @@ protected function alterRoutes(RouteCollection $collection) {
'entity' => array(
'type' => 'entity:' . $entity_type_id,
),
+ 'language' => array(
+ 'type' => 'language',
+ ),
),
'_access_mode' => 'ANY',
)
diff --git a/core/modules/language/language.services.yml b/core/modules/language/language.services.yml
index e183e6d..4b1ad29 100644
--- a/core/modules/language/language.services.yml
+++ b/core/modules/language/language.services.yml
@@ -17,3 +17,8 @@ services:
tags:
- { name: config.factory.override, priority: -254 }
- { name: event_subscriber }
+ language_converter:
+ class: Drupal\language\LanguageConverter
+ arguments: ['@language_manager']
+ tags:
+ - { name: paramconverter }
diff --git a/core/modules/language/src/LanguageConverter.php b/core/modules/language/src/LanguageConverter.php
new file mode 100644
index 0000000..7c7489d
--- /dev/null
+++ b/core/modules/language/src/LanguageConverter.php
@@ -0,0 +1,57 @@
+languageManager = $language_manager;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function convert($value, $definition, $name, array $defaults, Request $request) {
+ if (!empty($value)) {
+ return $this->languageManager->getLanguage($value);
+ }
+ return NULL;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function applies($definition, $name, Route $route) {
+ if (!empty($definition['type']) && $definition['type'] == 'language') {
+ return TRUE;
+ }
+ return FALSE;
+ }
+
+}