diff --git a/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php b/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php index 051574a..d86ecb9 100644 --- a/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php +++ b/core/modules/content_translation/src/Access/ContentTranslationManageAccessCheck.php @@ -63,20 +63,20 @@ public function __construct(EntityManagerInterface $manager, LanguageManagerInte * @param string $language * (optional) For an update or delete operation, the language code of the * translation being updated or deleted. - * @param string $_entity_type_id + * @param string $entity_type_id * (optional) The entity type ID. * * @return string * A \Drupal\Core\Access\AccessInterface constant value. */ - public function access(Route $route, Request $request, AccountInterface $account, $source = NULL, $target = NULL, $language = NULL, $_entity_type_id = NULL) { + public function access(Route $route, Request $request, AccountInterface $account, $source = NULL, $target = NULL, $language = NULL, $entity_type_id = NULL) { /* @var $entity \Drupal\Core\Entity\ContentEntityInterface */ - if ($entity = $request->attributes->get($_entity_type_id)) { + if ($entity = $request->attributes->get($entity_type_id)) { $operation = $route->getRequirement('_access_content_translation_manage'); - /* @var \Drupal\content_translation\ContentTranslationHandlerInterface $controller */ - $controller = $this->entityManager->getController($entity->getEntityTypeId(), 'translation'); + /* @var \Drupal\content_translation\ContentTranslationHandlerInterface $handler */ + $handler = $this->entityManager->getController($entity->getEntityTypeId(), 'translation'); // Load translation. $translations = $entity->getTranslationLanguages(); @@ -90,7 +90,7 @@ public function access(Route $route, Request $request, AccountInterface $account && isset($languages[$source_language->getId()]) && isset($languages[$target_language->getId()]) && !isset($translations[$target_language->getId()]) - && $controller->getTranslationAccess($entity, $operation)) + && $handler->getTranslationAccess($entity, $operation)) ? static::ALLOW : static::DENY; case 'update': @@ -99,7 +99,7 @@ public function access(Route $route, Request $request, AccountInterface $account return isset($languages[$language->getId()]) && $language->getId() != $entity->getUntranslated()->language()->getId() && isset($translations[$language->getId()]) - && $controller->getTranslationAccess($entity, $operation) + && $handler->getTranslationAccess($entity, $operation) ? static::ALLOW : static::DENY; } } diff --git a/core/modules/content_translation/src/Controller/ContentTranslationController.php b/core/modules/content_translation/src/Controller/ContentTranslationController.php index 12563c9..d4efb59 100644 --- a/core/modules/content_translation/src/Controller/ContentTranslationController.php +++ b/core/modules/content_translation/src/Controller/ContentTranslationController.php @@ -40,21 +40,21 @@ public function prepareTranslation(ContentEntityInterface $entity, LanguageInter * * @param \Symfony\Component\HttpFoundation\Request $request * The request object from which to extract the entity type. - * @param string $_entity_type_id + * @param string $entity_type_id * (optional) The entity type ID. * * @return array * Array of page elements to render. */ - public function overview(Request $request, $_entity_type_id = NULL) { - $entity = $request->attributes->get($_entity_type_id); + public function overview(Request $request, $entity_type_id = NULL) { + $entity = $request->attributes->get($entity_type_id); $account = $this->currentUser(); - $handler = $this->entityManager()->getController($_entity_type_id, 'translation'); + $handler = $this->entityManager()->getController($entity_type_id, 'translation'); $languages = $this->languageManager()->getLanguages(); $original = $entity->getUntranslated()->language()->getId(); $translations = $entity->getTranslationLanguages(); - $field_ui = $this->moduleHandler()->moduleExists('field_ui') && $account->hasPermission('administer ' . $_entity_type_id . ' fields'); + $field_ui = $this->moduleHandler()->moduleExists('field_ui') && $account->hasPermission('administer ' . $entity_type_id . ' fields'); $rows = array(); $show_source_column = FALSE; @@ -62,7 +62,7 @@ public function overview(Request $request, $_entity_type_id = NULL) { if ($this->languageManager()->isMultilingual()) { // Determine whether the current entity is translatable. $translatable = FALSE; - foreach ($this->entityManager->getFieldDefinitions($_entity_type_id, $entity->bundle()) as $instance) { + foreach ($this->entityManager->getFieldDefinitions($entity_type_id, $entity->bundle()) as $instance) { if ($instance->isTranslatable()) { $translatable = TRUE; break; @@ -80,25 +80,25 @@ public function overview(Request $request, $_entity_type_id = NULL) { $langcode = $language->getId(); $add_url = new Url( - 'content_translation.translation_add_' . $_entity_type_id, + 'content_translation.translation_add_' . $entity_type_id, array( 'source' => $original, 'target' => $language->getId(), - $_entity_type_id => $entity->id(), + $entity_type_id => $entity->id(), ) ); $edit_url = new Url( - 'content_translation.translation_edit_' . $_entity_type_id, + 'content_translation.translation_edit_' . $entity_type_id, array( 'language' => $language->getId(), - $_entity_type_id => $entity->id(), + $entity_type_id => $entity->id(), ) ); $delete_url = new Url( - 'content_translation.translation_delete_' . $_entity_type_id, + 'content_translation.translation_delete_' . $entity_type_id, array( 'language' => $language->getId(), - $_entity_type_id => $entity->id(), + $entity_type_id => $entity->id(), ) ); $operations = array( @@ -236,14 +236,14 @@ public function overview(Request $request, $_entity_type_id = NULL) { * language. * @param \Symfony\Component\HttpFoundation\Request $request * The request object from which to extract the entity type. - * @param string $_entity_type_id + * @param string $entity_type_id * (optional) The entity type ID. * * @return array * A processed form array ready to be rendered. */ - public function add(LanguageInterface $source, LanguageInterface $target, Request $request, $_entity_type_id = NULL) { - $entity = $request->attributes->get($_entity_type_id); + public function add(LanguageInterface $source, LanguageInterface $target, Request $request, $entity_type_id = NULL) { + $entity = $request->attributes->get($entity_type_id); // @todo Exploit the upcoming hook_entity_prepare() when available. // See https://www.drupal.org/node/1810394. @@ -253,12 +253,14 @@ public function add(LanguageInterface $source, LanguageInterface $target, Reques // $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default'; // See https://www.drupal.org/node/2006348. $operation = 'default'; - $form_state['langcode'] = $target->getId(); - $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); + $form_state_additions = array(); + $form_state_additions['langcode'] = $target->getId(); + $form_state_additions['content_translation']['source'] = $source; + $form_state_additions['content_translation']['target'] = $target; + $form_state_additions['content_translation']['translation_form'] = !$entity->access('update'); + + return $this->entityFormBuilder()->getForm($entity, $operation, $form_state_additions); } /** @@ -269,23 +271,25 @@ public function add(LanguageInterface $source, LanguageInterface $target, Reques * language. * @param \Symfony\Component\HttpFoundation\Request $request * The request object from which to extract the entity type. - * @param string $_entity_type_id + * @param string $entity_type_id * (optional) The entity type ID. * * @return array * A processed form array ready to be rendered. */ - public function edit(LanguageInterface $language, Request $request, $_entity_type_id = NULL) { - $entity = $request->attributes->get($_entity_type_id); + public function edit(LanguageInterface $language, Request $request, $entity_type_id = NULL) { + $entity = $request->attributes->get($entity_type_id); // @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'; - $form_state['langcode'] = $language->getId(); - $form_state['content_translation']['translation_form'] = TRUE; - return $this->entityFormBuilder()->getForm($entity, $operation, $form_state); + $form_state_additions = array(); + $form_state_additions['langcode'] = $language->getId(); + $form_state_additions['content_translation']['translation_form'] = TRUE; + + return $this->entityFormBuilder()->getForm($entity, $operation, $form_state_additions); } } diff --git a/core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php b/core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php index c27b5e8..1b723ce 100644 --- a/core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php +++ b/core/modules/content_translation/src/Form/ContentTranslationDeleteForm.php @@ -40,8 +40,8 @@ public function getFormId() { /** * {@inheritdoc} */ - public function buildForm(array $form, FormStateInterface $form_state, $_entity_type_id = NULL, $language = NULL) { - $this->entity = $this->getRequest()->attributes->get($_entity_type_id); + public function buildForm(array $form, FormStateInterface $form_state, $entity_type_id = NULL, $language = NULL) { + $this->entity = $this->getRequest()->attributes->get($entity_type_id); $this->language = language_load($language); return parent::buildForm($form, $form_state); } diff --git a/core/modules/content_translation/tests/src/Access/ContentTranslationManageAccessCheckTest.php b/core/modules/content_translation/tests/src/Access/ContentTranslationManageAccessCheckTest.php index 2960d14..cc6d15e 100644 --- a/core/modules/content_translation/tests/src/Access/ContentTranslationManageAccessCheckTest.php +++ b/core/modules/content_translation/tests/src/Access/ContentTranslationManageAccessCheckTest.php @@ -86,9 +86,9 @@ public function testCreateAccess() { // The request params. $language = 'en'; - $_entity_type_id = 'node'; + $entity_type_id = 'node'; - $this->assertEquals($check->access($route, $request, $account, $source, $target, $language, $_entity_type_id), AccessInterface::ALLOW, "The access check matches"); + $this->assertEquals($check->access($route, $request, $account, $source, $target, $language, $entity_type_id), AccessInterface::ALLOW, "The access check matches"); } }