public function ReferencePreviewForm::buildForm in Bibliography & Citation 8
Same name and namespace in other branches
- 2.0.x modules/bibcite_entity/src/Form/ReferencePreviewForm.php \Drupal\bibcite_entity\Form\ReferencePreviewForm::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.
\Drupal\Core\Entity\EntityInterface $reference: The reference being previews.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- modules/
bibcite_entity/ src/ Form/ ReferencePreviewForm.php, line 75
Class
- ReferencePreviewForm
- Reference Preview Form.
Namespace
Drupal\bibcite_entity\FormCode
public function buildForm(array $form, FormStateInterface $form_state, EntityInterface $reference = NULL) {
$query_options = [
'query' => [
'uuid' => $reference
->uuid(),
],
];
$query = $this
->getRequest()->query;
if ($query
->has('destination')) {
$query_options['query']['destination'] = $query
->get('destination');
}
$view_mode = $reference->preview_view_mode;
$form['backlink'] = [
'#type' => 'link',
'#title' => $this
->t('Back to reference editing'),
'#url' => $reference
->isNew() ? Url::fromRoute('entity.bibcite_reference.add_form', [
'bibcite_reference_type' => $reference
->bundle(),
]) : $reference
->toUrl('edit-form'),
'#options' => [
'attributes' => [
'class' => [
'reference-preview-backlink',
],
],
] + $query_options,
];
$view_mode_options = $this->entityDisplayRepository
->getViewModeOptionsByBundle('bibcite_reference', $reference
->bundle());
$form['uuid'] = [
'#type' => 'value',
'#value' => $reference
->uuid(),
];
$form['view_mode'] = [
'#type' => 'select',
'#title' => $this
->t('View mode'),
'#options' => $view_mode_options,
'#default_value' => $view_mode,
'#attributes' => [
'data-drupal-autosubmit' => TRUE,
],
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Switch'),
'#attributes' => [
'class' => [
'js-hide',
],
],
];
return $form;
}