Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
project
drupal
Commits
75b8c067
Commit
75b8c067
authored
Oct 03, 2013
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2084081
by amateescu: Fixed ER autocomplete doesn't work.
parent
34f0d6db
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
15 deletions
+20
-15
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php
..._reference/Plugin/field/widget/AutocompleteTagsWidget.php
+1
-1
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php
...tity_reference/Plugin/field/widget/AutocompleteWidget.php
+1
-1
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php
..._reference/Plugin/field/widget/AutocompleteWidgetBase.php
+12
-11
core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php
.../entity_reference/Tests/EntityReferenceAutoCreateTest.php
+6
-2
No files found.
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteTagsWidget.php
View file @
75b8c067
...
...
@@ -24,7 +24,7 @@
* settings = {
* "match_operator" = "CONTAINS",
* "size" = 60,
* "autocomplete_
path
" = "
entity_reference/autocomplete/
tags",
* "autocomplete_
type
" = "tags",
* "placeholder" = ""
* },
* multiple_values = TRUE
...
...
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidget.php
View file @
75b8c067
...
...
@@ -30,7 +30,7 @@
* settings = {
* "match_operator" = "CONTAINS",
* "size" = 60,
* "autocomplete_
path
" = "
entity_reference/autocomplete/
single",
* "autocomplete_
type
" = "single",
* "placeholder" = ""
* }
* )
...
...
core/modules/entity_reference/lib/Drupal/entity_reference/Plugin/field/widget/AutocompleteWidgetBase.php
View file @
75b8c067
...
...
@@ -75,23 +75,24 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
$entity
=
$items
->
getEntity
();
// Prepare the autocomplete path.
$autocomplete_path
=
$this
->
getSetting
(
'autocomplete_path'
);
$autocomplete_path
.
=
'/'
.
$this
->
fieldDefinition
->
getFieldName
()
.
'/'
.
$entity
->
entityType
()
.
'/'
.
$entity
->
bundle
()
.
'/'
;
// Use <NULL> as a placeholder in the URL when we don't have an entity.
// Most web servers collapse two consecutive slashes.
$id
=
'NULL'
;
if
(
$entity
&&
$entity_id
=
$entity
->
id
())
{
$id
=
$entity_id
;
// Prepare the autocomplete route parameters.
$autocomplete_route_parameters
=
array
(
'type'
=>
$this
->
getSetting
(
'autocomplete_type'
),
'field_name'
=>
$this
->
fieldDefinition
->
getFieldName
(),
'entity_type'
=>
$entity
->
entityType
(),
'bundle_name'
=>
$entity
->
bundle
(),
);
if
(
$entity_id
=
$entity
->
id
())
{
$autocomplete_route_parameters
[
'entity_id'
]
=
$entity_id
;
}
$autocomplete_path
.
=
$id
;
$element
+=
array
(
'#type'
=>
'textfield'
,
'#maxlength'
=>
1024
,
'#default_value'
=>
implode
(
', '
,
$this
->
getLabels
(
$items
)),
'#autocomplete_path'
=>
$autocomplete_path
,
'#autocomplete_route_name'
=>
'entity_reference.autocomplete'
,
'#autocomplete_route_parameters'
=>
$autocomplete_route_parameters
,
'#size'
=>
$this
->
getSetting
(
'size'
),
'#placeholder'
=>
$this
->
getSetting
(
'placeholder'
),
'#element_validate'
=>
array
(
array
(
$this
,
'elementValidate'
)),
...
...
core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php
View file @
75b8c067
...
...
@@ -17,7 +17,7 @@ class EntityReferenceAutoCreateTest extends WebTestBase {
public
static
function
getInfo
()
{
return
array
(
'name'
=>
'Entity Reference auto-create'
,
'name'
=>
'Entity Reference auto-create
and autocomplete UI
'
,
'description'
=>
'Tests creating new entity (e.g. taxonomy-term) from an autocomplete widget.'
,
'group'
=>
'Entity Reference'
,
);
...
...
@@ -76,12 +76,16 @@ function setUp() {
}
/**
* Assert creation on a new entity.
* Tests that the autocomplete input element appears and the creation of a new
* entity.
*/
public
function
testAutoCreate
()
{
$user1
=
$this
->
drupalCreateUser
(
array
(
'access content'
,
"create
$this->referencing_type
content"
));
$this
->
drupalLogin
(
$user1
);
$this
->
drupalGet
(
'node/add/'
.
$this
->
referencing_type
);
$this
->
assertFieldByXPath
(
'//input[@id="edit-test-field-0-target-id" and contains(@class, "form-autocomplete")]'
,
NULL
,
'The autocomplete input element appears.'
);
$new_title
=
$this
->
randomName
();
// Assert referenced node does not exist.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment