Commit 117a617b authored by webchick's avatar webchick

Issue #1896268 by tim.plunkett: Add Views integration for translation_entity().

parent f464f8ee
......@@ -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
......
......@@ -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
......
......@@ -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');
......
<?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;
}
}
<?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.
}
}
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: ''
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
......@@ -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'),
......
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