Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
301
Merge Requests
301
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
f8e139ce
Commit
f8e139ce
authored
Sep 26, 2015
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2574095
by marcingy: File upload and entity autocomplete results in fatal
parent
c72dc294
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
132 additions
and
1 deletion
+132
-1
core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php
...n/Field/FieldWidget/EntityReferenceAutocompleteWidget.php
+1
-1
core/modules/entity_reference/src/Tests/EntityReferenceFileUploadTest.php
...ity_reference/src/Tests/EntityReferenceFileUploadTest.php
+131
-0
No files found.
core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/EntityReferenceAutocompleteWidget.php
View file @
f8e139ce
...
...
@@ -120,7 +120,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen
* {@inheritdoc}
*/
public
function
errorElement
(
array
$element
,
ConstraintViolationInterface
$error
,
array
$form
,
FormStateInterface
$form_state
)
{
return
$element
[
'target_id'
]
;
return
isset
(
$element
[
'target_id'
])
?
$element
[
'target_id'
]
:
FALSE
;
}
/**
...
...
core/modules/entity_reference/src/Tests/EntityReferenceFileUploadTest.php
0 → 100644
View file @
f8e139ce
<?php
/**
* @file
* Contains \Drupal\entity_reference\Tests\EntityReferenceFileUploadTest.
*/
namespace
Drupal\entity_reference\Tests
;
use
Drupal\Core\Field\FieldStorageDefinitionInterface
;
use
Drupal\simpletest\WebTestBase
;
/**
* Tests an autocomplete widget with file upload.
*
* @group entity_reference
*/
class
EntityReferenceFileUploadTest
extends
WebTestBase
{
public
static
$modules
=
array
(
'entity_reference'
,
'node'
,
'file'
);
/**
* The name of a content type that will reference $referencedType.
*
* @var string
*/
protected
$referencingType
;
/**
* The name of a content type that will be referenced by $referencingType.
*
* @var string
*/
protected
$referencedType
;
/**
* Node id.
*
* @var integer
*/
protected
$nodeId
;
protected
function
setUp
()
{
parent
::
setUp
();
// Create "referencing" and "referenced" node types.
$referencing
=
$this
->
drupalCreateContentType
();
$this
->
referencingType
=
$referencing
->
id
();
$referenced
=
$this
->
drupalCreateContentType
();
$this
->
referencedType
=
$referenced
->
id
();
$this
->
nodeId
=
$this
->
drupalCreateNode
(
array
(
'type'
=>
$referenced
->
id
()))
->
id
();
entity_create
(
'field_storage_config'
,
array
(
'field_name'
=>
'test_field'
,
'entity_type'
=>
'node'
,
'translatable'
=>
FALSE
,
'entity_types'
=>
array
(),
'settings'
=>
array
(
'target_type'
=>
'node'
,
),
'type'
=>
'entity_reference'
,
'cardinality'
=>
FieldStorageDefinitionInterface
::
CARDINALITY_UNLIMITED
,
))
->
save
();
entity_create
(
'field_config'
,
array
(
'label'
=>
'Entity reference field'
,
'field_name'
=>
'test_field'
,
'entity_type'
=>
'node'
,
'required'
=>
TRUE
,
'bundle'
=>
$referencing
->
id
(),
'settings'
=>
array
(
'handler'
=>
'default'
,
'handler_settings'
=>
array
(
// Reference a single vocabulary.
'target_bundles'
=>
array
(
$referenced
->
id
(),
),
),
),
))
->
save
();
// Create a file field.
$file_field_name
=
'file_field'
;
$field_storage
=
entity_create
(
'field_storage_config'
,
array
(
'field_name'
=>
$file_field_name
,
'entity_type'
=>
'node'
,
'type'
=>
'file'
));
$field_storage
->
save
();
entity_create
(
'field_config'
,
array
(
'entity_type'
=>
'node'
,
'field_storage'
=>
$field_storage
,
'bundle'
=>
$referencing
->
id
(),
'label'
=>
$this
->
randomMachineName
()
.
'_label'
,
))
->
save
();
entity_get_display
(
'node'
,
$referencing
->
id
(),
'default'
)
->
setComponent
(
'test_field'
)
->
setComponent
(
$file_field_name
)
->
save
();
entity_get_form_display
(
'node'
,
$referencing
->
id
(),
'default'
)
->
setComponent
(
'test_field'
,
array
(
'type'
=>
'entity_reference_autocomplete'
,
))
->
setComponent
(
$file_field_name
,
array
(
'type'
=>
'file_generic'
,
))
->
save
();
}
/**
* Tests that the autocomplete input element does not cause ajax fatal.
*/
public
function
testFileUpload
()
{
$user1
=
$this
->
drupalCreateUser
(
array
(
'access content'
,
"create
$this->referencingType
content"
));
$this
->
drupalLogin
(
$user1
);
$test_file
=
current
(
$this
->
drupalGetTestFiles
(
'text'
));
$edit
[
'files[file_field_0]'
]
=
drupal_realpath
(
$test_file
->
uri
);
$this
->
drupalPostForm
(
'node/add/'
.
$this
->
referencingType
,
$edit
,
'Upload'
);
$this
->
assertResponse
(
200
);
$edit
=
array
(
'title[0][value]'
=>
$this
->
randomMachineName
(),
'test_field[0][target_id]'
=>
$this
->
nodeId
,
);
$this
->
drupalPostForm
(
NULL
,
$edit
,
'Save'
);
$this
->
assertResponse
(
200
);
}
}
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