diff --git c/core/modules/content_translation/content_translation.module w/core/modules/content_translation/content_translation.module index 7ca3551..9480b26 100644 --- c/core/modules/content_translation/content_translation.module +++ w/core/modules/content_translation/content_translation.module @@ -149,8 +149,9 @@ function content_translation_menu() { } $items["$path/translations"] = array( + 'title' => 'Translate', + 'route_name' => "content_translation.translation_overview_$entity_type", 'type' => MENU_LOCAL_TASK, - 'route_name' => "content_translation.translation_overview.$entity_type", 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, 'weight' => 2, ) + $item; @@ -165,19 +166,22 @@ function content_translation_menu() { // @todo Add the access callback instead of replacing it as soon as the // routing system supports multiple callbacks. $items["$path/translations/add/%language/%language"] = array( - 'route_name' => "content_translation.translation_add.$entity_type", - 'weight' => 1, + 'title' => 'Add', + 'route_name' => "content_translation.translation_add_$entity_type", + 'weight' => 1, ); // Edit translation callback. $items["$path/translations/edit/%language"] = array( - 'route_name' => "content_translation.translation_edit.$entity_type", - 'weight' => 1, + 'title' => 'Edit', + 'route_name' => "content_translation.translation_edit_$entity_type", + 'weight' => 1, ); // Delete translation callback. $items["$path/translations/delete/%language"] = array( - 'route_name' => "content_translation.translation_delete.$entity_type", + 'title' => 'Delete', + 'route_name' => "content_translation.delete_$entity_type", ); } } @@ -353,7 +357,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) { @@ -387,7 +391,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. */ @@ -984,7 +988,7 @@ function content_translation_save_settings($settings) { * @param string $path * The path for which language switch links should be provided. * - * @returns + * @return array * A renderable array of language switch links. */ function _content_translation_get_switch_links($path) { @@ -1002,7 +1006,7 @@ function _content_translation_get_switch_links($path) { * Populates target values with the source values. * * @param \Drupal\Core\Entity\EntityInterface $entity - * The entitiy being translated. + * The entity being translated. * @param \Drupal\Core\Language\Language $source * The language to be used as source. * @param \Drupal\Core\Language\Language $target diff --git c/core/modules/content_translation/content_translation.pages.inc.BACKUP.23891.inc w/core/modules/content_translation/content_translation.pages.inc.BACKUP.23891.inc deleted file mode 100644 index f4eba85..0000000 --- c/core/modules/content_translation/content_translation.pages.inc.BACKUP.23891.inc +++ /dev/null @@ -1,289 +0,0 @@ -entityType()); - $entity_manager = \Drupal::entityManager(); - $languages = language_list(); - $original = $entity->getUntranslated()->language()->id; - $translations = $entity->getTranslationLanguages(); - $field_ui = module_exists('field_ui') && user_access('administer ' . $entity->entityType() . ' fields'); - - $path = $controller->getViewPath($entity); - $base_path = $controller->getBasePath($entity); - $edit_path = $controller->getEditPath($entity); - - $header = array(t('Language'), t('Translation'), t('Source language'), t('Status'), t('Operations')); - $rows = array(); - - if (language_multilingual()) { - // If we have a view path defined for the current entity get the switch - // links based on it. - if ($path) { - $links = _content_translation_get_switch_links($path); - } - - // Determine whether the current entity is translatable. - $translatable = FALSE; - foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { - $field = $instance->getField(); - if ($field['translatable']) { - $translatable = TRUE; - break; - } - } - - foreach ($languages as $language) { - $language_name = $language->name; - $langcode = $language->id; - $add_path = $base_path . '/translations/add/' . $original . '/' . $langcode; - $translate_path = $base_path . '/translations/edit/' . $langcode; - $delete_path = $base_path . '/translations/delete/' . $langcode; - - if ($base_path) { - $add_links = _content_translation_get_switch_links($add_path); - $edit_links = _content_translation_get_switch_links($edit_path); - $translate_links = _content_translation_get_switch_links($translate_path); - $delete_links = _content_translation_get_switch_links($delete_path); - } - - $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; - $translation = $translations[$langcode]; - $label = $entity->label($langcode); - $link = isset($links->links[$langcode]['href']) ? $links->links[$langcode] : array('href' => $path, '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 ($edit_path && $entity->access('update')) { - $links['edit'] = isset($edit_links->links[$langcode]['href']) ? $edit_links->links[$langcode] : array('href' => $edit_path, '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 ($field_ui) { - $entity_path = $entity_manager->getAdminPath($entity->entityType(), $entity->bundle()); - // Link directly to the fields tab to make it easier to find the - // setting to enable translation on fields. - $path = $entity_path . '/fields'; - $links['nofields'] = array('title' => t('No translatable fields'), 'href' => $path, 'language' => $language); - } - } - - $status = t('Not translated'); - } - - $rows[] = array($language_name, $row_title, $source_name, $status, $operations); - } - } - - drupal_set_title(t('Translations of %label', array('%label' => $entity->label())), PASS_THROUGH); - - // 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; -} - -/** - * 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 = language_negotiation_get_switch_links(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 = language_negotiation_get_switch_links(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 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 : language(Language::TYPE_CONTENT); - // @todo Exploit the upcoming hook_entity_prepare() when available. - content_translation_prepare_translation($entity, $source, $target); - $info = $entity->entityInfo(); - $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default'; - $form_state['langcode'] = $target->id; - $form_state['content_translation']['source'] = $source; - $form_state['content_translation']['target'] = $target; - $controller = content_translation_controller($entity->entityType()); - $form_state['content_translation']['translation_form'] = !$entity->access('update'); - return \Drupal::entityManager()->getForm($entity, $operation, $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 Use \Drupal\content_translation\Controller\ContentTranslationController::edit() - */ -function content_translation_edit_page(EntityInterface $entity, Language $language = NULL) { - $language = !empty($language) ? $language : language(Language::TYPE_CONTENT); - $info = $entity->entityInfo(); - $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default'; - $form_state['langcode'] = $language->id; - $form_state['content_translation']['translation_form'] = TRUE; - return \Drupal::entityManager()->getForm($entity, $operation, $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->getPropertyValues()); - } -} - -/** - * Form constructor for the translation deletion confirmation. - * - * @deprecated Use \Drupal\content_translation\Form\ContentTranslationForm::deleteTranslation() - */ -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/content_translation.pages.inc.BASE.23891.inc w/core/modules/content_translation/content_translation.pages.inc.BASE.23891.inc deleted file mode 100644 index be151b9..0000000 --- c/core/modules/content_translation/content_translation.pages.inc.BASE.23891.inc +++ /dev/null @@ -1,287 +0,0 @@ -entityType()); - $entity_manager = \Drupal::entityManager(); - $languages = language_list(); - $original = $entity->getUntranslated()->language()->id; - $translations = $entity->getTranslationLanguages(); - $field_ui = module_exists('field_ui') && user_access('administer ' . $entity->entityType() . ' fields'); - - $path = $controller->getViewPath($entity); - $base_path = $controller->getBasePath($entity); - $edit_path = $controller->getEditPath($entity); - - $header = array(t('Language'), t('Translation'), t('Source language'), t('Status'), t('Operations')); - $rows = array(); - - if (language_multilingual()) { - // If we have a view path defined for the current entity get the switch - // links based on it. - if ($path) { - $links = _content_translation_get_switch_links($path); - } - - // Determine whether the current entity is translatable. - $translatable = FALSE; - foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { - $field = $instance->getField(); - if ($field['translatable']) { - $translatable = TRUE; - break; - } - } - - foreach ($languages as $language) { - $language_name = $language->name; - $langcode = $language->id; - $add_path = $base_path . '/translations/add/' . $original . '/' . $langcode; - $translate_path = $base_path . '/translations/edit/' . $langcode; - $delete_path = $base_path . '/translations/delete/' . $langcode; - - if ($base_path) { - $add_links = _content_translation_get_switch_links($add_path); - $edit_links = _content_translation_get_switch_links($edit_path); - $translate_links = _content_translation_get_switch_links($translate_path); - $delete_links = _content_translation_get_switch_links($delete_path); - } - - $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; - $translation = $translations[$langcode]; - $label = $entity->label($langcode); - $link = isset($links->links[$langcode]['href']) ? $links->links[$langcode] : array('href' => $path, '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 ($edit_path && $entity->access('update')) { - $links['edit'] = isset($edit_links->links[$langcode]['href']) ? $edit_links->links[$langcode] : array('href' => $edit_path, '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 ($field_ui) { - $entity_path = $entity_manager->getAdminPath($entity->entityType(), $entity->bundle()); - // Link directly to the fields tab to make it easier to find the - // setting to enable translation on fields. - $path = $entity_path . '/fields'; - $links['nofields'] = array('title' => t('No translatable fields'), 'href' => $path, 'language' => $language); - } - } - - $status = t('Not translated'); - } - - $rows[] = array($language_name, $row_title, $source_name, $status, $operations); - } - } - - drupal_set_title(t('Translations of %label', array('%label' => $entity->label())), PASS_THROUGH); - - // 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; -} - -/** - * 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 = language_negotiation_get_switch_links(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 = language_negotiation_get_switch_links(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 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 : language(Language::TYPE_CONTENT); - // @todo Exploit the upcoming hook_entity_prepare() when available. - content_translation_prepare_translation($entity, $source, $target); - $info = $entity->entityInfo(); - $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default'; - $form_state['langcode'] = $target->id; - $form_state['content_translation']['source'] = $source; - $form_state['content_translation']['target'] = $target; - $controller = content_translation_controller($entity->entityType()); - $form_state['content_translation']['translation_form'] = !$entity->access('update'); - return \Drupal::entityManager()->getForm($entity, $operation, $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 Use \Drupal\content_translation\Controller\ContentTranslationController::edit() - */ -function content_translation_edit_page(EntityInterface $entity, Language $language = NULL) { - $language = !empty($language) ? $language : language(Language::TYPE_CONTENT); - $info = $entity->entityInfo(); - $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default'; - $form_state['langcode'] = $language->id; - $form_state['content_translation']['translation_form'] = TRUE; - return \Drupal::entityManager()->getForm($entity, $operation, $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) { - $source_translation = $entity->getTranslation($source->id); - $entity->addTranslation($target->id, $source_translation->getPropertyValues()); -} - -/** - * Form constructor for the translation deletion confirmation. - * - * @deprecated Use \Drupal\content_translation\Form\ContentTranslationForm::deleteTranslation() - */ -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/content_translation.pages.inc.LOCAL.23891.inc w/core/modules/content_translation/content_translation.pages.inc.LOCAL.23891.inc deleted file mode 100644 index f4eba85..0000000 --- c/core/modules/content_translation/content_translation.pages.inc.LOCAL.23891.inc +++ /dev/null @@ -1,289 +0,0 @@ -entityType()); - $entity_manager = \Drupal::entityManager(); - $languages = language_list(); - $original = $entity->getUntranslated()->language()->id; - $translations = $entity->getTranslationLanguages(); - $field_ui = module_exists('field_ui') && user_access('administer ' . $entity->entityType() . ' fields'); - - $path = $controller->getViewPath($entity); - $base_path = $controller->getBasePath($entity); - $edit_path = $controller->getEditPath($entity); - - $header = array(t('Language'), t('Translation'), t('Source language'), t('Status'), t('Operations')); - $rows = array(); - - if (language_multilingual()) { - // If we have a view path defined for the current entity get the switch - // links based on it. - if ($path) { - $links = _content_translation_get_switch_links($path); - } - - // Determine whether the current entity is translatable. - $translatable = FALSE; - foreach (field_info_instances($entity->entityType(), $entity->bundle()) as $instance) { - $field = $instance->getField(); - if ($field['translatable']) { - $translatable = TRUE; - break; - } - } - - foreach ($languages as $language) { - $language_name = $language->name; - $langcode = $language->id; - $add_path = $base_path . '/translations/add/' . $original . '/' . $langcode; - $translate_path = $base_path . '/translations/edit/' . $langcode; - $delete_path = $base_path . '/translations/delete/' . $langcode; - - if ($base_path) { - $add_links = _content_translation_get_switch_links($add_path); - $edit_links = _content_translation_get_switch_links($edit_path); - $translate_links = _content_translation_get_switch_links($translate_path); - $delete_links = _content_translation_get_switch_links($delete_path); - } - - $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; - $translation = $translations[$langcode]; - $label = $entity->label($langcode); - $link = isset($links->links[$langcode]['href']) ? $links->links[$langcode] : array('href' => $path, '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 ($edit_path && $entity->access('update')) { - $links['edit'] = isset($edit_links->links[$langcode]['href']) ? $edit_links->links[$langcode] : array('href' => $edit_path, '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 ($field_ui) { - $entity_path = $entity_manager->getAdminPath($entity->entityType(), $entity->bundle()); - // Link directly to the fields tab to make it easier to find the - // setting to enable translation on fields. - $path = $entity_path . '/fields'; - $links['nofields'] = array('title' => t('No translatable fields'), 'href' => $path, 'language' => $language); - } - } - - $status = t('Not translated'); - } - - $rows[] = array($language_name, $row_title, $source_name, $status, $operations); - } - } - - drupal_set_title(t('Translations of %label', array('%label' => $entity->label())), PASS_THROUGH); - - // 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; -} - -/** - * 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 = language_negotiation_get_switch_links(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 = language_negotiation_get_switch_links(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 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 : language(Language::TYPE_CONTENT); - // @todo Exploit the upcoming hook_entity_prepare() when available. - content_translation_prepare_translation($entity, $source, $target); - $info = $entity->entityInfo(); - $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default'; - $form_state['langcode'] = $target->id; - $form_state['content_translation']['source'] = $source; - $form_state['content_translation']['target'] = $target; - $controller = content_translation_controller($entity->entityType()); - $form_state['content_translation']['translation_form'] = !$entity->access('update'); - return \Drupal::entityManager()->getForm($entity, $operation, $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 Use \Drupal\content_translation\Controller\ContentTranslationController::edit() - */ -function content_translation_edit_page(EntityInterface $entity, Language $language = NULL) { - $language = !empty($language) ? $language : language(Language::TYPE_CONTENT); - $info = $entity->entityInfo(); - $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default'; - $form_state['langcode'] = $language->id; - $form_state['content_translation']['translation_form'] = TRUE; - return \Drupal::entityManager()->getForm($entity, $operation, $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->getPropertyValues()); - } -} - -/** - * Form constructor for the translation deletion confirmation. - * - * @deprecated Use \Drupal\content_translation\Form\ContentTranslationForm::deleteTranslation() - */ -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/content_translation.pages.inc.REMOTE.23891.inc w/core/modules/content_translation/content_translation.pages.inc.REMOTE.23891.inc deleted file mode 100644 index e69de29..0000000 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 3a53710..d4d4e93 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 @@ -59,8 +59,8 @@ public function access(Route $route, Request $request) { switch ($operation) { case 'create': - $source = language_load($request->attributes->get('source')); - $target = language_load($request->attributes->get('target')); + $source = $request->attributes->get('source'); + $target = $request->attributes->get('target'); $source = !empty($source) ? $source : $entity->language(); $target = !empty($target) ? $target : language(Language::TYPE_CONTENT); return ($source->id != $target->id @@ -72,7 +72,7 @@ public function access(Route $route, Request $request) { case 'update': case 'delete': - $language = language_load($request->attributes->get('language')); + $language = $request->attributes->get('language'); $language = !empty($language) ? $language : language(Language::TYPE_CONTENT); return isset($languages[$language->id]) && $language->id != $entity->getUntranslated()->language()->id diff --git c/core/modules/content_translation/lib/Drupal/content_translation/Controller/ContentTranslationController.php w/core/modules/content_translation/lib/Drupal/content_translation/Controller/ContentTranslationController.php index f629330..0e2853e 100644 --- c/core/modules/content_translation/lib/Drupal/content_translation/Controller/ContentTranslationController.php +++ w/core/modules/content_translation/lib/Drupal/content_translation/Controller/ContentTranslationController.php @@ -78,7 +78,7 @@ public function overview(EntityInterface $entity) { ); $rows = array(); - if (language_multilingual()) { + if ($this->languageManager()->isMultilingual()) { // If we have a view path defined for the current entity get the switch // links based on it. if ($path) { 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 5d30c4c..f83e834 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 @@ -90,6 +90,12 @@ public function routes(RouteBuildEvent $event) { 'entity' => array( 'type' => 'entity:' . $entity_type, ), + 'source' => array( + 'type' => 'language', + ), + 'target' => array( + 'type' => 'language', + ), ), ) ); @@ -111,6 +117,9 @@ public function routes(RouteBuildEvent $event) { 'entity' => array( 'type' => 'entity:' . $entity_type, ), + 'language' => array( + 'type' => 'language', + ), ), ) ); @@ -132,6 +141,9 @@ public function routes(RouteBuildEvent $event) { 'entity' => array( 'type' => 'entity:' . $entity_type, ), + 'language' => array( + 'type' => 'language', + ), ), ) );