public function EntityUpdateExec::buildForm in Entity Update 2.0.x
Same name and namespace in other branches
- 8 src/Form/EntityUpdateExec.php \Drupal\entity_update\Form\EntityUpdateExec::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- src/
Form/ EntityUpdateExec.php, line 31
Class
- EntityUpdateExec
- Class CheckEntityUpdate.
Namespace
Drupal\entity_update\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $action = 'default') {
$aboutTextDiff = 'This page allows you to <b>update the entity types schema</b>.';
if ($action == 'clean') {
$aboutTextDiff = 'This page allows you to <b>cleanup the backup table</b>.';
}
elseif ($action == 'rescue') {
$aboutTextDiff = 'This page allows you to <b>restore entities from backup table</b>.';
}
elseif ($action == 'type') {
$aboutTextDiff = 'This page allows you to <b>update a selected entity type</b>.';
}
$aboutText = <<<TEXT
<p>{<span class="php-variable">$aboutTextDiff</span>}</p>
<p>
Please refer to the <a href='/admin/help/entity_update'>Help page</a>.
</p>
<p>
<b>CAUTION</b>
<ul>
<li>Use this module only as a development helper, Do not use in production sites.</li>
<li>The entity update may damage your database, therefore backup the database before taking any action.</li>
<li>If you are using this system, you should be conscious of what you are doing.</li>
<li> <b>You acknowledge that you are responsible for any issues due to this</b>.</li>
</ul>
</p>
<b>NOTE</b> : From here, You can update if:<br>
<ul>
<li>Any update if the entity type has no data.</li>
<li>Add new fields to entity type even with data.</li>
</ul>
<i>You can try "Run Full Update", but use the <b>drush</b> interface for safe execution and to have log messages. (Type : <code><b>drush help upe</b></code> for help.)</i><br>
<br>
</p>
TEXT;
$form['messages']['about'] = [
'#type' => 'markup',
'#markup' => $aboutText,
'#prefix' => '<div>',
'#suffix' => '</div>',
];
$form['confirm'] = [
'#type' => 'checkbox',
'#default_value' => '0',
'#title' => $this
->t('Yes, I want to execute the following action.'),
];
$form['action'] = [
'#type' => 'hidden',
'#default_value' => $action,
];
// Cleanup archives.
if ($action == 'clean') {
// Run backuped entities cleanup.
$form['submit_clean'] = [
'#type' => 'submit',
'#value' => $this
->t('Cleanup'),
'#submit' => [
'::submitFormClean',
],
'#description' => '',
];
}
elseif ($action == 'rescue') {
$form['submit_rescue'] = [
'#type' => 'submit',
'#value' => $this
->t('Run Entity Rescue'),
'#submit' => [
'::submitFormRescue',
],
];
}
elseif ($action == 'type') {
$list = EntityUpdate::getEntityTypesToUpdate();
if (!empty($list)) {
$form['action_entitytype'] = [
'#type' => 'details',
'#title' => 'Update a selected entity type',
'#open' => TRUE,
];
$options = [];
foreach ($list as $entity_type_id => $value) {
$options[$entity_type_id] = $entity_type_id;
}
$form['action_entitytype']['entity_type_id'] = [
'#type' => 'select',
'#title' => $this
->t('The entity type id to update'),
'#options' => $options,
];
// Update entity types with data. This action is not recomended from UI.
$form['action_entitytype']['submit_type'] = [
'#type' => 'submit',
'#value' => $this
->t('Run Type Update'),
'#submit' => [
'::submitFormSafe',
],
'#validate' => [
'::validateForm',
'::validateSafe',
],
'#description' => '',
];
}
else {
$form['action_entitytype'] = [
'#type' => 'markup',
'#markup' => 'Nothing to update',
];
}
}
else {
$form['force'] = [
'#type' => 'checkbox',
'#default_value' => '0',
'#title' => $this
->t('Try force update.'),
'#description' => $this
->t('Run basic update using --force option.'),
];
$form['submit_basic'] = [
'#type' => 'submit',
'#value' => $this
->t('Run Basic Update'),
'#submit' => [
'::submitFormBasic',
],
];
}
return $form;
}