-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathppi_preview.module
65 lines (57 loc) · 2.62 KB
/
ppi_preview.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
<?php
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\system\MenuInterface;
use Drupal\language\ConfigurableLanguageInterface;
use Drupal\Core\Access\AccessResult;
function ppi_preview_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.ppi_preview':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Displays previews generated by an InDesign server') . '</p>';
return $output;
default:
}
}
function ppi_preview_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form_object = $form_state->getFormObject();
if ($form_object && method_exists($form_object, 'getEntity')) {
$entity = $form_object->getEntity();
if ($entity->getEntityTypeId() == 'node') {
if ($entity->getType() == 'article' || $entity->getType() == "landing_page") { // type "landing_page" -> Acquia Lightning
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('ppi_preview.settings');
$idWrapperBaseUrl = $config->get('preview_url');
$apiKey = $config->get('api_key');
//\Drupal::logger('ppi_preview')->notice($idWrapperBaseUrl);
$form['ppi_preview'] = [
'#type' => 'details',
'#group' => isset($form['additional_settings']) ? 'additional_settings' : 'advanced',
'#title' => t('Print Preview'),
'#description' => t('Displays a print preview'),
'#weight' => -10,
'#open' => 1
];
$form['ppi_preview']['preview'] = [
'#theme' => 'image',
'#uri' => $idWrapperBaseUrl . '?id=' . $entity->uuid() . '&key=' . $apiKey,
'#style_name' => 'large',
'#title' => t('ppi print preview'),
'#attributes' => [ 'id' => 'ppi-preview-id' ],
'#attached' => [
'library' => [ 'ppi_preview/ppi_preview_expand' ]
]
];
}
}
}
}
function ppi_preview_entity_create_access(\Drupal\Core\Session\AccountInterface $account, array $context, $entity_bundle) {
// $account: Drupal\Core\Session\AccountProxy, account:Drupal\user\Entity\User, id:"1", initialAccountId:null, _serviceId:"current_user"
// $context: [entity_type_id:"paragraph", langcode:"x-default"]
// $entity_bundle: "text"
// \Drupal::logger('ppi_preview')->notice("---------------- hook_entity_create_access() called");
return AccessResult::allowed();
}