Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
0b132ec5
Commit
0b132ec5
authored
Sep 7, 2015
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2551217
by larowlan, legolasbo: Data loss using Preview on content types with image field
parent
585f6d92
No related branches found
No related tags found
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/node/src/NodeForm.php
+4
-1
4 additions, 1 deletion
core/modules/node/src/NodeForm.php
core/modules/node/src/Tests/PagePreviewTest.php
+45
-4
45 additions, 4 deletions
core/modules/node/src/Tests/PagePreviewTest.php
with
49 additions
and
5 deletions
core/modules/node/src/NodeForm.php
+
4
−
1
View file @
0b132ec5
...
@@ -83,7 +83,10 @@ public function form(array $form, FormStateInterface $form_state) {
...
@@ -83,7 +83,10 @@ public function form(array $form, FormStateInterface $form_state) {
if
(
$preview
=
$store
->
get
(
$uuid
))
{
if
(
$preview
=
$store
->
get
(
$uuid
))
{
/** @var $preview \Drupal\Core\Form\FormStateInterface */
/** @var $preview \Drupal\Core\Form\FormStateInterface */
$form_state
=
$preview
;
foreach
(
$preview
->
getValues
()
as
$name
=>
$value
)
{
$form_state
->
setValue
(
$name
,
$value
);
}
// Rebuild the form.
// Rebuild the form.
$form_state
->
setRebuild
();
$form_state
->
setRebuild
();
...
...
This diff is collapsed.
Click to expand it.
core/modules/node/src/Tests/PagePreviewTest.php
+
45
−
4
View file @
0b132ec5
...
@@ -12,6 +12,8 @@
...
@@ -12,6 +12,8 @@
use
Drupal\Component\Utility\Unicode
;
use
Drupal\Component\Utility\Unicode
;
use
Drupal\Core\Language\LanguageInterface
;
use
Drupal\Core\Language\LanguageInterface
;
use
Drupal\entity_reference
\Tests\EntityReferenceTestTrait
;
use
Drupal\entity_reference
\Tests\EntityReferenceTestTrait
;
use
Drupal\field\Entity\FieldConfig
;
use
Drupal\field\Entity\FieldStorageConfig
;
use
Drupal\node\Entity\NodeType
;
use
Drupal\node\Entity\NodeType
;
/**
/**
...
@@ -29,7 +31,7 @@ class PagePreviewTest extends NodeTestBase {
...
@@ -29,7 +31,7 @@ class PagePreviewTest extends NodeTestBase {
*
*
* @var array
* @var array
*/
*/
public
static
$modules
=
array
(
'node'
,
'taxonomy'
,
'comment'
);
public
static
$modules
=
array
(
'node'
,
'taxonomy'
,
'comment'
,
'image'
,
'file'
);
/**
/**
* The name of the created field.
* The name of the created field.
...
@@ -68,6 +70,25 @@ protected function setUp() {
...
@@ -68,6 +70,25 @@ protected function setUp() {
$this
->
term
=
$term
;
$this
->
term
=
$term
;
// Create an image field.
FieldStorageConfig
::
create
([
'field_name'
=>
'field_image'
,
'entity_type'
=>
'node'
,
'type'
=>
'image'
,
'settings'
=>
[],
'cardinality'
=>
FieldStorageConfig
::
CARDINALITY_UNLIMITED
,
])
->
save
();
$field_config
=
FieldConfig
::
create
([
'field_name'
=>
'field_image'
,
'label'
=>
'Images'
,
'entity_type'
=>
'node'
,
'bundle'
=>
'page'
,
'required'
=>
FALSE
,
'settings'
=>
[],
]);
$field_config
->
save
();
// Create a field.
// Create a field.
$this
->
fieldName
=
Unicode
::
strtolower
(
$this
->
randomMachineName
());
$this
->
fieldName
=
Unicode
::
strtolower
(
$this
->
randomMachineName
());
$handler_settings
=
array
(
$handler_settings
=
array
(
...
@@ -95,6 +116,17 @@ protected function setUp() {
...
@@ -95,6 +116,17 @@ protected function setUp() {
'type'
=>
'entity_reference_label'
,
'type'
=>
'entity_reference_label'
,
))
))
->
save
();
->
save
();
entity_get_form_display
(
'node'
,
'page'
,
'default'
)
->
setComponent
(
'field_image'
,
array
(
'type'
=>
'image_image'
,
'settings'
=>
[],
))
->
save
();
entity_get_display
(
'node'
,
'page'
,
'default'
)
->
setComponent
(
'field_image'
)
->
save
();
}
}
/**
/**
...
@@ -110,7 +142,14 @@ function testPagePreview() {
...
@@ -110,7 +142,14 @@ function testPagePreview() {
$edit
[
$title_key
]
=
$this
->
randomMachineName
(
8
);
$edit
[
$title_key
]
=
$this
->
randomMachineName
(
8
);
$edit
[
$body_key
]
=
$this
->
randomMachineName
(
16
);
$edit
[
$body_key
]
=
$this
->
randomMachineName
(
16
);
$edit
[
$term_key
]
=
$this
->
term
->
getName
();
$edit
[
$term_key
]
=
$this
->
term
->
getName
();
$this
->
drupalPostForm
(
'node/add/page'
,
$edit
,
t
(
'Preview'
));
// Upload an image.
$test_image
=
current
(
$this
->
drupalGetTestFiles
(
'image'
,
39325
));
$edit
[
'files[field_image_0][]'
]
=
drupal_realpath
(
$test_image
->
uri
);
$this
->
drupalPostForm
(
'node/add/page'
,
$edit
,
t
(
'Upload'
));
// Add an alt tag and preview the node.
$this
->
drupalPostForm
(
NULL
,
[
'field_image[0][alt]'
=>
'Picture of llamas'
],
t
(
'Preview'
));
// Check that the preview is displaying the title, body and term.
// Check that the preview is displaying the title, body and term.
$this
->
assertTitle
(
t
(
'@title | Drupal'
,
array
(
'@title'
=>
$edit
[
$title_key
])),
'Basic page title is preview.'
);
$this
->
assertTitle
(
t
(
'@title | Drupal'
,
array
(
'@title'
=>
$edit
[
$title_key
])),
'Basic page title is preview.'
);
...
@@ -141,6 +180,7 @@ function testPagePreview() {
...
@@ -141,6 +180,7 @@ function testPagePreview() {
$this
->
assertFieldByName
(
$title_key
,
$edit
[
$title_key
],
'Title field displayed.'
);
$this
->
assertFieldByName
(
$title_key
,
$edit
[
$title_key
],
'Title field displayed.'
);
$this
->
assertFieldByName
(
$body_key
,
$edit
[
$body_key
],
'Body field displayed.'
);
$this
->
assertFieldByName
(
$body_key
,
$edit
[
$body_key
],
'Body field displayed.'
);
$this
->
assertFieldByName
(
$term_key
,
$edit
[
$term_key
]
.
' ('
.
$this
->
term
->
id
()
.
')'
,
'Term field displayed.'
);
$this
->
assertFieldByName
(
$term_key
,
$edit
[
$term_key
]
.
' ('
.
$this
->
term
->
id
()
.
')'
,
'Term field displayed.'
);
$this
->
assertFieldByName
(
'field_image[0][alt]'
,
'Picture of llamas'
);
// Return to page preview to check everything is as expected.
// Return to page preview to check everything is as expected.
$this
->
drupalPostForm
(
NULL
,
array
(),
t
(
'Preview'
));
$this
->
drupalPostForm
(
NULL
,
array
(),
t
(
'Preview'
));
...
@@ -156,8 +196,9 @@ function testPagePreview() {
...
@@ -156,8 +196,9 @@ function testPagePreview() {
$this
->
assertFieldByName
(
$body_key
,
$edit
[
$body_key
],
'Body field displayed.'
);
$this
->
assertFieldByName
(
$body_key
,
$edit
[
$body_key
],
'Body field displayed.'
);
$this
->
assertFieldByName
(
$term_key
,
$edit
[
$term_key
]
.
' ('
.
$this
->
term
->
id
()
.
')'
,
'Term field displayed.'
);
$this
->
assertFieldByName
(
$term_key
,
$edit
[
$term_key
]
.
' ('
.
$this
->
term
->
id
()
.
')'
,
'Term field displayed.'
);
// Save the node.
// Save the node - this is a new POST, so we need to upload the image.
$this
->
drupalPostForm
(
'node/add/page'
,
$edit
,
t
(
'Save'
));
$this
->
drupalPostForm
(
'node/add/page'
,
$edit
,
t
(
'Upload'
));
$this
->
drupalPostForm
(
NULL
,
[
'field_image[0][alt]'
=>
'Picture of llamas'
],
t
(
'Save'
));
$node
=
$this
->
drupalGetNodeByTitle
(
$edit
[
$title_key
]);
$node
=
$this
->
drupalGetNodeByTitle
(
$edit
[
$title_key
]);
// Check the term was displayed on the saved node.
// Check the term was displayed on the saved node.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment