MigrateForm.php in Workbench Moderation to Content Moderation 8
File
src/Form/MigrateForm.php
View source
<?php
namespace Drupal\wbm2cm\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\wbm2cm\MigrateManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MigrateForm extends FormBase {
protected $migrate;
public function __construct(MigrateManager $migrate_manager) {
$this->migrate = $migrate_manager;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('wbm2cm.migrate_manager'));
}
public function getFormId() {
return 'migrate_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$is_complete = $this->migrate
->isComplete();
if ($is_complete) {
return $this
->buildFormForComplete($form, $form_state);
}
else {
return $this
->buildFormForIncomplete($form, $form_state);
}
}
protected function buildFormForComplete(array $form, FormStateInterface $form_state) {
$form['info'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => 'The migration is complete! You may now uninstall this module.',
];
return $form;
}
protected function buildFormForIncomplete(array $form, FormStateInterface $form_state) {
$form['info'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => 'This migration is experimental and is designed for Drupal 8.4 alpha, migrating from Workbench Moderation to Content Moderation. There are known issues and many untested scenarios. For more details, see https://www.drupal.org/node/2897870.',
];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Migrate'),
'#button_type' => 'primary',
];
return $form;
}
public function validateForm(array &$form, FormStateInterface $form_state) {
$messages = $this->migrate
->getValidationMessages();
foreach ($messages as $message_id => $message) {
$form_state
->setErrorByName($message_id, $message);
}
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state
->setRedirect('wbm2cm.migrate');
}
}
Classes
Name |
Description |
MigrateForm |
A form to trigger batch processing if state is valid. |