-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathopen_citations.module
More file actions
44 lines (39 loc) · 1.24 KB
/
open_citations.module
File metadata and controls
44 lines (39 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* @file
* Open citations module file.
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\open_citations\Entity\node\Publication;
use Drupal\open_citations\OpenCitationsBatches;
/**
* Implements hook_entity_bundle_info_alter().
*/
function open_citations_entity_bundle_info_alter(array &$bundles): void {
if (isset($bundles['node']['publication'])) {
$bundles['node']['publication']['class'] = Publication::class;
}
}
/**
* Implements hook_form_FORM_ID_alter().
*
* Alter node create/edit form to add a new button for triggering the batch.
*/
function open_citations_form_node_form_alter(&$form, $form_state) {
if (isset($form['actions']['submit'])) {
$button_label = t('Save and Update Citation Data');
$form['actions']['update_citations'] = ['#value' => $button_label] + $form['actions']['submit'];
$form['actions']['update_citations']['#submit'][] = '_open_citations_node_format_submit';
}
}
/**
* Submit handler for the update citations button.
*
* @param array $form
* The form.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
function _open_citations_node_format_submit(array $form, FormStateInterface $form_state) {
OpenCitationsBatches::initiateBatchProcessing();
}