public function ProcessForm::buildForm in Module Builder 8.3
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
1 call to ProcessForm::buildForm()
- ProcessTestSamplesForm::buildForm in module_builder_devel/
src/ Form/ ProcessTestSamplesForm.php - Form constructor.
1 method overrides ProcessForm::buildForm()
- ProcessTestSamplesForm::buildForm in module_builder_devel/
src/ Form/ ProcessTestSamplesForm.php - Form constructor.
File
- src/
Form/ ProcessForm.php, line 68
Class
- ProcessForm
- Form for running the DCB analysis process.
Namespace
Drupal\module_builder\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
try {
$task_handler_report = $this->drupalCodeBuilder
->getTask('ReportHookDataFolder');
$task_report_summary = $this->drupalCodeBuilder
->getTask('ReportSummary');
} catch (SanityException $e) {
if ($e
->getFailedSanityLevel() == 'data_directory_exists') {
$this->messenger
->addError($this
->t("The hooks data directory does not exist, or is not writeable. Check your settings and your filesystem."));
return $form;
}
// We're in right place to do something about a hooks processed sanity
// problem, so no need to show a message for that.
}
// The task handler returns sane values for these even if there's no hook
// data.
$last_update = $task_handler_report
->lastUpdatedDate();
$directory = \DrupalCodeBuilder\Factory::getEnvironment()
->getHooksDirectory();
$form['intro'] = array(
'#markup' => '<p>' . t("Module Builder analyses your site's code to find data about Drupal components such as hooks, plugins, tagged services, and more." . ' ' . "This processed data is stored in your local filesystem." . ' ' . "You should update the code analysis when updating site code, or updating Module Builder or Drupal Code Builder.") . '</p>',
);
$form['analyse'] = [
'#type' => 'fieldset',
'#title' => "Perform analysis",
];
$form['analyse']['last_update'] = array(
'#markup' => '<p>' . ($last_update ? t('Your last data update was %date.', array(
'%date' => \Drupal::service('date.formatter')
->format($last_update, 'large'),
)) : t("The site's code has not yet been analysed.")) . '</p>',
);
$form['analyse']['submit'] = array(
'#type' => 'submit',
'#value' => $last_update ? t('Update code analysis') : t('Perform code analysis'),
);
if ($last_update) {
try {
$analysis_data = $task_report_summary
->listStoredData();
} catch (\DrupalCodeBuilder\Exception\StorageException $e) {
// Bail if the storage has a problem.
$this
->messenger()
->addError($e
->getMessage());
return $form;
}
$form['results'] = [
'#type' => 'fieldset',
'#title' => "Analysis results",
];
$form['results']['text'] = array(
'#markup' => '<p>' . t('You have the following data saved in %dir: ', array(
'%dir' => $directory,
)) . '</p>',
);
foreach ($analysis_data as $type => $type_data) {
$form['results'][$type] = [
'#type' => 'details',
'#title' => "{$type_data['label']} ({$type_data['count']})",
'#open' => FALSE,
];
if (is_array(reset($type_data['list']))) {
$items = [];
foreach ($type_data['list'] as $group_name => $group_items) {
$items = array_merge($items, array_keys($group_items));
}
}
else {
$items = array_keys($type_data['list']);
}
$form['results'][$type]['items'] = [
'#theme' => 'item_list',
'#items' => $items,
];
}
}
return $form;
}