public function NodeRevisionGenerateForm::buildForm in Node Revision Delete 8
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
- modules/
node_revision_generate/ src/ Form/ NodeRevisionGenerateForm.php, line 67
Class
- NodeRevisionGenerateForm
- Class NodeRevisionGenerate.
Namespace
Drupal\node_revision_generate\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Get all Content types.
$content_types = [];
$form['bundles'] = [];
$node_types = $this->entityTypeManager
->getStorage('node_type')
->loadMultiple();
foreach ($node_types as $type) {
$content_type_machine_name = $type
->id();
// If the content type don't have nodes should be disabled.
if (!$this->nodeRevisionGenerate
->existsNodesContentType($content_type_machine_name)) {
$form['bundles'][$content_type_machine_name]['#disabled'] = TRUE;
$content_types[$content_type_machine_name] = $this
->t('@content_type. There are no nodes.', [
'@content_type' => $type
->label(),
]);
}
else {
$content_types[$content_type_machine_name] = $type
->label();
}
}
// Sort the content types by content type name.
asort($content_types);
$form['bundles'] += [
'#type' => 'checkboxes',
'#title' => $this
->t('Content types'),
'#options' => $content_types,
'#required' => TRUE,
];
$form['revisions_number'] = [
'#type' => 'number',
'#title' => $this
->t('Revisions number'),
'#min' => 1,
'#default_value' => 1,
'#description' => $this
->t('The maximum number of revisions that will be created for each node of the selected content types.'),
'#required' => TRUE,
];
$form['age'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Revisions age'),
'#description' => $this
->t('The age between each generated revision.'),
'#required' => TRUE,
];
$form['age']['number'] = [
'#type' => 'number',
'#min' => 1,
'#default_value' => 1,
'#required' => TRUE,
];
$time_options = [
'86400' => $this
->t('Day'),
'604800' => $this
->t('Week'),
'2592000' => $this
->t('Month'),
];
$form['age']['time'] = [
'#type' => 'select',
'#options' => $time_options,
];
$form['description'] = [
'#type' => 'item',
'#markup' => $this
->t('The first revision will be generated starting from the created date of the last node revision and the last one will not have a date in the future. So, depending on this maybe we will not generate the number of revisions you expect.'),
];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Generate revisions'),
'#button_type' => 'primary',
];
// Adding donation text.
$form['#prefix'] = Donation::getDonationText();
return $form;
}