diff --git a/CHANGELOG.txt b/CHANGELOG.txt index fbaa3c3..085b239 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,7 +1,6 @@ Entity translation 7.x-1.x, xxxx-xx-xx -------------------------------------- -#1694478 by bforchhammer: Delete menu items when translation is deleted. #1770250 by bforchhammer, plach: Fixed Translatable fields disappear when editing default language (entities other than node). #1377542 by bforchhammer | Daemon_Byte: Fixed Do not always use the admin theme. diff --git a/entity_translation.install b/entity_translation.install index ffff0b8..e16a565 100644 --- a/entity_translation.install +++ b/entity_translation.install @@ -93,6 +93,36 @@ function entity_translation_install() { // Make translation use the content language type. variable_set('translation_language_type', LANGUAGE_TYPE_CONTENT); + + // Grant the 'edit original values' permission, so we don't break editing on existing sites. + $msg = _entity_translation_grant_permissions(); + drupal_set_message($msg); +} + +/** + * Grant 'edit original values' permission to roles which have entity editing permissions. + */ +function _entity_translation_grant_permissions() { + $permissions = array('administer nodes', 'post comments', 'edit own comments', 'administer taxonomy', 'administer users'); + foreach (node_permissions_get_configured_types() as $type) { + $permissions[] = "create $type content"; + $permissions[] = "edit own $type content"; + $permissions[] = "edit any $type content"; + } + foreach (taxonomy_get_vocabularies() as $vocabulary) { + $permissions[] = "edit terms in {$vocabulary->vid}"; + } + + $roles = user_roles(FALSE, $permissions); + foreach ($roles as $rid => $role) { + user_role_grant_permissions($rid, array('edit original values')); + } + + $t = get_t(); + return $t('The %permission permission has been assigned to the following roles: %roles', array( + '%permission' => 'edit original values', + '%roles' => implode(', ', $roles), + )); } /** @@ -167,3 +197,10 @@ function entity_translation_update_7001() { ->condition('name', 'entity_translation') ->execute(); } + +/** + * Grant 'edit original values' permission to roles which have entity editing permissions. + */ +function entity_translation_update_7002() { + return _entity_translation_grant_permissions(); +} diff --git a/entity_translation_i18n_menu/entity_translation_i18n_menu.module b/entity_translation_i18n_menu/entity_translation_i18n_menu.module index 88a9315..a0242be 100644 --- a/entity_translation_i18n_menu/entity_translation_i18n_menu.module +++ b/entity_translation_i18n_menu/entity_translation_i18n_menu.module @@ -3,6 +3,9 @@ /** * @file * The menu specific translation functions and hook implementations. + * + * @todo + * - translation deletion */ /** @@ -349,40 +352,3 @@ function entity_translation_i18n_menu_entity_translation_upgrade($node, $transla menu_link_save($link, $node->menu); } } - -/** - * Implements hook_entity_translation_delete(). - */ -function entity_translation_i18n_menu_entity_translation_delete($entity_type, $entity, $langcode) { - list($entity_id, , ) = entity_extract_ids($entity_type, $entity); - - // Clean-up all menu module links that point to this node. - $result = db_select('menu_links', 'ml') - ->fields('ml', array('mlid', 'language')) - ->condition('link_path', 'node/' . $entity_id) - ->condition('module', 'menu') - ->execute() - ->fetchAllAssoc('mlid'); - - foreach ($result as $link) { - // Delete all menu links matching the deleted language. - if ($link->language == $langcode) { - menu_link_delete($link->mlid); - } - - // Delete string translations for all language-neutral menu items. - if ($link->language == LANGUAGE_NONE) { - $name = array('menu', 'item', $link->mlid); - foreach (array('title', 'description') as $key) { - $name[] = $key; - $source = i18n_string_get_source($name); - if(!empty($source->lid)) { - db_delete('locales_target') - ->condition('lid', $source->lid) - ->condition('language', $langcode) - ->execute(); - } - } - } - } -} diff --git a/entity_translation_i18n_menu/entity_translation_i18n_menu.test b/entity_translation_i18n_menu/entity_translation_i18n_menu.test index 19873ef..b3dd4ab 100644 --- a/entity_translation_i18n_menu/entity_translation_i18n_menu.test +++ b/entity_translation_i18n_menu/entity_translation_i18n_menu.test @@ -90,18 +90,6 @@ class EntityTranslationMenuTranslationTestCase extends EntityTranslationTestCase } /** - * Remove translation in given langcode from node. - */ - function removeTranslation($node, $langcode) { - $this->drupalGet('node/' . $node->nid . '/translate/delete/' . $langcode); - $this->drupalPost(NULL, array(), t('Delete')); - - // Check to make sure translation was deleted. - $this->drupalGet('node/' . $node->nid . '/edit/add/' . $node->language . '/' . $langcode); - $this->assertResponse(200, 'Translation add page found. Old translation deleted.'); - } - - /** * Edit a page menu item. * * Check that node form contains old menu link title, then replace with given @@ -155,12 +143,6 @@ class EntityTranslationMenuTranslationTestCase extends EntityTranslationTestCase // Check that English menu link has not changed. $this->get('en', ''); $this->assertText($link_title_en2); - - // Delete Spanish translation and check that the respective menu item has - // been deleted as well. - $this->removeTranslation($node, 'es'); - $this->get('es', ''); - $this->assertNoText($link_title_es2); } /** @@ -231,11 +213,5 @@ class EntityTranslationMenuTranslationTestCase extends EntityTranslationTestCase // Check that English menu link has not changed. $this->get('en', ''); $this->assertText($link_title_en2); - - // Delete Spanish translation and check that the respective menu item has - // been deleted as well. - $this->removeTranslation($node, 'es'); - $this->get('es', ''); - $this->assertNoText($link_title_es2); } }