public function MappingImportForm::form in GatherContent 8.3
Gets the actual form array to be built.
Overrides EntityForm::form
See also
\Drupal\Core\Entity\EntityForm::processForm()
\Drupal\Core\Entity\EntityForm::afterBuild()
File
- src/
Form/ MappingImportForm.php, line 21
Class
- MappingImportForm
- Class MappingImportForm.
Namespace
Drupal\gathercontent\FormCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$pr_obj = new Project();
$projects = $pr_obj
->getProjects();
$template_obj = new Template();
$form['description'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#value' => t("Please select the GatherContent Templates you'd like to map. Only Templates you've not selected will be listed."),
'#attributes' => [
'class' => [
'description',
],
],
];
$form['projects'] = [
'#type' => 'vertical_tabs',
];
$form['template_counter'] = [
'#type' => 'container',
'#attributes' => [
'class' => [
'gather-content-counter-message',
],
],
'#attached' => [
'library' => [
'gathercontent/template_counter',
],
],
];
$created_mapping_ids = Mapping::loadMultiple();
$local_templates = [];
foreach ($created_mapping_ids as $mapping) {
/** @var \Drupal\gathercontent\Entity\Mapping $mapping */
$local_templates[$mapping
->getGathercontentTemplateId()] = $mapping
->getGathercontentTemplate();
}
foreach ($projects as $project_id => $project) {
$remote_templates = $template_obj
->getTemplates($project_id);
$templates = array_diff_assoc($remote_templates, $local_templates);
if (empty($templates)) {
continue;
}
$form['p' . $project_id] = [
'#type' => 'details',
'#title' => $project,
'#group' => 'projects',
'#tree' => TRUE,
];
$form['p' . $project_id]['templates'] = [
'#type' => 'checkboxes',
'#title' => $project,
'#options' => $templates,
'#attributes' => [
'class' => [
'gather-content-counted',
],
],
];
}
return $form;
}