Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
visual_editor
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
visual_editor
Commits
2cda1fb4
Commit
2cda1fb4
authored
1 year ago
by
Jesus Manuel Olivas
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3450267
: Add support for Preview Draft Content
parent
a251b608
Branches
Branches containing commit
Tags
1.0.6
Tags containing commit
1 merge request
!16
✨ Issue #3450267: Add support for Preview Draft Content
Pipeline
#183818
passed with warnings
1 year ago
Stage: build
Stage: validate
Changes
2
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Form/NodeEditForm.php
+5
-3
5 additions, 3 deletions
src/Form/NodeEditForm.php
src/FormEditTrait.php
+48
-11
48 additions, 11 deletions
src/FormEditTrait.php
with
53 additions
and
14 deletions
src/Form/NodeEditForm.php
+
5
−
3
View file @
2cda1fb4
...
...
@@ -25,13 +25,15 @@ class NodeEditForm extends NodeForm {
* Overridden to store the root parent entity.
*/
public
function
buildForm
(
array
$form
,
FormStateInterface
$form_state
)
{
// Calculate if preview | latest published revision.
$this
->
calculateNodeEntity
(
$form
,
$form_state
);
// Build the form.
$form
=
parent
::
buildForm
(
$form
,
$form_state
);
$node
=
$this
->
calculateNodeEntity
(
$form
,
$form_state
);
// Hide Preview button.
$form
[
'actions'
][
'preview'
][
'#access'
]
=
$this
->
isLatestRevision
();
// Hide Delete button.
$form
[
'actions'
][
'delete'
][
'#access'
]
=
FALSE
;
// Hide advanced tab.
$form
[
'advanced'
][
'#attributes'
][
'class'
][]
=
'visually-hidden'
;
// Add ajax callback to submit button.
$form
[
'actions'
][
'submit'
][
'#ajax'
][
'callback'
]
=
'::ajaxSubmit'
;
// @todo static::ajaxSubmit() requires data-drupal-selector to be the same
...
...
This diff is collapsed.
Click to expand it.
src/FormEditTrait.php
+
48
−
11
View file @
2cda1fb4
...
...
@@ -9,6 +9,23 @@ namespace Drupal\visual_editor;
*/
trait
FormEditTrait
{
/**
* Stores the isLatestRevision status.
*
* @var bool
*/
protected
$isLatestRevision
=
FALSE
;
/**
* Get the isLatestRevision status.
*
* @return bool
* The isLatestRevision status.
*/
public
function
isLatestRevision
()
{
return
$this
->
isLatestRevision
;
}
/**
* Sets the entity for sidebar edit form.
*
...
...
@@ -17,19 +34,43 @@ trait FormEditTrait {
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state object.
*
* @return
\Drupal\Core\Entity\ContentEntityInterface
*
The node object to return
.
* @return
void
*
Return nothing
.
*/
public
function
calculateNodeEntity
(
&
$form
,
&
$form_state
)
{
// Check if the entity is not the latest published revision.
$entity
=
$form_state
->
getFormObject
()
->
getEntity
();
// Set the isLatestRevision status.
$this
->
isLatestRevision
=
$entity
->
isLatestRevision
();
// If not the latest revision, load the latest revision.
if
(
!
$entity
->
isLatestRevision
())
{
$revisionId
=
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
getLatestRevisionId
(
$entity
->
id
());
$node
=
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
loadRevision
(
$revisionId
);
$form_state
->
getFormObject
()
->
setEntity
(
$node
);
$form_state
->
setRebuild
();
$this
->
entity
=
$node
;
return
;
}
// Check if the form is in preview mode.
$query
=
\Drupal
::
request
()
->
query
;
$is
_p
review
=
$query
->
has
(
'preview'
)
&&
$query
->
get
(
'preview'
)
==
'true'
;
$is
P
review
=
$query
->
has
(
'preview'
)
&&
$query
->
get
(
'preview'
)
==
'true'
;
// Try to restore from temp store, this must be done before calling
// parent::form().
$store
=
$this
->
tempStoreFactory
->
get
(
'node_preview'
);
$node_uuid
=
$form_state
->
getFormObject
()
->
getEntity
()
->
uuid
();
$uuid
=
$form_state
->
getFormObject
()
->
getEntity
()
->
uuid
();
$preview
=
$store
->
get
(
$uuid
);
if
(
$is
_p
review
&&
!
$form_state
->
isRebuilding
()
&&
$
node_
uuid
&&
$preview
=
$store
->
get
(
$node_uuid
)
)
{
if
(
$is
P
review
&&
!
$form_state
->
isRebuilding
()
&&
$uuid
&&
$preview
)
{
/** @var \Drupal\Core\Form\FormStateInterface $preview */
$form_state
->
setStorage
(
$preview
->
getStorage
());
$form_state
->
setUserInput
(
$preview
->
getUserInput
());
...
...
@@ -46,14 +87,10 @@ trait FormEditTrait {
$this
->
entity
->
in_preview
=
NULL
;
$form_state
->
set
(
'has_been_previewed'
,
TRUE
);
return
$this
->
entity
;
}
else
{
$this
->
entity
=
$form_state
->
getFormObject
()
->
getEntity
();
return
$form_state
->
getFormObject
()
->
getEntity
();
return
;
}
$this
->
entity
=
$form_state
->
getFormObject
()
->
getEntity
();
}
}
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