public function EntityUpdateExec::buildForm in Entity Update 8
Same name and namespace in other branches
- 2.0.x 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') {
$link_help = '/admin/help/entity_update';
$about_text = <<<TEXT
<p>
This page allow to update entity types schema. Please refer to the <a href='{<span class="php-variable">$link_help</span>}'>Help page</a>.
</p>
<p>
<b>CAUTION</b>
<ul>
<li>Use this module only as development helper, Do not use in production sites.</li>
<li>The entity update may damage your database, therefor update the database before any action.</li>
<li>If you use this system, you are conscience what you are doing. <b>You are the responsible of your work</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' => $about_text,
'#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',
],
'#validate' => [
'::validateOk',
],
'#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;
}