-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathargo.module
86 lines (79 loc) · 2.99 KB
/
argo.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
76
77
78
79
80
81
82
83
84
85
86
<?php
/**
* @file
* Implement hook for Argo module.
*/
use Drupal\Core\Database\Database;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\field\FieldConfigInterface;
use Psr\Log\LogLevel;
/**
* Implements hook_entity_delete().
*
* Argo periodically syncs asset metadata modified since the last sync.
* Since deleted tracked entities won't show up in that query, we need to
* log these deletions and clean up after they're accounted for.
* Without this deletion log, we would have to check all entities and subtract
* the ones not present after the last sync. The deletion log is a more efficient
* alternative.
*
* @param Drupal\Core\Entity\EntityInterface $entity
* Entity about to be deleted.
*/
function argo_entity_delete(EntityInterface $entity) {
if ($entity instanceof ContentEntityInterface && $entity->isTranslatable()) {
$conn = Database::getConnection();
try {
$conn->upsert('argo_entity_deletion')
->fields([
'entityType' => $entity->getEntityTypeId(),
'bundle' => $entity->bundle(),
'uuid' => $entity->uuid(),
])
->key('uuid')
->execute();
}
catch (Exception $e) {
\Drupal::logger('argo')->log(LogLevel::ERROR, $e->__toString());
}
}
}
/**
* Implements hook_FORM_ID_alter().
*
* Exposes new field configuration to exclude field from being exported and
* translated by Argo. Its value can still be translated manually - changed
* per language. This is useful for certain string values such as display
* settings where the value itself should not be translated as it is used to
* control how content is rendered (e.g. css classes, event date/time timezone
* settings etc...).
*/
function argo_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state) {
/** @var \Drupal\field\Entity\FieldConfig $field_config */
$field_config = $form_state->getFormObject()->getEntity();
$bundle_is_translatable = \Drupal::service('content_translation.manager')
->isEnabled($field_config->getTargetEntityTypeId(), $field_config->getTargetBundle());
$form['argo_excluded'] = [
'#type' => 'checkbox',
'#title' => t('Exclude from Argo translations'),
'#weight' => 0,
'#default_value' => $field_config->getThirdPartySetting('argo', 'excluded', 0),
'#description' => t('This field will no longer be exported and translated by Argo, but can still be translated manually.'),
'#states' => [
'visible' => [
':input[name="translatable"]' => ['checked' => TRUE],
],
],
'#access' => $bundle_is_translatable,
];
$form['#entity_builders'][] = 'argo_entity_builder';
}
/**
* Entity builder callback.
*/
function argo_entity_builder($entity_type, FieldConfigInterface $entity, &$form, FormStateInterface $form_state) {
$exclude_from_translation = $form_state->getValue('argo_excluded');
$entity->setThirdPartySetting('argo', 'excluded', $exclude_from_translation);
}