ModalPublishedForm.php in Modal 8.3
File
src/Form/ModalPublishedForm.php
View source
<?php
namespace Drupal\modal_page\Form;
use Drupal\Core\Entity\ContentEntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class ModalPublishedForm extends ContentEntityConfirmFormBase {
public function getQuestion() {
$entity = $this
->getEntity();
if ($entity->published->value) {
return $this
->t('Are you sure you want to unpublish entity %title?', [
'%title' => $this->entity
->label(),
]);
}
return $this
->t('Are you sure you want to publish entity %title?', [
'%title' => $this->entity
->label(),
]);
}
public function getDescription() {
return $this
->t('This action can be fixed in the future.');
}
public function getCancelUrl() {
return new Url('modal_page.default');
}
public function getConfirmText() {
return $this
->t('Comfirm');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$entity = $this
->getEntity();
if ($entity->published->value) {
$entity->published->value = FALSE;
}
else {
$entity->published->value = TRUE;
}
$entity
->save();
$form_state
->setRedirect('modal_page.default');
}
}