Commit 69a5eefd authored by Dries's avatar Dries

Issue #1832778 by Schnitzel, ancamp, nagwani, YesCT, Lukas von Blarer, rvilar,...

Issue #1832778 by Schnitzel, ancamp, nagwani, YesCT, Lukas von Blarer, rvilar, Gábor Hojtsy: include translation operation in overviews for translatable entities.
parent 5cae7618
......@@ -136,6 +136,13 @@ function comment_admin_overview($form, &$form_state, $arg) {
'href' => 'comment/' . $comment->cid . '/edit',
'query' => $destination,
);
if (module_invoke('translation_entity', 'translate_access', $comment)) {
$links['translate'] = array(
'title' => t('translate'),
'href' => 'comment/' . $comment->cid . '/translations',
'query' => $destination,
);
}
$options[$comment->cid]['operations']['data'] = array(
'#type' => 'operations',
'#links' => $links,
......
......@@ -74,8 +74,11 @@ function setupTestFields() {
/**
* Overrides \Drupal\translation_entity\Tests\EntityTranslationUITest::createEntity().
*/
protected function createEntity($values, $langcode) {
$node = $this->drupalCreateNode(array('type' => $this->nodeBundle));
protected function createEntity($values, $langcode, $node_bundle = NULL) {
if (!isset($node_bundle)) {
$node_bundle = $this->nodeBundle;
}
$node = $this->drupalCreateNode(array('type' => $node_bundle));
$values['nid'] = $node->nid;
$values['uid'] = $node->uid;
return parent::createEntity($values, $langcode);
......@@ -92,4 +95,21 @@ protected function getNewEntityValues($langcode) {
) + parent::getNewEntityValues($langcode);
}
/**
* Tests translate link on comment content admin page.
*/
function testTranslateLinkCommentAdminPage() {
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer comments', 'translate any entity'));
$this->drupalLogin($this->admin_user);
$cid_translatable = $this->createEntity(array(), $this->langcodes[0], $this->nodeBundle);
$cid_untranslatable = $this->createEntity(array(), $this->langcodes[0], 'page');
// Verify translation links.
$this->drupalGet('admin/content/comment');
$this->assertResponse(200);
$this->assertLinkByHref('comment/' . $cid_translatable . '/translations');
$this->assertNoLinkByHref('comment/' . $cid_untranslatable . '/translations');
}
}
......@@ -59,6 +59,23 @@ function getTranslatorPermissions() {
return array("edit any $this->bundle content", "translate $this->entityType entities", 'edit original values');
}
/**
* Tests translate link on content admin page.
*/
function testTranslateLinkContentAdminPage() {
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'access content overview', 'administer nodes', 'bypass node access'));
$this->drupalLogin($this->admin_user);
$page = $this->drupalCreateNode(array('type' => 'page'));
$article = $this->drupalCreateNode(array('type' => 'article'));
// Verify translation links.
$this->drupalGet('admin/content');
$this->assertResponse(200);
$this->assertLinkByHref('node/' . $article->nid . '/translations');
$this->assertNoLinkByHref('node/' . $page->nid . '/translations');
}
/**
* Overrides \Drupal\translation_entity\Tests\EntityTranslationUITest::getNewEntityValues().
*/
......
......@@ -560,6 +560,13 @@ function node_admin_nodes() {
'query' => $destination,
);
}
if (module_invoke('translation_entity', 'enabled', 'node', $node->bundle())) {
$operations['translate'] = array(
'title' => t('translate'),
'href' => 'node/' . $node->nid . '/translations',
'query' => $destination,
);
}
$options[$node->nid]['operations'] = array();
if (count($operations) > 1) {
// Render an unordered list of operations links.
......
......@@ -72,8 +72,11 @@ function getTranslatorPermissions() {
/**
* Overrides \Drupal\translation_entity\Tests\EntityTranslationUITest::createEntity().
*/
protected function createEntity($values, $langcode) {
$vocabulary = taxonomy_vocabulary_machine_name_load($this->bundle);
protected function createEntity($values, $langcode, $vocabulary_name = NULL) {
if (!isset($vocabulary_name)) {
$vocabulary_name = $this->bundle;
}
$vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary_name);
$values['vid'] = $vocabulary->id();
return parent::createEntity($values, $langcode);
}
......@@ -99,4 +102,41 @@ public function testTranslationUI() {
$this->assertEqual('taxonomy_term', $rows[0]->entity_type);
$this->assertEqual('taxonomy_term', $rows[1]->entity_type);
}
/**
* Tests translate link on vocabulary term list.
*/
function testTranslateLinkVocabularyAdminPage() {
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer taxonomy', 'translate any entity'));
$this->drupalLogin($this->admin_user);
$translatable_vocabulary_name = taxonomy_vocabulary_machine_name_load($this->bundle)->name;
$translatable_tid = $this->createEntity(array(), $this->langcodes[0]);
// Create an untranslatable vocabulary.
$untranslatable_vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => 'untranslatable_voc',
'description' => $this->randomName(),
'machine_name' => 'untranslatable_voc',
'langcode' => LANGUAGE_NOT_SPECIFIED,
'help' => '',
'weight' => mt_rand(0, 10),
));
taxonomy_vocabulary_save($untranslatable_vocabulary);
$untranslatable_vocabulary_name = $untranslatable_vocabulary->name;
$untranslatable_tid = $this->createEntity(array(), $this->langcodes[0], $untranslatable_vocabulary_name);
// Verify translation links.
$this->drupalGet('admin/structure/taxonomy/' . $translatable_vocabulary_name);
$this->assertResponse(200);
$this->assertLinkByHref('term/' . $translatable_tid . '/translations');
$this->assertLinkByHref('term/' . $translatable_tid . '/edit');
$this->drupalGet('admin/structure/taxonomy/' . $untranslatable_vocabulary_name);
$this->assertResponse(200);
$this->assertLinkByHref('term/' . $untranslatable_tid . '/edit');
$this->assertNoLinkByHref('term/' . $untranslatable_tid . '/translations');
}
}
......@@ -249,7 +249,7 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) {
}
}
}
$destination = drupal_get_destination();
// Build the actual form.
foreach ($current_page as $key => $term) {
// Save the term for the current page so we don't have to load it a second time.
......@@ -285,9 +285,16 @@ function taxonomy_overview_terms($form, &$form_state, Vocabulary $vocabulary) {
);
}
$operations = array(
'edit' => array('title' => t('edit'), 'href' => 'taxonomy/term/' . $term->tid . '/edit', 'query' => drupal_get_destination()),
'delete' => array('title' => t('delete'), 'href' => 'taxonomy/term/' . $term->tid . '/delete', 'query' => drupal_get_destination()),
'edit' => array('title' => t('edit'), 'href' => 'taxonomy/term/' . $term->tid . '/edit', 'query' => $destination),
'delete' => array('title' => t('delete'), 'href' => 'taxonomy/term/' . $term->tid . '/delete', 'query' => $destination),
);
if (module_invoke('translation_entity', 'translate_access', $term)) {
$operations['translate'] = array(
'title' => t('translate'),
'href' => 'taxonomy/term/' . $term->tid . '/translations',
'query' => $destination,
);
}
$form[$key]['operations'] = array(
'#type' => 'operations',
'#links' => $operations,
......
......@@ -59,4 +59,19 @@ protected function getNewEntityValues($langcode) {
return array('name' => $this->name) + parent::getNewEntityValues($langcode);
}
/**
* Tests translate link on user admin list.
*/
function testTranslateLinkUserAdminPage() {
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer users', 'translate any entity'));
$this->drupalLogin($this->admin_user);
$uid = $this->createEntity(array('name' => $this->randomName()), $this->langcodes[0]);
// Verify translation links.
$this->drupalGet('admin/people');
$this->assertResponse(200);
$this->assertLinkByHref('user/' . $uid . '/translations');
}
}
......@@ -192,11 +192,11 @@ function user_admin_account() {
);
$destination = drupal_get_destination();
$status = array(t('blocked'), t('active'));
$roles = array_map('check_plain', user_roles(TRUE));
$accounts = array();
foreach ($result as $account) {
$account = user_load($account->uid);
$users_roles = array();
$roles_result = db_query('SELECT rid FROM {users_roles} WHERE uid = :uid', array(':uid' => $account->uid));
foreach ($roles_result as $user_role) {
......@@ -214,9 +214,16 @@ function user_admin_account() {
$links = array();
$links['edit'] = array(
'title' => t('edit'),
'href' => "user/$account->uid/edit",
'href' => 'user/' . $account->uid . '/edit',
'query' => $destination,
);
if (module_invoke('translation_entity', 'translate_access', $account)) {
$links['translate'] = array(
'title' => t('translate'),
'href' => 'user/' . $account->uid . '/translations',
'query' => $destination,
);
}
$options[$account->uid]['operations']['data'] = array(
'#type' => 'operations',
'#links' => $links,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment