public function StaticGeneratorForm::buildForm in Tome 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/
tome_static/ src/ Form/ StaticGeneratorForm.php, line 84
Class
- StaticGeneratorForm
- Contains a form for initializing a static build.
Namespace
Drupal\tome_static\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
$form['description'] = [
'#markup' => '<p>' . $this
->t('Submitting this form will initiate a build of all uncached static pages site using Tome. Existing files in the static export directory (@dir) will be overridden.', [
'@dir' => $this->static
->getStaticDirectory(),
]) . '</p>',
];
$form['base_url'] = [
'#type' => 'textfield',
'#title' => $this
->t('Base URL'),
'#default_value' => $this->state
->get(StaticGeneratorInterface::STATE_KEY_URL, 'http://127.0.0.1'),
'#required' => TRUE,
'#size' => 30,
'#description' => $this
->t('The absolute URL used for generating static pages. This should match the domain on the site where the static site will be deployed.'),
];
$warnings = $this
->getWarnings();
if ($this->state
->get(StaticGeneratorInterface::STATE_KEY_BUILDING, FALSE)) {
$warnings[] = $this
->t('Another user may be running a static build, proceed only if the last build failed unexpectedly.');
}
if (!empty($warnings)) {
$form['warnings'] = [
'#type' => 'container',
'title' => [
'#markup' => '<strong>' . $this
->t('Build warnings') . '</strong>',
],
'list' => [
'#theme' => 'item_list',
'#items' => [],
],
];
foreach ($warnings as $warning) {
$form['warnings']['list']['#items'][] = [
'#markup' => $warning,
];
}
}
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
return $form;
}