public function MappingForm::buildForm in Bibliography & Citation 8
Same name and namespace in other branches
- 2.0.x modules/bibcite_entity/src/Form/MappingForm.php \Drupal\bibcite_entity\Form\MappingForm::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
1 call to MappingForm::buildForm()
- CslMappingForm::buildForm in modules/
bibcite_entity/ src/ Form/ CslMappingForm.php - Form constructor.
1 method overrides MappingForm::buildForm()
- CslMappingForm::buildForm in modules/
bibcite_entity/ src/ Form/ CslMappingForm.php - Form constructor.
File
- modules/
bibcite_entity/ src/ Form/ MappingForm.php, line 71
Class
- MappingForm
- Format mapping form.
Namespace
Drupal\bibcite_entity\FormCode
public function buildForm(array $form, FormStateInterface $form_state, $bibcite_format = NULL) {
/** @var \Drupal\bibcite\Plugin\BibciteFormatInterface $bibcite_format */
if (!$this->config) {
$this
->initConfiguration($bibcite_format);
}
$form['types'] = [
'#type' => 'table',
'#caption' => $this
->t('Formats mapping'),
'#header' => [
$this
->t('Format type'),
$this
->t('Reference type'),
],
];
$type_options = $this
->getReferenceTypesOptions();
$type_defaults = $this->config
->get('types');
foreach ($bibcite_format
->getTypes() as $type) {
$form['types'][$type]['format'] = [
'#type' => 'item',
'#markup' => $type,
'#value' => $type,
];
$form['types'][$type]['entity'] = [
'#type' => 'select',
'#options' => $type_options,
'#empty_option' => $this
->t('- Select -'),
'#default_value' => isset($type_defaults[$type]) ? $type_defaults[$type] : NULL,
];
}
$form['fields'] = [
'#type' => 'table',
'#caption' => $this
->t('Fields mapping'),
'#header' => [
$this
->t('Format field'),
$this
->t('Reference field'),
],
];
$field_options = $this
->getReferenceFieldOptions();
$field_defaults = $this->config
->get('fields');
foreach ($bibcite_format
->getFields() as $field) {
$form['fields'][$field]['format'] = [
'#type' => 'item',
'#markup' => $field,
'#value' => $field,
];
$form['fields'][$field]['entity'] = [
'#type' => 'select',
'#options' => $field_options,
'#empty_option' => $this
->t('- Select -'),
'#default_value' => isset($field_defaults[$field]) ? $field_defaults[$field] : NULL,
];
}
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Save configuration'),
'#button_type' => 'primary',
];
return $form;
}