Commit f7c357e1 authored by alexpott's avatar alexpott

Issue #2472421 by geertvd, bircher, dawehner, jibran: Entity reference, views...

Issue #2472421 by geertvd, bircher, dawehner, jibran: Entity reference, views filter reference method is broken
parent 6e83e1f9
......@@ -25,11 +25,11 @@ class EntityReferenceAdminTest extends WebTestBase {
*
* Enable path module to ensure that the selection handler does not fail for
* entities with a path field.
* Enable views_ui module to see the no_view_help text.
*
* @var array
*/
public static $modules = array('node', 'field_ui', 'entity_reference', 'path', 'taxonomy', 'block', 'views');
public static $modules = array('node', 'field_ui', 'entity_reference', 'path', 'taxonomy', 'block', 'views', 'views_ui', 'entity_test');
/**
* The name of the content type created for testing purposes.
......@@ -46,7 +46,7 @@ protected function setUp() {
$this->drupalPlaceBlock('system_breadcrumb_block');
// Create test user.
$admin_user = $this->drupalCreateUser(array('access content', 'administer node fields', 'administer node display'));
$admin_user = $this->drupalCreateUser(array('access content', 'administer node fields', 'administer node display', 'administer views'));
$this->drupalLogin($admin_user);
// Create a content type, with underscores.
......@@ -149,15 +149,53 @@ public function testFieldAdminHandler() {
$this->drupalGet($bundle_path . '/fields/' . $field_name);
$this->assertFieldByName('settings[handler_settings][filter][type]', '_none');
// Switch the target type to 'node'.
$field_name = 'node.' . $this->type . '.field_test';
$edit = array(
'settings[target_type]' => 'node',
);
$this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings'));
// Try to select the views handler.
$edit = array(
'settings[handler]' => 'views',
);
$this->drupalPostAjaxForm($bundle_path . '/fields/' . $field_name, $edit, 'settings[handler]');
$this->assertRaw(t('No eligible views were found. <a href="@create">Create a view</a> with an <em>Entity Reference</em> display, or add such a display to an <a href="@existing">existing view</a>.', array(
'@create' => \Drupal::url('views_ui.add'),
'@existing' => \Drupal::url('entity.view.collection'),
)));
$this->drupalPostForm(NULL, $edit, t('Save settings'));
// If no eligible view is available we should see a message.
$this->assertText('The views entity selection mode requires a view.');
// Enable the entity_reference_test module which creates an eligible view.
$this->container->get('module_installer')->install(array('entity_reference_test'));
$this->resetAll();
$this->drupalGet($bundle_path . '/fields/' . $field_name);
$this->drupalPostAjaxForm($bundle_path . '/fields/' . $field_name, $edit, 'settings[handler]');
$edit = array(
'settings[handler_settings][view][view_and_display]' => 'test_entity_reference:entity_reference_1',
);
$this->drupalPostForm(NULL, $edit, t('Save settings'));
$this->assertResponse(200);
}
// Switch the target type to 'entity_test'.
$edit = array(
'settings[target_type]' => 'entity_test',
);
$this->drupalPostForm($bundle_path . '/fields/' . $field_name . '/storage', $edit, t('Save field settings'));
$this->drupalGet($bundle_path . '/fields/' . $field_name);
$edit = array(
'settings[handler]' => 'views',
);
$this->drupalPostAjaxForm($bundle_path . '/fields/' . $field_name, $edit, 'settings[handler]');
$edit = array(
'settings[handler_settings][view][view_and_display]' => 'test_entity_reference_entity_test:entity_reference_1',
);
$this->drupalPostForm(NULL, $edit, t('Save settings'));
$this->assertResponse(200);
}
/**
* Tests the formatters for the Entity References
......
langcode: en
status: true
dependencies:
module:
- entity_reference
- entity_reference_test
- entity_test
id: test_entity_reference_entity_test
label: 'Entity reference'
module: views
description: ''
tag: ''
base_table: entity_test
base_field: id
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: 0
display_options:
access:
type: none
cache:
type: none
query:
type: views_query
exposed_form:
type: basic
pager:
type: full
style:
type: default
row:
type: fields
fields:
name:
table: entity_test
field: name
id: name
entity_type: null
entity_field: name
plugin_id: field
relationship: none
group_type: group
admin_label: ''
label: ''
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: value
type: string
settings: { }
group_column: value
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
filters: { }
sorts: { }
header: { }
footer: { }
empty: { }
relationships: { }
arguments: { }
display_extenders: { }
entity_reference_1:
display_plugin: entity_reference
id: entity_reference_1
display_title: EntityReference
position: null
display_options:
display_extenders: { }
style:
type: entity_reference
options:
search_fields:
name: name
......@@ -110,7 +110,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
$options = array();
foreach ($displays as $data) {
list($view, $display_id) = $data;
if ($view->storage->get('base_table') == $entity_type->getBaseTable()) {
if (in_array($view->storage->get('base_table'), [$entity_type->getBaseTable(), $entity_type->getDataTable()])) {
$name = $view->storage->get('id');
$display = $view->storage->get('display');
$options[$name . ':' . $display_id] = $name . ' - ' . $display[$display_id]['display_title'];
......@@ -147,8 +147,8 @@ public function buildConfigurationForm(array $form, FormStateInterface $form_sta
if ($this->currentUser->hasPermission('administer views') && $this->moduleHandler->moduleExists('views_ui')) {
$form['view']['no_view_help'] = array(
'#markup' => '<p>' . $this->t('No eligible views were found. <a href="@create">Create a view</a> with an <em>Entity Reference</em> display, or add such a display to an <a href="@existing">existing view</a>.', array(
'@create' => Url::fromRoute('views_ui.add'),
'@existing' => Url::fromRoute('entity.view.collection'),
'@create' => Url::fromRoute('views_ui.add')->toString(),
'@existing' => Url::fromRoute('entity.view.collection')->toString(),
)) . '</p>',
);
}
......
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