Skip to content
Snippets Groups Projects
Commit 4d4278ba authored by Eric Bremner's avatar Eric Bremner Committed by Igor Biki
Browse files

ISTWCMS-5506: adding check that description of content is filled in before...

ISTWCMS-5506: adding check that description of content is filled in before doing content moderation block
parent 986672fc
No related branches found
No related tags found
1 merge request!245ISTWCMS-5506: adding check that description of content is filled in before...
......@@ -6,11 +6,13 @@ use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\Core\Url;
use Drupal\uw_cfg_common\Service\UWService;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
/**
* Form class for the content access form.
......@@ -45,6 +47,13 @@ class UwContentModerationForm extends ConfirmFormBase {
*/
protected $currentUser;
/**
* The drupal messaging.
*
* @var \Drupal\Core\Messenger\MessengerInterface
*/
protected $messenger;
/**
* Class constructor.
*
......@@ -52,10 +61,17 @@ class UwContentModerationForm extends ConfirmFormBase {
* The entity type manager.
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The entity type manager.
* @param \Drupal\Core\Messenger\MessengerInterface $messenger
* The drupal messaging.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, AccountProxyInterface $currentUser) {
public function __construct(
EntityTypeManagerInterface $entity_type_manager,
AccountProxyInterface $currentUser,
MessengerInterface $messenger
) {
$this->entityTypeManager = $entity_type_manager;
$this->currentUser = $currentUser;
$this->messenger = $messenger;
}
/**
......@@ -65,7 +81,8 @@ class UwContentModerationForm extends ConfirmFormBase {
// Instantiates this form class.
return new static(
$container->get('entity_type.manager'),
$container->get('current_user')
$container->get('current_user'),
$container->get('messenger')
);
}
......@@ -117,6 +134,35 @@ class UwContentModerationForm extends ConfirmFormBase {
$this->vid = $vid;
$this->status = $status;
// If we are publishing this node, ensure that the meta
// content description is set.
if (!$this->status) {
// Load the node of this revision.
$node = $this->entityTypeManager->getStorage('node')->loadRevision($this->vid);
// If there is no meta content description, set message and
// redirect back to node page.
if (!$node->field_uw_meta_description->getValue()) {
// Get the URL to the node.
$url = Url::fromRoute('entity.node.canonical', ['node' => $this->nid]);
// Setup the redirect.
$redirect = new RedirectResponse($url->toString());
// Send the redirect.
$redirect->send();
// Add the message that the description for content is required.
$this->messenger->addError('Field "Description of content" is required when publishing.');
// We need to exit the code so that redirect and the message
// work correctly, without this the message does not display.
exit;
}
}
// Get the form from the parent, we need this to ensure
// that we have all the components (like confirm/cancel)
// load with this form as well.
......@@ -142,7 +188,7 @@ class UwContentModerationForm extends ConfirmFormBase {
return $form;
}
/**
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment