ContentTranslationHandler.php 24.3 KB
Newer Older
1 2 3 4
<?php

/**
 * @file
5
 * Contains \Drupal\content_translation\ContentTranslationHandler.
6 7
 */

8
namespace Drupal\content_translation;
9

10
use Drupal\Core\Access\AccessResult;
11
use Drupal\Core\DependencyInjection\DependencySerializationTrait;
12
use Drupal\Core\Entity\EntityHandlerInterface;
13
use Drupal\Core\Entity\EntityInterface;
14
use Drupal\Core\Entity\EntityTypeInterface;
15
use Drupal\Core\Field\BaseFieldDefinition;
16
use Drupal\Core\Form\FormStateInterface;
17
use Drupal\Core\Language\LanguageInterface;
18
use Drupal\Core\Language\LanguageManagerInterface;
19
use Drupal\Core\Render\Element;
20
use Drupal\user\Entity\User;
21
use Symfony\Component\DependencyInjection\ContainerInterface;
22 23

/**
24
 * Base class for content translation handlers.
25 26
 *
 * @ingroup entity_api
27
 */
28
class ContentTranslationHandler implements ContentTranslationHandlerInterface, EntityHandlerInterface {
29
  use DependencySerializationTrait;
30 31 32 33 34 35

  /**
   * The type of the entity being translated.
   *
   * @var string
   */
36
  protected $entityTypeId;
37 38

  /**
39
   * Information about the entity type.
40
   *
41
   * @var \Drupal\Core\Entity\EntityTypeInterface
42
   */
43
  protected $entityType;
44

45 46 47 48 49 50 51 52
  /**
   * The language manager.
   *
   * @var \Drupal\Core\Language\LanguageManagerInterface
   */
  protected $languageManager;

  /**
53 54 55
   * The content translation manager.
   *
   * @var \Drupal\content_translation\ContentTranslationManagerInterface
56
   */
57
  protected $manager;
58

59
  /**
60
   * Initializes an instance of the content translation controller.
61
   *
62
   * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type
63
   *   The info array of the given entity type.
64 65
   * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
   *   The language manager.
66 67
   * @param \Drupal\content_translation\ContentTranslationManagerInterface $manager
   *   The content translation manager service.
68
   */
69
  public function __construct(EntityTypeInterface $entity_type, LanguageManagerInterface $language_manager, ContentTranslationManagerInterface $manager) {
70 71
    $this->entityTypeId = $entity_type->id();
    $this->entityType = $entity_type;
72
    $this->languageManager = $language_manager;
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
    $this->manager = $manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) {
    return new static(
      $entity_type,
      $container->get('language_manager'),
      $container->get('content_translation.manager')
    );
  }

  /**
   * {@inheritdoc}
   */
  public function getFieldDefinitions() {
    $definitions = array();

    $definitions['content_translation_source'] = BaseFieldDefinition::create('language')
      ->setLabel(t('Translation source'))
      ->setDescription(t('The source language from which this translation was created.'))
      ->setDefaultValue(LanguageInterface::LANGCODE_NOT_SPECIFIED)
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE);

