Skip to content
Snippets Groups Projects

Feature/istwcms 4166 publish unpublish

Merged Eric Bremner requested to merge feature/ISTWCMS-4166-publish-unpublish into 8.x-1.x
1 file
+ 82
5
Compare changes
  • Side-by-side
  • Inline
@@ -2,14 +2,58 @@
namespace Drupal\uw_cfg_common\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\uw_cfg_common\UwPermissions\UwPermissions;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form class for the content access form.
*/
class UwContentModerationForm extends FormBase {
class UwContentModerationForm extends ConfirmFormBase {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The nid (node id).
*
* @var int
*/
protected $nid;
/**
* The vid (version id).
*
* @var int
*/
protected $vid;
/**
* Class constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
// Instantiates this form class.
return new static(
$container->get('entity_type.manager')
);
}
/**
* {@inheritdoc}
@@ -23,9 +67,12 @@ class UwContentModerationForm extends FormBase {
*/
public function buildForm(array $form, FormStateInterface $form_state, $nid = NULL, $vid = NULL) {
$form = [];
// Set the node and version ids.
$this->nid = $nid;
$this->vid = $vid;
return $form;
// Return the form from the parent (confirm form).
return parent::buildForm($form, $form_state);
}
/**
@@ -36,4 +83,34 @@ class UwContentModerationForm extends FormBase {
// Set the message that the permissions have been saved.
$this->messenger()->addStatus($this->t('The changes have been saved.'));
}
/**
* Returns the question to ask the user.
*
* @return \Drupal\Core\StringTranslation\TranslatableMarkup
* The form question. The page title will be set to this value.
*/
public function getQuestion() {
// Get the node object.
$node = $this->entityTypeManager->getStorage('node')->load($this->nid);
// Return the question to see if they want to publish the node.
return t('Are you sure you want to unpublish %node_title?', ['%node_title' => $node->getTitle()]);
}
/**
* Returns the route to go to if the user cancels the action.
*
* @return \Drupal\Core\Url
* A URL object.
*/
public function getCancelUrl() {
// Set the options for the URL.
$options = ['absolute' => TRUE];
// Return the URL back to the node.
return Url::fromRoute('entity.node.canonical', ['node' => $this->nid], $options);
}
}
Loading