-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitc_jsonapi.module
75 lines (67 loc) · 2.18 KB
/
itc_jsonapi.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
69
70
71
72
73
74
75
<?php
/**
* @file
* Contains itc_jsonapi.module.
*/
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\itc_jsonapi\MenuLinkContentAccessControlHandler;
/**
* Implements hook_help().
*/
function itc_jsonapi_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the itc_jsonapi module.
case 'help.page.itc_jsonapi':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('jsonapi enhencers') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_entity_type_build().
*/
function itc_jsonapi_entity_type_build(array &$entity_types) {
if (isset($entity_types['menu_link_content'])) {
/** @var \Drupal\Core\Entity\ContentEntityType $menu_link_content_type */
$menu_link_content_type = $entity_types['menu_link_content'];
$menu_link_content_type->setHandlerClass('access', MenuLinkContentAccessControlHandler::class);
}
}
/**
* Implements hook_entity_bundle_field_info_alter().
*
* @param \Drupal\Core\Field\FieldDefinitionInterface[] $fields
*/
function itc_jsonapi_entity_bundle_field_info_alter(&$fields, EntityTypeInterface $entity_type, $bundle) {
if ($entity_type->id() === 'contact_message'
&& $bundle === 'newsletter') {
if (isset($fields['field_email'])) {
$fields['field_email']->addConstraint('unique_email');
}
}
}
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function itc_jsonapi_contact_message_insert(EntityInterface $entity) {
$route_match = \Drupal::routeMatch();
$route_name = $route_match->getRouteName();
if (strpos($route_name, 'jsonapi.contact_message') === 0) {
/** @var \Drupal\contact\MessageInterface $message */
$message = $entity;
/** @var \Drupal\contact\MailHandlerInterface $mail_handler */
$mail_handler = \Drupal::service('contact.mail_handler');
$mail_handler->sendMailMessages($message, \Drupal::currentUser());
}
}
/**
*
*/
function itc_jsonapi_form_node_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Preview not available using jsonapi.
}