    $definitions['content_translation_outdated'] = BaseFieldDefinition::create('boolean')
      ->setLabel(t('Translation outdated'))
      ->setDescription(t('A boolean indicating whether this translation needs to be updated.'))
      ->setDefaultValue(FALSE)
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE);

    if (!$this->hasAuthor()) {
      $definitions['content_translation_uid'] = BaseFieldDefinition::create('entity_reference')
        ->setLabel(t('Translation author'))
        ->setDescription(t('The author of this translation.'))
        ->setSetting('target_type', 'user')
        ->setSetting('handler', 'default')
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE);
    }

    if (!$this->hasPublishedStatus()) {
      $definitions['content_translation_status'] = BaseFieldDefinition::create('boolean')
        ->setLabel(t('Translation status'))
        ->setDescription(t('A boolean indicating whether the translation is visible to non-translators.'))
        ->setDefaultValue(TRUE)
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE);
    }

    if (!$this->hasCreatedTime()) {
      $definitions['content_translation_created'] = BaseFieldDefinition::create('created')
        ->setLabel(t('Translation created time'))
        ->setDescription(t('The Unix timestamp when the translation was created.'))
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE);
    }

    if (!$this->hasChangedTime()) {
      $definitions['content_translation_changed'] = BaseFieldDefinition::create('changed')
        ->setLabel(t('Translation changed time'))
        ->setDescription(t('The Unix timestamp when the translation was most recently saved.'))
        ->setPropertyConstraints('value', array('EntityChanged' => array()))
        ->setRevisionable(TRUE)
        ->setTranslatable(TRUE);
    }

    return $definitions;
  }

  /**
   * Checks whether the entity type supports author natively.
   *
   * @return bool
   *   TRUE if metadata is natively supported, FALSE otherwise.
   */
  protected function hasAuthor() {
    return is_subclass_of($this->entityType->getClass(), '\Drupal\user\EntityOwnerInterface');
  }

  /**
   * Checks whether the entity type supports published status natively.
   *
   * @return bool
   *   TRUE if metadata is natively supported, FALSE otherwise.
   */
  protected function hasPublishedStatus() {
    return array_key_exists('status', \Drupal::entityManager()->getLastInstalledFieldStorageDefinitions($this->entityType->id()));
  }

  /**
   * Checks whether the entity type supports modification time natively.
   *
   * @return bool
   *   TRUE if metadata is natively supported, FALSE otherwise.
   */
  protected function hasChangedTime() {
    return is_subclass_of($this->entityType->getClass(), '\Drupal\Core\Entity\EntityChangedInterface');
  }

  /**
   * Checks whether the entity type supports creation time natively.
   *
   * @return bool
   *   TRUE if metadata is natively supported, FALSE otherwise.
   */
  protected function hasCreatedTime() {
    return array_key_exists('created', \Drupal::entityManager()->getLastInstalledFieldStorageDefinitions($this->entityType->id()));
184 185 186
  }

  /**
187
   * {@inheritdoc}
188 189
   */
  public function retranslate(EntityInterface $entity, $langcode = NULL) {
190
    $updated_langcode = !empty($langcode) ? $langcode : $entity->language()->getId();
191 192 193
    foreach ($entity->getTranslationLanguages() as $langcode => $language) {
      $this->manager->getTranslationMetadata($entity->getTranslation($langcode))
        ->setOutdated($langcode != $updated_langcode);
194 195 196 197
    }
  }

  /**
198
   * {@inheritdoc}
199
   */
200
  public function getTranslationAccess(EntityInterface $entity, $op) {
201
    // @todo Move this logic into a translation access control handler checking also
202
    //   the translation language and the given account.
203
    $entity_type = $entity->getEntityType();
204 205 206
    $translate_permission = TRUE;
    // If no permission granularity is defined this entity type does not need an
    // explicit translate permission.
207 208 209
    $current_user = \Drupal::currentUser();
    if (!$current_user->hasPermission('translate any entity') && $permission_granularity = $entity_type->getPermissionGranularity()) {
      $translate_permission = $current_user->hasPermission($permission_granularity == 'bundle' ? "translate {$entity->bundle()} {$entity->getEntityTypeId()}" : "translate {$entity->getEntityTypeId()}");
210
    }
211
    return AccessResult::allowedIf($translate_permission && $current_user->hasPermission("$op content translations"))->cachePerRole();
212 213 214
  }

  /**
215
   * {@inheritdoc}
216
   */
217
  public function getSourceLangcode(FormStateInterface $form_state) {
218
    if ($source = $form_state->get(['content_translation', 'source'])) {
219
      return $source->getId();
220 221
    }
    return FALSE;
222 223 224
  }

  /**
225
   * {@inheritdoc}
226
   */
