ResetStatusEntityConfirmation.php in CMS Content Sync 8
File
src/Form/ResetStatusEntityConfirmation.php
View source
<?php
namespace Drupal\cms_content_sync\Form;
use Drupal\cms_content_sync\Entity\Pool;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\Messenger;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class ResetStatusEntityConfirmation extends ConfirmFormBase {
protected $cms_content_sync_pool;
protected $pool_storage;
protected $pool;
protected $messenger;
public function __construct(EntityTypeManager $manager, Messenger $messenger) {
$this->pool_storage = $manager
->getStorage('cms_content_sync_pool');
$this->messenger = $messenger;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_type.manager'), $container
->get('messenger'));
}
public function buildForm(array $form, FormStateInterface $form_state, $cms_content_sync_pool = null) {
$this->cms_content_sync_pool = $cms_content_sync_pool;
$this->pool = $this->pool_storage
->load($this->cms_content_sync_pool);
return parent::buildForm($form, $form_state);
}
public function getFormId() {
return 'cms_content_sync_pool_status_entity_reset_confirmation';
}
public function getQuestion() {
return 'Are you sure you want to reset the status entities for the Pool: "' . $this->pool
->label() . '"?';
}
public function getDescription() {
return $this
->t('By resetting the status of all entities, the date of the last pull
and the date of the last push will be reset. The dates will no longer be displayed until
the content is pulled or pushed again and all entities will be pushed / pulled again at
the next synchronization regardless of whether they have changed or not.');
}
public function getCancelUrl() {
return new Url('entity.cms_content_sync_pool.collection');
}
public function getConfirmText() {
return t('Confirm');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
Pool::resetStatusEntities($this->pool
->id());
$this->messenger
->addMessage($this
->t('The status entities for the Pool @pool have been reset successfully.', [
'@pool' => $this->pool
->label(),
]));
$form_state
->setRedirect('entity.cms_content_sync_pool.collection');
}
}