diff --git a/core/modules/comment/comment.views.inc b/core/modules/comment/comment.views.inc index f7ce2f92f9aad3ac86bfbd7454e1f13e07860425..8f5b186978f74eb1aefb34c4d3bed2ed9e0c92cf 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 2e8ab14e4c63ea587d6af1141d3fc051e4b2d1a4..d3fb851458bf8a646181321f1c72c89fa34af30e 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 c82873e0b2bf96c80859a25de6111e754d990a2a..d683d68c8fdcc054f13f6ffd46aca5b8d64203b9 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 0000000000000000000000000000000000000000..ae2bd007d587c4fbdbe250a48315632669bc4454 --- /dev/null +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Plugin/views/field/TranslationLink.php @@ -0,0 +1,90 @@ +<?php + +/** + * @file + * Contains \Drupal\translation_entity\Plugin\views\field\TranslationLink. + */ + +namespace Drupal\translation_entity\Plugin\views\field; + +use Drupal\views\Plugin\views\field\FieldPluginBase; +use Drupal\Core\Annotation\Plugin; +use Drupal\Core\Entity\EntityInterface; + +/** + * Provides a translation link for an entity. + * + * @ingroup views_field_handlers + * + * @Plugin( + * id = "translation_entity_link", + * module = "translation_entity" + * ) + */ +class TranslationLink extends FieldPluginBase { + + /** + * Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::defineOptions(). + */ + protected function defineOptions() { + $options = parent::defineOptions(); + $options['text'] = array('default' => '', '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 (translation_entity_translate_access($entity)) { + $text = !empty($this->options['text']) ? $this->options['text'] : t('translate'); + + $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 0000000000000000000000000000000000000000..72cdd46ac5b8b6ac3fe3c22016bc0b0d17f31802 --- /dev/null +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/Views/TranslationLinkTest.php @@ -0,0 +1,76 @@ +<?php + +/** + * @file + * Contains \Drupal\translation_entity\Tests\Views\TranslationLinkTest. + */ + +namespace Drupal\translation_entity\Tests\Views; + +use Drupal\views\Tests\ViewTestBase; +use Drupal\translation_entity\Tests\EntityTranslationUITest; +use Drupal\views\Tests\ViewTestData; + +/** + * Tests the Entity translation overview link field handler. + * + * @see \Drupal\translation_entity\Plugin\views\field\TranslationLink + */ +class TranslationLinkTest extends EntityTranslationUITest { + + /** + * Views used by this test. + * + * @var array + */ + public static $testViews = array('test_entity_translations_link'); + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('translation_entity_test_views'); + + public static function getInfo() { + return array( + 'name' => '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'); + $this->assertNoLinkByHref('user/2/translations', 'The translations link is not present when translation_entity_translate_access() is FALSE.'); + } + + /** + * 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 0000000000000000000000000000000000000000..c431338c196da9f49a00be26ef51d6068ab2626d --- /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 0000000000000000000000000000000000000000..39d267b1cb0b27df93b807d354967783c8f07a8a --- /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 0000000000000000000000000000000000000000..b3d9bbc7f3711e882119cd6b3af051245d859d04 --- /dev/null +++ b/core/modules/translation_entity/tests/modules/translation_entity_test_views/translation_entity_test_views.module @@ -0,0 +1 @@ +<?php diff --git a/core/modules/user/user.views.inc b/core/modules/user/user.views.inc index 5aefa46c0d4c8cac54df693b55bfd9d64448cf2c..410793891299efa60f53fcf453068e413b4de01e 100644 --- a/core/modules/user/user.views.inc +++ b/core/modules/user/user.views.inc @@ -295,6 +295,17 @@ function user_views_data() { ), ); + // Entity translation field. + if (drupal_container()->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'),