227
  public function entityFormAlter(array &$form, FormStateInterface $form_state, EntityInterface $entity) {
228 229
    $form_object = $form_state->getFormObject();
    $form_langcode = $form_object->getFormLangcode($form_state);
230
    $entity_langcode = $entity->getUntranslated()->language()->getId();
231 232 233 234 235 236 237 238
    $source_langcode = $this->getSourceLangcode($form_state);

    $new_translation = !empty($source_langcode);
    $translations = $entity->getTranslationLanguages();
    if ($new_translation) {
      // Make sure a new translation does not appear as existing yet.
      unset($translations[$form_langcode]);
    }
239
    $is_translation = !$form_object->isDefaultFormLangcode($form_state);
240 241 242 243
    $has_translations = count($translations) > 1;

    // Adjust page title to specify the current language being edited, if we
    // have at least one translation.
244
    $languages = $this->languageManager->getLanguages();
245 246 247
    if (isset($languages[$form_langcode]) && ($has_translations || $new_translation)) {
      $title = $this->entityFormTitle($entity);
      // When editing the original values display just the entity label.
248
      if ($form_langcode != $entity_langcode) {
249
        $t_args = array('%language' => $languages[$form_langcode]->getName(), '%title' => $entity->label());
250 251
        $title = empty($source_langcode) ? $title . ' [' . t('%language translation', $t_args) . ']' : t('Create %language translation of %title', $t_args);
      }
252
      $form['#title'] = $title;
253 254 255 256 257 258
    }

    // Display source language selector only if we are creating a new
    // translation and there are at least two translations available.
    if ($has_translations && $new_translation) {
      $form['source_langcode'] = array(
259
        '#type' => 'details',
260
        '#title' => t('Source language: @language', array('@language' => $languages[$source_langcode]->getName())),
261 262 263 264
        '#tree' => TRUE,
        '#weight' => -100,
        '#multilingual' => TRUE,
        'source' => array(
265 266
          '#title' => t('Select source language'),
          '#title_display' => 'invisible',
267 268 269 270 271 272 273 274 275 276
          '#type' => 'select',
          '#default_value' => $source_langcode,
          '#options' => array(),
        ),
        'submit' => array(
          '#type' => 'submit',
          '#value' => t('Change'),
          '#submit' => array(array($this, 'entityFormSourceChange')),
        ),
      );
277
      foreach ($this->languageManager->getLanguages() as $language) {
278
        if (isset($translations[$language->getId()])) {
279
          $form['source_langcode']['source']['#options'][$language->getId()] = $language->getName();
280 281 282 283
        }
      }
    }

284
    // Locate the language widget.
285 286 287
    $langcode_key = $this->entityType->getKey('langcode');
    if (isset($form[$langcode_key])) {
      $language_widget = &$form[$langcode_key];
288 289 290 291 292 293 294 295 296 297
    }

    // If we are editing the source entity, limit the list of languages so that
    // it is not possible to switch to a language for which a translation
    // already exists. Note that this will only work if the widget is structured
    // like \Drupal\Core\Field\Plugin\Field\FieldWidget\LanguageSelectWidget.
    if (isset($language_widget['widget'][0]['value']) && !$is_translation && $has_translations) {
      $language_select = &$language_widget['widget'][0]['value'];
      if ($language_select['#type'] == 'language_select') {
        $options = array();
298
        foreach ($this->languageManager->getLanguages() as $language) {
299 300 301 302 303
          // Show the current language, and the languages for which no
          // translation already exists.
          if (empty($translations[$language->getId()]) || $language->getId() == $entity_langcode) {
            $options[$language->getId()] = $language->getName();
          }
304
        }
305
        $language_select['#options'] = $options;
306 307 308
      }
    }
    if ($is_translation) {
309 310
      if (isset($language_widget)) {
        $language_widget['widget']['#access'] = FALSE;
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
      }

      // Replace the delete button with the delete translation one.
      if (!$new_translation) {
        $weight = 100;
        foreach (array('delete', 'submit') as $key) {
          if (isset($form['actions'][$key]['weight'])) {
            $weight = $form['actions'][$key]['weight'];
            break;
          }
        }
        $form['actions']['delete_translation'] = array(
          '#type' => 'submit',
          '#value' => t('Delete translation'),
          '#weight' => $weight,
          '#submit' => array(array($this, 'entityFormDeleteTranslation')),
327
          '#access' => $this->getTranslationAccess($entity, 'delete')->isAllowed(),
328 329 330 331 332 333 334 335 336 337
        );
      }

      // Always remove the delete button on translation forms.
      unset($form['actions']['delete']);
    }

    // We need to display the translation tab only when there is at least one
    // translation available or a new one is about to be created.
    if ($new_translation || $has_translations) {
338
      $form['content_translation'] = array(
339
        '#type' => 'details',
340 341 342
        '#title' => t('Translation'),
        '#tree' => TRUE,
        '#weight' => 10,
343
        '#access' => $this->getTranslationAccess($entity, $source_langcode ? 'create' : 'update')->isAllowed(),
344 345 346
        '#multilingual' => TRUE,
      );

347
      // A new translation is enabled by default.
348 349
      $metadata = $this->manager->getTranslationMetadata($entity);
      $status = $new_translation || $metadata->isPublished();
350 351 352 353
      // If there is only one published translation we cannot unpublish it,
      // since there would be nothing left to display.
      $enabled = TRUE;
      if ($status) {
354 355 356 357
        $published = 0;
        foreach ($entity->getTranslationLanguages() as $langcode => $language) {
          $published += $this->manager->getTranslationMetadata($entity->getTranslation($langcode))
            ->isPublished();
358 359 360 361 362 363 364
        }
        $enabled = $published > 1;
      }
      $description = $enabled ?
        t('An unpublished translation will not be visible without translation permissions.') :
        t('Only this translation is published. You must publish at least one more translation to unpublish this one.');

365
      $form['content_translation']['status'] = array(
366 367 368 369 370 371 372
        '#type' => 'checkbox',
        '#title' => t('This translation is published'),
        '#default_value' => $status,
        '#description' => $description,
        '#disabled' => !$enabled,
      );

373
      $translate = !$new_translation && $metadata->isOutdated();
374
      if (!$translate) {
375
        $form['content_translation']['retranslate'] = array(
376 377 378 379 380 381 382
          '#type' => 'checkbox',
          '#title' => t('Flag other translations as outdated'),
          '#default_value' => FALSE,
          '#description' => t('If you made a significant change, which means the other translations should be updated, you can flag all translations of this content as outdated. This will not change any other property of them, like whether they are published or not.'),
        );
      }
      else {
383
        $form['content_translation']['outdated'] = array(
384 385 386 387 388
          '#type' => 'checkbox',
          '#title' => t('This translation needs to be updated'),
          '#default_value' => $translate,
          '#description' => t('When this option is checked, this translation needs to be updated. Uncheck when the translation is up to date again.'),
        );
389
        $form['content_translation']['#open'] = TRUE;
390 391
      }

392 393 394
      // Default to the anonymous user.
      $name = '';
      if ($new_translation) {
395
        $name = \Drupal::currentUser()->getUsername();
396
      }
397 398
      elseif (($account = $metadata->getAuthor()) && $account->id()) {
        $name = $account->getUsername();
399
      }
400
      $form['content_translation']['name'] = array(
401 402 403
        '#type' => 'textfield',
        '#title' => t('Authored by'),
        '#maxlength' => 60,
404
        '#autocomplete_route_name' => 'user.autocomplete',
405
        '#default_value' => $name,
406
        '#description' => t('Leave blank for %anonymous.', array('%anonymous' => \Drupal::config('user.settings')->get('anonymous'))),
407 408
      );

409
      $date = $new_translation ? REQUEST_TIME : $metadata->getCreatedTime();
410
      $form['content_translation']['created'] = array(
411 412 413
        '#type' => 'textfield',
        '#title' => t('Authored on'),
        '#maxlength' => 25,
414 415
        '#description' => t('Format: %time. The date format is YYYY-MM-DD and %timezone is the time zone offset from UTC. Leave blank to use the time of form submission.', array('%time' => format_date(REQUEST_TIME, 'custom', 'Y-m-d H:i:s O'), '%timezone' => format_date(REQUEST_TIME, 'custom', 'O'))),
        '#default_value' => $new_translation || !$date ? '' : format_date($date, 'custom', 'Y-m-d H:i:s O'),
416 417
      );

418 419
      if (isset($language_widget)) {
        $language_widget['#multilingual'] = TRUE;
420 421 422 423 424 425 426 427
      }

      $form['#process'][] = array($this, 'entityFormSharedElements');
    }

    // Process the submitted values before they are stored.
    $form['#entity_builders'][] = array($this, 'entityFormEntityBuild');

428 429 430 431 432
    // Handle entity validation.
    if (isset($form['actions']['submit'])) {
      $form['actions']['submit']['#validate'][] = array($this, 'entityFormValidate');
    }

433 434 435 436 437 438 439
    // Handle entity deletion.
    if (isset($form['actions']['delete'])) {
      $form['actions']['delete']['#submit'][] = array($this, 'entityFormDelete');
    }
  }

  /**
440
   * Process callback: determines which elements get clue in the form.
441
   *
442
   * @see \Drupal\content_translation\ContentTranslationHandler::entityFormAlter()
443
   */
