-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkbench_reviewer.module
68 lines (63 loc) · 2.31 KB
/
workbench_reviewer.module
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityTypeInterface;
/**
* Implements hook_entity_bundle_field_info().
*/
function workbench_reviewer_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
// Only add the reviewer field for bundles that are under moderation.
if ($entity_type->id() == 'node' && array_key_exists('moderation_state', $base_field_definitions)) {
$definitions['workbench_reviewer'] = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Request review'))
->setDescription(t('Optional: Enter the name of the user who should review this change.'))
->setDisplayConfigurable('view', TRUE)
->setDisplayOptions('view', array(
'label' => 'hidden',
'type' => 'hidden',
))
->setDisplayConfigurable('form', FALSE)
->setDisplayOptions('form', array(
'type' => 'entity_reference_autocomplete',
'weight' => 100,
'settings' => array(
'size' => 60,
'match_operator' => 'CONTAINS',
'placeholder' => ''
),
))
->setSetting('target_type', 'user');
return $definitions;
}
}
/**
* Implements hook_entity_field_storage_info().
*/
function workbench_reviewer_entity_field_storage_info(EntityTypeInterface $entity_type) {
// Adds the field for Workbench Reviewer to entity that are nodes.
if ($entity_type->id() == 'node') {
$definitions['workbench_reviewer'] = BaseFieldDefinition::create('entity_reference')
->setName('workbench_reviewer')
->setLabel(t('Request review'))
->setTargetEntityTypeId($entity_type->id())
->setSetting('target_type', 'user');
return $definitions;
}
}
/**
* Implements hook_form_BASE_FORM_ID_alter().
*
*/
function workbench_reviewer_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Move the Workbench Reviewer field to the 'meta' tab group.
$form['workbench_reviewer']['#group'] = 'meta';
}
/**
* Implements hook_preprocess_page().
*/
function workbench_reviewer_preprocess_page(&$variables) {
// For admin pages, add in our library CSS and other assets.
if ($variables['is_admin']) {
$variables['#attached']['library'][] = 'workbench_reviewer/workbench_reviewer';
}
}