function lingotek_form_alter in Lingotek Translation 8
Same name and namespace in other branches
- 8.2 lingotek.module \lingotek_form_alter()
- 6 lingotek.module \lingotek_form_alter()
- 7.4 lingotek.module \lingotek_form_alter()
- 4.0.x lingotek.module \lingotek_form_alter()
- 3.0.x lingotek.module \lingotek_form_alter()
- 3.1.x lingotek.module \lingotek_form_alter()
- 3.2.x lingotek.module \lingotek_form_alter()
- 3.3.x lingotek.module \lingotek_form_alter()
- 3.4.x lingotek.module \lingotek_form_alter()
- 3.5.x lingotek.module \lingotek_form_alter()
- 3.6.x lingotek.module \lingotek_form_alter()
- 3.7.x lingotek.module \lingotek_form_alter()
- 3.8.x lingotek.module \lingotek_form_alter()
Implements hook_form_alter().
File
- ./
lingotek.module, line 295 - lingotek.module
Code
function lingotek_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form_object = $form_state
->getFormObject();
if ($form_object instanceof ContentEntityFormInterface) {
// If it is a delete form, return.
if ('delete' === $form_object
->getOperation()) {
return;
}
$entity = $form_object
->getEntity();
/** @var ContentTranslationManagerInterface $content_translation_manager */
$content_translation_manager = \Drupal::service('content_translation.manager');
/** @var \Drupal\lingotek\LingotekConfigurationServiceInterface $lingotek_config */
$lingotek_config = \Drupal::service('lingotek.configuration');
// If content translation is not enabled and lingotek configured, don't add
// the form element.
if (!$content_translation_manager
->isEnabled($entity
->getEntityTypeId(), $entity
->bundle()) || !$lingotek_config
->isEnabled($entity
->getEntityTypeId(), $entity
->bundle())) {
return;
}
$default_profile = $lingotek_config
->getEntityProfile($entity);
$profile_options = $lingotek_config
->getProfileOptions();
$current_user = \Drupal::currentUser();
$can_assign_profile = $current_user
->hasPermission('assign lingotek translation profiles') || $current_user
->hasPermission('administer lingotek');
$form['lingotek_translation_management'] = array(
'#type' => 'details',
'#title' => t('Translation Management'),
'#description' => t('The Lingotek Translation module was developed to help you translate your site. The module integrates the Lingotek translation management system directly into Drupal, so that your users can leverage the power of Lingotek\'s translation tools and services without ever having to leave the comfort of your Drupal environment.'),
'#group' => 'advanced',
'#weight' => 50,
'#access' => $can_assign_profile,
);
$form['lingotek_translation_management']['lingotek_translation_profile'] = array(
'#type' => 'select',
'#title' => t('Translation Profile'),
'#options' => $profile_options,
'#default_value' => $default_profile
->id(),
'#access' => $can_assign_profile,
);
foreach (array_keys($form['actions']) as $action) {
if ($action != 'preview' && $action != 'lingotek_metadata' && isset($form['actions'][$action]['#type']) && $form['actions'][$action]['#type'] === 'submit') {
// We need to act before the node itself is saved.
$submit_actions = $form['actions'][$action]['#submit'];
array_unshift($submit_actions, 'lingotek_form_content_entity_form_submit');
$form['actions'][$action]['#submit'] = $submit_actions;
}
}
}
}