FlowPullConfirmation.php in CMS Content Sync 2.0.x
File
src/Form/FlowPullConfirmation.php
View source
<?php
namespace Drupal\cms_content_sync\Form;
use Drupal\Core\Entity\EntityTypeManager;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class FlowPullConfirmation extends ConfirmFormBase {
protected $tempStoreFactory;
protected $storage;
protected $nodes;
protected $flow;
protected $flow_storage;
protected $cms_content_sync_flow;
public function __construct(PrivateTempStoreFactory $temp_store_factory, EntityTypeManager $manager) {
$this->tempStoreFactory = $temp_store_factory;
$this->flow_storage = $manager
->getStorage('cms_content_sync_flow');
}
public function buildForm(array $form, FormStateInterface $form_state, $cms_content_sync_flow = null) {
$this->cms_content_sync_flow = $cms_content_sync_flow;
$this->flow = $this->flow_storage
->load($this->cms_content_sync_flow);
if ($this->flow
->useV2()) {
return $this
->redirect('cms_content_sync.syndication', [
'flow' => $this->flow
->id(),
'new' => 'true',
]);
}
$form['pull_mode'] = [
'#type' => 'radios',
'#options' => [
'new_entities' => $this
->t('Only add new entities'),
'all_entities' => $this
->t('Force update of all entities'),
],
'#default_value' => 'new_entities',
];
return parent::buildForm($form, $form_state);
}
public static function create(ContainerInterface $container) {
return new static($container
->get('tempstore.private'), $container
->get('entity_type.manager'));
}
public function getFormId() {
return 'pool_pull_confirmation';
}
public function getQuestion() {
return 'Do you really want to pull all entities from this flow?';
}
public function getDescription() {
return $this
->t('Depending on the amount of entities this could take a while.');
}
public function getCancelUrl() {
return new Url('system.admin_content');
}
public function getConfirmText() {
return t('Pull');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state
->setRedirect('entity.cms_content_sync_flow.pull', [
'cms_content_sync_flow' => $this->flow
->id(),
'pull_mode' => $form_state
->getValue('pull_mode'),
]);
}
}