Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_cfg_common
Commits
9d319bd6
Commit
9d319bd6
authored
2 years ago
by
Eric Bremner
Committed by
Igor Biki
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5506: using the require on publish module to look for nodes that can not be published
parent
d9cff0a3
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!245
ISTWCMS-5506: adding check that description of content is filled in before...
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Form/UwContentModerationForm.php
+49
-15
49 additions, 15 deletions
src/Form/UwContentModerationForm.php
with
49 additions
and
15 deletions
src/Form/UwContentModerationForm.php
+
49
−
15
View file @
9d319bd6
...
@@ -10,9 +10,12 @@ use Drupal\Core\Messenger\MessengerInterface;
...
@@ -10,9 +10,12 @@ use Drupal\Core\Messenger\MessengerInterface;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\Core\Session\AccountInterface
;
use
Drupal\Core\Session\AccountProxyInterface
;
use
Drupal\Core\Session\AccountProxyInterface
;
use
Drupal\Core\Url
;
use
Drupal\Core\Url
;
use
Drupal\field\FieldConfigInterface
;
use
Drupal\uw_cfg_common
\Service\UWService
;
use
Drupal\uw_cfg_common
\Service\UWService
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\RedirectResponse
;
use
Symfony\Component\HttpFoundation\RedirectResponse
;
use
Drupal\require_on_publish
\Plugin\Validation\Constraint\RequireOnPublish
;
/**
/**
* Form class for the content access form.
* Form class for the content access form.
...
@@ -138,28 +141,59 @@ class UwContentModerationForm extends ConfirmFormBase {
...
@@ -138,28 +141,59 @@ class UwContentModerationForm extends ConfirmFormBase {
// content description is set.
// content description is set.
if
(
!
$this
->
status
)
{
if
(
!
$this
->
status
)
{
/**
* This code is taken from the require_on_publish
* module, there was no easy way to use the validator
* inside this class.
*/
// Load the node of this revision.
// Load the node of this revision.
$node
=
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
loadRevision
(
$this
->
vid
);
$entity
=
$this
->
entityTypeManager
->
getStorage
(
'node'
)
->
loadRevision
(
$this
->
vid
);
/** @var \Drupal\Core\Field\FieldItemListInterface $field */
foreach
(
$entity
->
getFields
()
as
$field
)
{
/** @var \Drupal\Core\Field\FieldConfigInterface $field_config */
$field_config
=
$field
->
getFieldDefinition
();
if
(
!
(
$field_config
instanceof
FieldConfigInterface
))
{
continue
;
}
if
(
!
$field
->
isEmpty
())
{
continue
;
}
// If the field has require on publish, check that it has a value.
if
(
$field_config
->
getThirdPartySetting
(
'require_on_publish'
,
'require_on_publish'
,
FALSE
))
{
// If the field does not have a value, set the message and redirect.
if
(
!
$field
->
getValue
())
{
// Load the Require on publish class that contains
// the message to be displayed.
$constraint
=
new
RequireOnPublish
();
// If there is no meta content description, set message and
// Get the URL to the node.
// redirect back to node page.
$url
=
Url
::
fromRoute
(
'entity.node.canonical'
,
[
'node'
=>
$this
->
nid
]);
if
(
!
$node
->
field_uw_meta_description
->
getValue
())
{
//
G
et the
URL to the node
.
//
S
et
up
the
redirect
.
$url
=
Url
::
fromRoute
(
'entity.node.canonical'
,
[
'node'
=>
$this
->
nid
]
);
$redirect
=
new
RedirectResponse
(
$url
->
toString
()
);
// Se
tup
the redirect.
// Se
nd
the redirect.
$redirect
=
new
RedirectResponse
(
$url
->
toString
()
);
$redirect
->
send
(
);
// Send the redirect.
// Get the message to be dispalyed, which comes from the require
$redirect
->
send
();
// on publish class.
$message
=
$this
->
t
(
$constraint
->
message
,
[
'%field_label'
=>
$field_config
->
getLabel
()]);
// Add the message that the description for content is required.
// Add the message that the description for content is required.
$this
->
messenger
->
addError
(
'Field "Description of content" is required when publishing.'
);
$this
->
messenger
->
addError
(
$message
);
// We need to exit the code so that redirect and the message
// We need to exit the code so that redirect and the message
// work correctly, without this the message does not display.
// work correctly, without this the message does not display.
exit
;
exit
;
}
}
}
}
}
}
...
...
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