function translation_views_content_form_fix_destination in Translation Views 8
Submit callback for "source_langcode" button.
1 string reference to 'translation_views_content_form_fix_destination'
- translation_views_form_alter in ./
translation_views.module - Implements hook_form_alter().
File
- ./
translation_views.module, line 59 - Provide hooks for translation_views module.
Code
function translation_views_content_form_fix_destination($form, FormStateInterface $form_state) {
/* @var \Drupal\Core\Entity\ContentEntityFormInterface $form_object */
/* @var \Drupal\Core\Entity\ContentEntityInterface $entity */
/* @var \Symfony\Component\HttpFoundation\ParameterBag $query */
$form_object = $form_state
->getFormObject();
$entity = $form_object
->getEntity();
$source = $form_state
->getValue([
'source_langcode',
'source',
]);
$query = \Drupal::service('request_stack')
->getCurrentRequest()->query;
$options = [];
// Remove destination parameter from request,
// to allow "Change" button works like desired.
if ($query
->has('destination')) {
$options['query']['destination'] = $query
->get('destination');
$query
->remove('destination');
}
$entity_type_id = $entity
->getEntityTypeId();
$form_state
->setRedirect("entity.{$entity_type_id}.content_translation_add", [
$entity_type_id => $entity
->id(),
'source' => $source,
'target' => $form_object
->getFormLangcode($form_state),
], $options);
}