Commit 40997e53 authored by damiankloip's avatar damiankloip Committed by tim.plunkett

Issue #1765046 by damiankloip, dawehner: Create a 'real table' property similar to real field.

parent ef1f2eac
......@@ -120,6 +120,11 @@ public function init(&$view, &$options) {
$this->table = $options['table'];
}
// Allow alliases on both fields and tables.
if (isset($this->definition['real table'])) {
$this->table = $this->definition['real table'];
}
if (isset($this->definition['real field'])) {
$this->realField = $this->definition['real field'];
}
......
<?php
/**
* @file
* Definition of Drupal\views\Tests\Handler\HandlerAliasTest.
*/
namespace Drupal\views\Tests\Handler;
use Drupal\views\Tests\ViewTestBase;
/**
* Tests abstract handlers of views.
*/
class HandlerAliasTest extends ViewTestBase {
public static function getInfo() {
return array(
'name' => 'Handler alias tests',
'description' => 'Tests handler table and field aliases.',
'group' => 'Views',
);
}
protected function setUp() {
parent::setUp();
// Create a new user for the 'real table'.
$this->user = $this->drupalCreateUser();
$this->enableViewsTestModule();
}
/**
* Overrides Drupal\views\Tests\ViewTestBase::viewsData().
*/
protected function viewsData() {
$data = parent::viewsData();
// User the existing test_filter plugin.
$data['views_test_data_alias']['table']['real table'] = 'views_test_data';
$data['views_test_data_alias']['name_alias']['filter']['id'] = 'test_filter';
$data['views_test_data_alias']['name_alias']['filter']['real field'] = 'name';
return $data;
}
public function testPluginAliases() {
$view = views_get_view('test_filter');
$view->initDisplay();
// Change the filtering.
$view->display['default']->handler->overrideOption('filters', array(
'test_filter' => array(
'id' => 'test_filter',
'table' => 'views_test_data_alias',
'field' => 'name_alias',
'operator' => '=',
'value' => 'John',
'group' => 0,
),
));
$this->executeView($view);
$filter = $view->filter['test_filter'];
// Check the definition values are present.
$this->assertIdentical($filter->definition['real table'], 'views_test_data');
$this->assertIdentical($filter->definition['real field'], 'name');
$this->assertIdentical($filter->table, 'views_test_data');
$this->assertIdentical($filter->realField, 'name');
// Test an existing user uid field.
$view = views_get_view('test_alias');
$view->initDisplay();
$this->executeView($view);
$filter = $view->filter['uid_raw'];
$this->assertIdentical($filter->definition['real field'], 'uid');
$this->assertIdentical($filter->field, 'uid_raw');
$this->assertIdentical($filter->table, 'users');
$this->assertIdentical($filter->realField, 'uid');
}
}
api_version: '3.0'
base_table: users
core: 8.0-dev
description: ''
disabled: '0'
display:
default:
display_options:
access:
perm: 'access user profiles'
type: perm
cache:
type: none
exposed_form:
type: basic
fields:
name:
alter:
absolute: '0'
alter_text: '0'
ellipsis: '0'
html: '0'
make_link: '0'
strip_tags: '0'
trim: '0'
word_boundary: '0'
empty_zero: '0'
field: name
hide_empty: '0'
id: name
label: ''
link_to_user: '1'
overwrite_anonymous: '0'
table: users
filters:
uid_raw:
admin_label: ''
expose:
description: ''
identifier: ''
label: ''
multiple: '0'
operator: ''
operator_id: '0'
remember: '0'
remember_roles:
authenticated: authenticated
required: '0'
use_operator: '0'
exposed: '0'
field: uid_raw
group: '1'
group_info:
default_group: All
default_group_multiple: { }
description: ''
group_items: { }
identifier: ''
label: ''
multiple: '0'
optional: '1'
remember: '0'
widget: select
group_type: group
id: uid_raw
is_grouped: '0'
operator: '>'
relationship: none
table: users
value:
max: ''
min: ''
value: '1'
pager:
type: full
query:
type: views_query
row_plugin: fields
style_plugin: default
display_plugin: default
display_title: Master
id: default
position: '0'
human_name: test_alias
module: views
name: test_alias
tag: default
uuid: 3bdfd3e6-15aa-4324-9005-5ad8b321d265
......@@ -1330,7 +1330,7 @@ function views_get_handler($table, $field, $type, $override = NULL) {
}
$definition = $data[$field][$type];
foreach (array('group', 'title', 'title short', 'help', 'real field') as $key) {
foreach (array('group', 'title', 'title short', 'help', 'real field', 'real table') as $key) {
if (!isset($definition[$key])) {
// First check the field level
if (!empty($data[$field][$key])) {
......
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