diff --git a/core/modules/comment/comment.views.inc b/core/modules/comment/comment.views.inc index f7ce2f9..8f5b186 100644 --- a/core/modules/comment/comment.views.inc +++ b/core/modules/comment/comment.views.inc @@ -376,6 +376,17 @@ function comment_views_data() { ), ); + // Entity translation field. + if (drupal_container()->get('module_handler')->moduleExists('translation_entity')) { + $data['comment']['translation_link'] = array( + 'title' => t('Translation link'), + 'help' => t('Provide a link to the translations overview for comments.'), + 'field' => array( + 'id' => 'translation_entity_link', + ), + ); + } + // node_comment_statistics table // define the group diff --git a/core/modules/node/node.views.inc b/core/modules/node/node.views.inc index 2e8ab14..d3fb851 100644 --- a/core/modules/node/node.views.inc +++ b/core/modules/node/node.views.inc @@ -226,6 +226,17 @@ function node_views_data() { ); } + // Entity translation field. + if (drupal_container()->get('module_handler')->moduleExists('translation_entity')) { + $data['node']['translation_link'] = array( + 'title' => t('Translation link'), + 'help' => t('Provide a link to the translations overview for nodes.'), + 'field' => array( + 'id' => 'translation_entity_link', + ), + ); + } + // Define some fields based upon views_handler_field_entity in the entity // table so they can be re-used with other query backends. // @see views_handler_field_entity diff --git a/core/modules/taxonomy/taxonomy.views.inc b/core/modules/taxonomy/taxonomy.views.inc index c82873e..d683d68 100644 --- a/core/modules/taxonomy/taxonomy.views.inc +++ b/core/modules/taxonomy/taxonomy.views.inc @@ -176,6 +176,17 @@ function taxonomy_views_data() { ), ); + // Entity translation field. + if (drupal_container()->get('module_handler')->moduleExists('translation_entity')) { + $data['taxonomy_term_data']['translation_link'] = array( + 'title' => t('Translation link'), + 'help' => t('Provide a link to the translations overview for taxonomy terms.'), + 'field' => array( + 'id' => 'translation_entity_link', + ), + ); + } + // taxonomy_index table $data['taxonomy_index']['table']['group'] = t('Taxonomy term'); diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Plugin/views/field/TranslationLink.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Plugin/views/field/TranslationLink.php new file mode 100644 index 0000000..aa877fe --- /dev/null +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Plugin/views/field/TranslationLink.php @@ -0,0 +1,90 @@ + '', 'translatable' => TRUE); + return $options; + } + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::buildOptionsForm(). + */ + public function buildOptionsForm(&$form, &$form_state) { + $form['text'] = array( + '#type' => 'textfield', + '#title' => t('Text to display'), + '#default_value' => $this->options['text'], + ); + parent::buildOptionsForm($form, $form_state); + } + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::render(). + */ + function render($values) { + return $this->render_link($this->get_entity($values), $values); + } + + /** + * Alters the field to render a link. + * + * @param \Drupal\Core\Entity\EntityInterface $entity + * The entity being rendered. + * @param \stdClass $values + * The current row of the views result. + * + * @return string + * The acutal rendered text (without the link) of this field. + */ + public function render_link(EntityInterface $entity, \stdClass $values) { + if (module_invoke('translation_entity', 'translate_access', $entity)) { + $text = !empty($this->options['text']) ? $this->options['text'] : t('view'); + + $this->options['alter']['make_link'] = TRUE; + $uri = $entity->uri(); + $this->options['alter']['path'] = $uri['path'] . '/translations'; + + return $text; + } + } + + /** + * Overrides \Drupal\views\Plugin\views\Plugin\field\FieldPluginBase::query(). + */ + public function query() { + } + + /** + * Overrides \Drupal\views\Plugin\views\Plugin\field\FieldPluginBase::click_sortable(). + */ + public function click_sortable() { + return FALSE; + } + +} diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/Views/TranslationLinkTest.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/Views/TranslationLinkTest.php new file mode 100644 index 0000000..4f0ca76 --- /dev/null +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/Views/TranslationLinkTest.php @@ -0,0 +1,75 @@ + 'Entity Translation: Link field', + 'description' => 'Tests the Entity translation overview link field handler.', + 'group' => 'Views Modules', + ); + } + + function setUp() { + // @todo Use entity_type once it is has multilingual Views integration. + $this->entityType = 'user'; + + parent::setUp(); + + ViewTestData::importTestViews(get_class($this), array('translation_entity_test_views')); + } + + /** + * Implements \Drupal\translation_entity\Tests\EntityTranslationUITest::getTranslatorPermission(). + */ + function getTranslatorPermissions() { + return array("translate $this->entityType entities", 'edit original values'); + } + + /** + * Tests the Entity translation overview link field handler. + */ + public function testTranslationLink() { + $this->drupalGet('test-entity-translations-link'); + $this->assertLinkByHref('user/1/translations'); + } + + /** + * Overrides \Drupal\translation_entity\Tests\EntityTranslationUITest::testTranslationUI(). + */ + public function testTranslationUI() { + // @todo \Drupal\translation_entity\Tests\EntityTranslationUITest contains + // essential helper methods that should be seprarated from test methods. + } + +} diff --git a/core/modules/translation_entity/tests/modules/translation_entity_test_views/test_views/views.view.test_entity_translations_link.yml b/core/modules/translation_entity/tests/modules/translation_entity_test_views/test_views/views.view.test_entity_translations_link.yml new file mode 100644 index 0000000..c431338 --- /dev/null +++ b/core/modules/translation_entity/tests/modules/translation_entity_test_views/test_views/views.view.test_entity_translations_link.yml @@ -0,0 +1,96 @@ +base_field: uid +base_table: users +core: 8.x +description: '' +disabled: '0' +display: + default: + display_plugin: default + id: default + display_title: Master + position: '' + display_options: + access: + type: none + cache: + type: none + query: + type: views_query + exposed_form: + type: basic + options: + submit_button: Filter + reset_button: '1' + reset_button_label: Reset + pager: + type: full + options: + items_per_page: '50' + style: + type: table + options: + columns: + name: name + translation_link: translation_link + default: created + row: + type: fields + fields: + name: + id: name + table: users + field: name + label: Username + link_to_user: '1' + format_username: '1' + translation_link: + id: translation_link + table: users + field: translation_link + label: 'Translation link' + exclude: '0' + alter: + alter_text: '0' + element_class: '' + element_default_classes: '1' + empty: '' + hide_empty: '0' + empty_zero: '0' + hide_alter_empty: '1' + text: Translate + filters: + uid_raw: + id: uid_raw + table: users + field: uid_raw + operator: '!=' + value: + value: '0' + group: '1' + exposed: '0' + sorts: + created: + id: created + table: users + field: created + order: DESC + title: People + empty: + area: + id: area + table: views + field: area + empty: '1' + content: 'No people available.' + format: filtered_html + page_1: + display_plugin: page + id: page_1 + display_title: Page + position: '' + display_options: + path: test-entity-translations-link +human_name: People +module: views +id: test_entity_translations_link +tag: '' diff --git a/core/modules/translation_entity/tests/modules/translation_entity_test_views/translation_entity_test_views.info b/core/modules/translation_entity/tests/modules/translation_entity_test_views/translation_entity_test_views.info new file mode 100644 index 0000000..39d267b --- /dev/null +++ b/core/modules/translation_entity/tests/modules/translation_entity_test_views/translation_entity_test_views.info @@ -0,0 +1,8 @@ +name = Entity translation test views +description = Provides default views for views entity translation tests. +package = Testing +version = VERSION +core = 8.x +dependencies[] = translation_entity +dependencies[] = views +hidden = TRUE diff --git a/core/modules/translation_entity/tests/modules/translation_entity_test_views/translation_entity_test_views.module b/core/modules/translation_entity/tests/modules/translation_entity_test_views/translation_entity_test_views.module new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/core/modules/translation_entity/tests/modules/translation_entity_test_views/translation_entity_test_views.module @@ -0,0 +1 @@ +get('module_handler')->moduleExists('translation_entity')) { + $data['users']['translation_link'] = array( + 'title' => t('Translation link'), + 'help' => t('Provide a link to the translations overview for users.'), + 'field' => array( + 'id' => 'translation_entity_link', + ), + ); + } + $data['users']['edit_node'] = array( 'field' => array( 'title' => t('Edit link'),