Update to Drupal 8.2.0. For more information, see https://www.drupal.org/project/drupal/releases/8.2.0

This commit is contained in:
Pantheon Automation 2016-10-06 15:16:20 -07:00 committed by Greg Anderson
parent 2f563ab520
commit f1c8716f57
1732 changed files with 52334 additions and 11780 deletions

View file

@ -93,12 +93,13 @@ function _content_translation_form_language_content_settings_form_alter(array &$
$form['#attached']['library'][] = 'content_translation/drupal.content_translation.admin';
$entity_manager = Drupal::entityManager();
$bundle_info_service = \Drupal::service('entity_type.bundle.info');
foreach ($form['#labels'] as $entity_type_id => $label) {
$entity_type = $entity_manager->getDefinition($entity_type_id);
$storage_definitions = $entity_type instanceof ContentEntityTypeInterface ? $entity_manager->getFieldStorageDefinitions($entity_type_id) : array();
$entity_type_translatable = $content_translation_manager->isSupported($entity_type_id);
foreach (entity_get_bundles($entity_type_id) as $bundle => $bundle_info) {
foreach ($bundle_info_service->getBundleInfo($entity_type_id) as $bundle => $bundle_info) {
// Here we do not want the widget to be altered and hold also the "Enable
// translation" checkbox, which would be redundant. Hence we add this key
// to be able to skip alterations. Alter the title and display the message
@ -112,7 +113,7 @@ function _content_translation_form_language_content_settings_form_alter(array &$
$fields = $entity_manager->getFieldDefinitions($entity_type_id, $bundle);
if ($fields) {
foreach ($fields as $field_name => $definition) {
if (!empty($storage_definitions[$field_name]) && _content_translation_is_field_translatability_configurable($entity_type, $storage_definitions[$field_name])) {
if ($definition->isComputed() || (!empty($storage_definitions[$field_name]) && _content_translation_is_field_translatability_configurable($entity_type, $storage_definitions[$field_name]))) {
$form['settings'][$entity_type_id][$bundle]['fields'][$field_name] = array(
'#label' => $definition->getLabel(),
'#type' => 'checkbox',

View file

@ -351,9 +351,9 @@ function content_translation_language_fallback_candidates_entity_view_alter(&$ca
*/
function content_translation_entity_extra_field_info() {
$extra = array();
$bundle_info_service = \Drupal::service('entity_type.bundle.info');
foreach (\Drupal::entityManager()->getDefinitions() as $entity_type => $info) {
foreach (entity_get_bundles($entity_type) as $bundle => $bundle_info) {
foreach ($bundle_info_service->getBundleInfo($entity_type) as $bundle => $bundle_info) {
if (\Drupal::service('content_translation.manager')->isEnabled($entity_type, $bundle)) {
$extra[$entity_type][$bundle]['form']['translation'] = array(
'label' => t('Translation'),
@ -412,7 +412,8 @@ function content_translation_entity_presave(EntityInterface $entity) {
// as original language, since source values are the only ones available to
// compare against.
if (!isset($entity->original)) {
$entity->original = entity_load_unchanged($entity->entityType(), $entity->id());
$entity->original = \Drupal::entityTypeManager()
->getStorage($entity->entityType())->loadUnchanged($entity->id());
}
$langcode = $entity->language()->getId();
/** @var \Drupal\content_translation\ContentTranslationManagerInterface $manager */

View file

@ -1,6 +1,5 @@
administer content translation:
title: 'Administer translation settings'
description: 'Configure translatability of entities and fields.'
create content translations:
title: 'Create translations'
update content translations:

View file

@ -26,7 +26,7 @@ class ContentTranslationController extends ControllerBase {
/**
* Initializes a content translation controller.
*
* @param \Drupal\content_translation\ContentTranslationManagerInterface
* @param \Drupal\content_translation\ContentTranslationManagerInterface $manager
* A content translation manager instance.
*/
public function __construct(ContentTranslationManagerInterface $manager) {
@ -319,7 +319,7 @@ class ContentTranslationController extends ControllerBase {
* @param \Drupal\Core\Language\LanguageInterface $target
* The language of the translated values. Defaults to the current content
* language.
* @param \Drupal\Core\Routing\RouteMatchInterface
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match object from which to extract the entity type.
* @param string $entity_type_id
* (optional) The entity type ID.
@ -354,7 +354,7 @@ class ContentTranslationController extends ControllerBase {
* @param \Drupal\Core\Language\LanguageInterface $language
* The language of the translated values. Defaults to the current content
* language.
* @param \Drupal\Core\Routing\RouteMatchInterface
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match object from which to extract the entity type.
* @param string $entity_type_id
* (optional) The entity type ID.

View file

@ -77,7 +77,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
$this->drupalLogin($this->editor);
$this->entityId = $this->createEntity($values[$default_langcode], $default_langcode);
$this->drupalLogin($this->translator);
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$this->assertTrue($entity, 'Entity found in the database.');
$this->drupalGet($entity->urlInfo());
$this->assertResponse(200, 'Entity URL is valid.');
@ -119,7 +122,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
// Ensure that the content language cache context is not yet added to the
// page.
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$this->drupalGet($entity->urlInfo());
$this->assertCacheContexts(Cache::mergeContexts(['languages:language_content'], $this->defaultCacheContexts));
@ -154,7 +160,8 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
if ($this->testLanguageSelector) {
$this->assertNoFieldByXPath('//select[@id="edit-langcode-0-value"]', NULL, 'Language selector correctly disabled on translations.');
}
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$this->drupalGet($entity->urlInfo('drupal:content-translation-overview'));
$this->assertNoText('Source language', 'Source language column correctly hidden.');
@ -184,7 +191,8 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
'target' => $langcode
], array('language' => $language));
$this->drupalPostForm($add_url, $edit, $this->getFormSubmitActionForNewTranslation($entity, $langcode));
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$this->drupalGet($entity->urlInfo('drupal:content-translation-overview'));
$this->assertText('Source language', 'Source language column correctly shown.');
@ -204,7 +212,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
* Tests that the translation overview shows the correct values.
*/
protected function doTestTranslationOverview() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$translate_url = $entity->urlInfo('drupal:content-translation-overview');
$this->drupalGet($translate_url);
$translate_url->setAbsolute(FALSE);
@ -226,7 +237,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
* Tests up-to-date status tracking.
*/
protected function doTestOutdatedStatus() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$langcode = 'fr';
$languages = \Drupal::languageManager()->getLanguages();
@ -234,7 +248,8 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
$edit = array('content_translation[retranslate]' => TRUE);
$edit_path = $entity->urlInfo('edit-form', array('language' => $languages[$langcode]));
$this->drupalPostForm($edit_path, $edit, $this->getFormSubmitAction($entity, $langcode));
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
// Check that every translation has the correct "outdated" status, and that
// the Translation fieldset is open if the translation is "outdated".
@ -252,7 +267,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
$this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $added_langcode));
$this->drupalGet($url);
$this->assertFieldByXPath('//input[@name="content_translation[retranslate]"]', FALSE, 'The retranslate flag is now shown.');
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$this->assertFalse($this->manager->getTranslationMetadata($entity->getTranslation($added_langcode))->isOutdated(), 'The "outdated" status has been correctly stored.');
}
}
@ -262,7 +280,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
* Tests the translation publishing status.
*/
protected function doTestPublishedStatus() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
// Unpublish translations.
foreach ($this->langcodes as $index => $langcode) {
@ -270,7 +291,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
$url = $entity->urlInfo('edit-form', array('language' => ConfigurableLanguage::load($langcode)));
$edit = array('content_translation[status]' => FALSE);
$this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode));
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$this->assertFalse($this->manager->getTranslationMetadata($entity->getTranslation($langcode))->isPublished(), 'The translation has been correctly unpublished.');
}
}
@ -284,7 +308,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
* Tests the translation authoring information.
*/
protected function doTestAuthoringInfo() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$values = array();
// Post different authoring information for each translation.
@ -302,7 +329,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
$this->drupalPostForm($url, $edit, $this->getFormSubmitAction($entity, $langcode));
}
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
foreach ($this->langcodes as $langcode) {
$metadata = $this->manager->getTranslationMetadata($entity->getTranslation($langcode));
$this->assertEqual($metadata->getAuthor()->id(), $values[$langcode]['uid'], 'Translation author correctly stored.');
@ -330,12 +360,16 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
// Confirm and delete a translation.
$this->drupalLogin($this->translator);
$langcode = 'fr';
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$language = ConfigurableLanguage::load($langcode);
$url = $entity->urlInfo('edit-form', array('language' => $language));
$this->drupalPostForm($url, array(), t('Delete translation'));
$this->drupalPostForm(NULL, array(), t('Delete @language translation', array('@language' => $language->getName())));
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId, TRUE);
if ($this->assertTrue(is_object($entity), 'Entity found')) {
$translations = $entity->getTranslationLanguages();
$this->assertTrue(count($translations) == 2 && empty($translations[$langcode]), 'Translation successfully deleted.');
@ -465,7 +499,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
* Tests edit content translation.
*/
protected function doTestTranslationEdit() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$languages = $this->container->get('language_manager')->getLanguages();
foreach ($this->langcodes as $langcode) {
@ -484,7 +521,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
* Tests the basic translation workflow.
*/
protected function doTestTranslationChanged() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$changed_field_name = $this->getChangedFieldName($entity);
$definition = $entity->getFieldDefinition($changed_field_name);
$config = $definition->getConfig($entity->bundle());
@ -517,7 +557,10 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
$edit_path = $entity->urlInfo('edit-form', array('language' => $language));
$this->drupalPostForm($edit_path, $edit, $this->getFormSubmitAction($entity, $langcode));
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$this->assertEqual(
$entity->getChangedTimeAcrossTranslations(), $entity->getTranslation($langcode)->getChangedTime(),
format_string('Changed time for language %language is the latest change over all languages.', array('%language' => $language->getName()))
@ -551,13 +594,19 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
* Test the changed time after API and FORM save without changes.
*/
public function doTestChangedTimeAfterSaveWithoutChanges() {
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
// Test only entities, which implement the EntityChangedInterface.
if ($entity->getEntityType()->isSubclassOf('Drupal\Core\Entity\EntityChangedInterface')) {
$changed_timestamp = $entity->getChangedTime();
$entity->save();
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$this->assertEqual($changed_timestamp, $entity->getChangedTime(), 'The entity\'s changed time wasn\'t updated after API save without changes.');
// Ensure different save timestamps.
@ -568,7 +617,8 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
$edit_path = $entity->urlInfo('edit-form', array('language' => $language));
$this->drupalPostForm($edit_path, [], $this->getFormSubmitAction($entity, $language->getId()));
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$storage->resetCache([$this->entityId]);
$entity = $storage->load($this->entityId);
$this->assertNotEqual($changed_timestamp, $entity->getChangedTime(), 'The entity\'s changed time was updated after form save without changes.');
}
}

View file

@ -64,7 +64,10 @@ class ContentTranslationWorkflowsTest extends ContentTranslationTestBase {
$this->fieldName => array(array('value' => $this->randomMachineName(16))),
);
$id = $this->createEntity($values, $default_langcode);
$this->entity = entity_load($this->entityTypeId, $id, TRUE);
$storage = $this->container->get('entity_type.manager')
->getStorage($this->entityTypeId);
$storage->resetCache([$id]);
$this->entity = $storage->load($id);
// Create a translation.
$this->drupalLogin($this->translator);