Skip to content
Snippets Groups Projects
Commit 579c3ba7 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1867572 by swentel, dawehner, damiankloip, sun: Fixed Field module...

Issue #1867572 by swentel, dawehner, damiankloip, sun: Fixed Field module generates views data for entities without base table.
parent 4dc5b8d2
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @file
* Contains \Drupal\contact\Tests\Views\ContactFieldsTest.
*/
namespace Drupal\contact\Tests\Views;
use Drupal\views\Tests\ViewTestBase;
/**
* Tests which checks that no fieldapi fields are added on contact.
*/
class ContactFieldsTest extends ViewTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('field', 'text', 'contact');
/**
* Contains the field definition array attached to contact used for this test.
*
* @var array
*/
protected $field;
public static function getInfo() {
return array(
'name' => 'Contact: Field views data',
'description' => 'Tests which checks that no fieldapi fields are added on contact.',
'group' => 'Views Modules',
);
}
protected function setUp() {
parent::setUp();
$field = array(
'field_name' => strtolower($this->randomName()),
'type' => 'text'
);
$this->field = field_create_field($field);
$instance = array(
'field_name' => $field['field_name'],
'entity_type' => 'contact_message',
'bundle' => 'contact_message',
);
field_create_instance($instance);
}
/**
* Tests the views data generation.
*/
public function testViewsData() {
$field_name = $this->field['field_name'];
$table_name = _field_sql_storage_tablename($this->field);
$data = drupal_container()->get('views.views_data')->get($table_name);
// Test that the expected data array is returned.
$expected = array('', '_value', '_format');
$this->assertEqual(count($data), count($expected), 'The expected amount of array keys were found.');
foreach ($expected as $suffix) {
$this->assertTrue(isset($data[$field_name . $suffix]));
}
$this->assertTrue(empty($data['table']['join']), 'The field is not joined to the non existent contact message base table.');
}
}
......@@ -127,6 +127,9 @@ function field_views_field_default_views_data($field) {
$group_name = $groups[$entity];
}
if (!isset($entity_info['base_table'])) {
continue;
}
$entity_tables[$entity_info['base_table']] = $entity;
$current_tables[$entity] = $entity_info['base_table'];
if (isset($entity_info['revision_table'])) {
......@@ -201,6 +204,9 @@ function field_views_field_default_views_data($field) {
$aliases = array();
$also_known = array();
foreach ($all_labels as $entity_name => $labels) {
if (!isset($current_tables[$entity_name])) {
continue;
}
foreach ($labels as $label_name => $true) {
if ($type == FIELD_LOAD_CURRENT) {
if ($group_name != $groups[$entity_name] || $label != $label_name) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment