forked from VolantisDev/drupal-name-prepopulate
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathname_prepopulate.module
More file actions
41 lines (30 loc) · 1.12 KB
/
name_prepopulate.module
File metadata and controls
41 lines (30 loc) · 1.12 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
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\name_prepopulate\NamePrepopulateHelper;
/**
* Implements hook_entity_prepare_form().
*/
function name_prepopulate_entity_prepare_form(\Drupal\Core\Entity\EntityInterface $entity, $operation, \Drupal\Core\Form\FormStateInterface $form_state) {
$nameField = 'field_name';
$types = ['contact_message'];
if (!in_array($entity->getEntityTypeId(), $types) || !($entity instanceof \Drupal\Core\Entity\FieldableEntityInterface)) {
return;
}
if (!$entity->hasField($nameField) || $entity->get($nameField)->isEmpty()) {
return;
}
$helper = new NamePrepopulateHelper($entity, $nameField);
$helper->prepopulateFromAccount();
}
/**
* Implements hook_entity_presave().
*/
function name_prepopulate_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
$nameField = 'field_name';
$types = ['contact_message'];
if (!in_array($entity->getEntityTypeId(), $types) || !($entity instanceof \Drupal\Core\Entity\FieldableEntityInterface)) {
return;
}
$helper = new NamePrepopulateHelper($entity, $nameField);
$helper->fillTextField($entity, 'name');
}