444
  public function entityFormSharedElements($element, FormStateInterface $form_state, $form) {
445 446 447 448 449
    static $ignored_types;

    // @todo Find a more reliable way to determine if a form element concerns a
    //   multilingual value.
    if (!isset($ignored_types)) {
450
      $ignored_types = array_flip(array('actions', 'value', 'hidden', 'vertical_tabs', 'token', 'details'));
451 452
    }

453
    foreach (Element::children($element) as $key) {
454
      if (!isset($element[$key]['#type'])) {
455
        $this->entityFormSharedElements($element[$key], $form_state, $form);
456 457 458 459 460 461 462 463
      }
      else {
        // Ignore non-widget form elements.
        if (isset($ignored_types[$element[$key]['#type']])) {
          continue;
        }
        // Elements are considered to be non multilingual by default.
        if (empty($element[$key]['#multilingual'])) {
464 465 466
          // If we are displaying a multilingual entity form we need to provide
          // translatability clues, otherwise the shared form elements should be
          // hidden.
467
          if (!$form_state->get(['content_translation', 'translation_form'])) {
468 469 470 471 472
            $this->addTranslatabilityClue($element[$key]);
          }
          else {
            $element[$key]['#access'] = FALSE;
          }
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
        }
      }
    }

    return $element;
  }

  /**
   * Adds a clue about the form element translatability.
   *
   * If the given element does not have a #title attribute, the function is
   * recursively applied to child elements.
   *
   * @param array $element
   *   A form element array.
   */
  protected function addTranslatabilityClue(&$element) {
    static $suffix, $fapi_title_elements;

    // Elements which can have a #title attribute according to FAPI Reference.
    if (!isset($suffix)) {
      $suffix = ' <span class="translation-entity-all-languages">(' . t('all languages') . ')</span>';
495
      $fapi_title_elements = array_flip(array('checkbox', 'checkboxes', 'date', 'details', 'fieldset', 'file', 'item', 'password', 'password_confirm', 'radio', 'radios', 'select', 'text_format', 'textarea', 'textfield', 'weight'));
496 497 498 499 500 501 502 503 504 505
    }

    // Update #title attribute for all elements that are allowed to have a
    // #title attribute according to the Form API Reference. The reason for this
    // check is because some elements have a #title attribute even though it is
    // not rendered, e.g. field containers.
    if (isset($element['#type']) && isset($fapi_title_elements[$element['#type']]) && isset($element['#title'])) {
      $element['#title'] .= $suffix;
    }
    // If the current element does not have a (valid) title, try child elements.
506
    elseif ($children = Element::children($element)) {
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
      foreach ($children as $delta) {
        $this->addTranslatabilityClue($element[$delta], $suffix);
      }
    }
    // If there are no children, fall back to the current #title attribute if it
    // exists.
    elseif (isset($element['#title'])) {
      $element['#title'] .= $suffix;
    }
  }

  /**
   * Entity builder method.
   *
   * @param string $entity_type
   *   The type of the entity.
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity whose form is being built.
   *
526
   * @see \Drupal\content_translation\ContentTranslationHandler::entityFormAlter()
527
   */
528
  public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
529 530
    $form_object = $form_state->getFormObject();
    $form_langcode = $form_object->getFormLangcode($form_state);
531
    $values = &$form_state->getValue('content_translation', array());
532

533 534
    if ($values['name'] == \Drupal::config('user.settings')->get('anonymous')) {
      $values['name'] = '';
535 536
    }

537 538 539 540 541
    $metadata = $this->manager->getTranslationMetadata($entity);
    $metadata->setAuthor(!empty($values['name']) && ($account = user_load_by_name($values['name'])) ? $account : User::load(0));
    $metadata->setPublished(!empty($values['status']));
    $metadata->setCreatedTime(!empty($values['created']) ? strtotime($values['created']) : REQUEST_TIME);
    $metadata->setChangedTime(REQUEST_TIME);
542

543 544
    $source_langcode = $this->getSourceLangcode($form_state);
    if ($source_langcode) {
545
      $metadata->setSource($source_langcode);
546 547
    }

548
    $metadata->setOutdated(!empty($values['outdated']));
549 550 551 552 553
    if (!empty($values['retranslate'])) {
      $this->retranslate($entity, $form_langcode);
    }
  }

554
  /**
555
   * Form validation handler for ContentTranslationHandler::entityFormAlter().
556
   *
557
   * Validates the submitted content translation metadata.
558
   */
559
  function entityFormValidate($form, FormStateInterface $form_state) {
560 561
    if (!$form_state->isValueEmpty('content_translation')) {
      $translation = $form_state->getValue('content_translation');
562 563
      // Validate the "authored by" field.
      if (!empty($translation['name']) && !($account = user_load_by_name($translation['name']))) {
564
        $form_state->setErrorByName('content_translation][name', t('The translation authoring username %name does not exist.', array('%name' => $translation['name'])));
565 566 567
      }
      // Validate the "authored on" field.
      if (!empty($translation['created']) && strtotime($translation['created']) === FALSE) {
568
        $form_state->setErrorByName('content_translation][created', t('You have to specify a valid translation authoring date.'));
569 570 571 572
      }
    }
  }

573
  /**
574
   * Form submission handler for ContentTranslationHandler::entityFormAlter().
575 576 577
   *
   * Takes care of the source language change.
   */
578
  public function entityFormSourceChange($form, FormStateInterface $form_state) {
579 580
    $form_object = $form_state->getFormObject();
    $entity = $form_object->getEntity();
581
    $source = $form_state->getValue(array('source_langcode', 'source'));
582

583 584 585 586
    $entity_type_id = $entity->getEntityTypeId();
    $form_state->setRedirect('content_translation.translation_add_' . $entity_type_id, array(
      $entity_type_id => $entity->id(),
      'source' => $source,
587
      'target' => $form_object->getFormLangcode($form_state),
588
    ));
589
    $languages = $this->languageManager->getLanguages();
590
    drupal_set_message(t('Source language set to: %language', array('%language' => $languages[$source]->getName())));
591 592 593
  }

  /**
594
   * Form submission handler for ContentTranslationHandler::entityFormAlter().
595 596 597
   *
   * Takes care of entity deletion.
   */
598
  function entityFormDelete($form, FormStateInterface $form_state) {
599 600
    $form_object = $form_state->getFormObject()->getEntity();
    $entity = $form_object->getEntity();
601 602 603 604 605 606
    if (count($entity->getTranslationLanguages()) > 1) {
      drupal_set_message(t('This will delete all the translations of %label.', array('%label' => $entity->label())), 'warning');
    }
  }

  /**
607
   * Form submission handler for ContentTranslationHandler::entityFormAlter().
608
   *
609
   * Takes care of content translation deletion.
610
   */
611
  function entityFormDeleteTranslation($form, FormStateInterface $form_state) {
612 613
    $form_object = $form_state->getFormObject();
    $entity = $form_object->getEntity();
614
    $entity_type_id = $entity->getEntityTypeId();
615
    $form_state->setRedirect('content_translation.translation_delete_' . $entity_type_id, array(
616
      $entity_type_id => $entity->id(),
617
      'language' => $form_object->getFormLangcode($form_state),
618
    ));
619 620 621 622 623 624 625 626 627 628 629 630 631
  }

  /**
   * Returns the title to be used for the entity form page.
   *
   * @param \Drupal\Core\Entity\EntityInterface $entity
   *   The entity whose form is being altered.
   */
  protected function entityFormTitle(EntityInterface $entity) {
    return $entity->label();
  }

}