Update to Drupal 8.0.0-beta15. For more information, see: https://www.drupal.org/node/2563023

This commit is contained in:
Pantheon Automation 2015-09-04 13:20:09 -07:00 committed by Greg Anderson
parent 2720a9ec4b
commit f3791f1da3
1898 changed files with 54300 additions and 11481 deletions

View file

@ -5,7 +5,6 @@
* The content translation administration forms.
*/
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Config\Entity\ThirdPartySettingsInterface;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityTypeInterface;
@ -216,10 +215,10 @@ function _content_translation_preprocess_language_content_settings_table(&$varia
'bundle' => array(
'#prefix' => '<span class="visually-hidden">',
'#suffix' => '</span> ',
'#markup' => SafeMarkup::checkPlain($element[$bundle]['settings']['#label']),
'#plain_text' => $element[$bundle]['settings']['#label'],
),
'field' => array(
'#markup' => SafeMarkup::checkPlain($field_element['#label']),
'#plain_text' => $field_element['#label'],
),
),
'class' => array('field'),
@ -250,15 +249,15 @@ function _content_translation_preprocess_language_content_settings_table(&$varia
'bundle' => array(
'#prefix' => '<span class="visually-hidden">',
'#suffix' => '</span> ',
'#markup' => SafeMarkup::checkPlain($element[$bundle]['settings']['#label']),
'#plain_text' => $element[$bundle]['settings']['#label'],
),
'field' => array(
'#prefix' => '<span class="visually-hidden">',
'#suffix' => '</span> ',
'#markup' => SafeMarkup::checkPlain($field_element['#label']),
'#plain_text' => $field_element['#label'],
),
'columns' => array(
'#markup' => SafeMarkup::checkPlain($column_label),
'#plain_text' => $column_label,
),
),
'class' => array('column'),

View file

@ -11,6 +11,9 @@
* Forces applicable options to be checked as translatable.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attaches content translation dependent options to the UI.
*/
Drupal.behaviors.contentTranslationDependentOptions = {
attach: function (context) {
@ -75,11 +78,14 @@
* Makes field translatability inherit bundle translatability.
*
* @type {Drupal~behavior}
*
* @prop {Drupal~behaviorAttach} attach
* Attaches content translation behavior.
*/
Drupal.behaviors.contentTranslation = {
attach: function (context) {
// Initially hide all field rows for non translatable bundles and all column
// rows for non translatable fields.
// Initially hide all field rows for non translatable bundles and all
// column rows for non translatable fields.
$(context).find('table .bundle-settings .translatable :input').once('translation-entity-admin-hide').each(function () {
var $input = $(this);
var $bundleSettings = $input.closest('.bundle-settings');

View file

@ -267,7 +267,8 @@ function content_translation_menu_links_discovered_alter(array &$links) {
*/
function content_translation_translate_access(EntityInterface $entity) {
$account = \Drupal::currentUser();
$condition = $entity instanceof ContentEntityInterface && !$entity->getUntranslated()->language()->isLocked() && \Drupal::languageManager()->isMultilingual() && $entity->isTranslatable() &&
$condition = $entity instanceof ContentEntityInterface && $entity->access('view') &&
!$entity->getUntranslated()->language()->isLocked() && \Drupal::languageManager()->isMultilingual() && $entity->isTranslatable() &&
($account->hasPermission('create content translations') || $account->hasPermission('update content translations') || $account->hasPermission('delete content translations'));
return AccessResult::allowedIf($condition)->cachePerPermissions()->cacheUntilEntityChanges($entity);
}

View file

@ -290,8 +290,8 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E
$title = $this->entityFormTitle($entity);
// When editing the original values display just the entity label.
if ($form_langcode != $entity_langcode) {
$t_args = array('%language' => $languages[$form_langcode]->getName(), '%title' => $entity->label(), '!title' => $title);
$title = empty($source_langcode) ? t('!title [%language translation]', $t_args) : t('Create %language translation of %title', $t_args);
$t_args = array('%language' => $languages[$form_langcode]->getName(), '%title' => $entity->label(), '@title' => $title);
$title = empty($source_langcode) ? t('@title [%language translation]', $t_args) : t('Create %language translation of %title', $t_args);
}
$form['#title'] = $title;
}

View file

@ -62,7 +62,7 @@ class ContentTranslationUpdatesManager implements EventSubscriberInterface {
foreach (array_diff_key($storage_definitions, $installed_storage_definitions) as $storage_definition) {
/** @var $storage_definition \Drupal\Core\Field\FieldStorageDefinitionInterface */
if ($storage_definition->getProvider() == 'content_translation') {
$this->entityManager->onFieldStorageDefinitionCreate($storage_definition);
$this->updateManager->installFieldStorageDefinition($storage_definition->getName(), $entity_type_id, 'content_translation', $storage_definition);
}
}
}

View file

@ -69,6 +69,7 @@ class ContentTranslationRouteSubscriber extends RouteSubscriberBase {
'entity_type_id' => $entity_type_id,
),
array(
'_entity_access' => $entity_type_id . '.view',
'_access_content_translation_overview' => $entity_type_id,
),
array(
@ -94,6 +95,7 @@ class ContentTranslationRouteSubscriber extends RouteSubscriberBase {
),
array(
'_entity_access' => $entity_type_id . '.view',
'_access_content_translation_manage' => 'create',
),
array(

View file

@ -14,6 +14,11 @@ namespace Drupal\content_translation\Tests;
*/
class ContentTestTranslationUITest extends ContentTranslationUITestBase {
/**
* {@inheritdoc}
*/
protected $testHTMLEscapeForAllLanguages = TRUE;
/**
* Modules to enable.
*
@ -21,6 +26,18 @@ class ContentTestTranslationUITest extends ContentTranslationUITestBase {
*/
public static $modules = array('language', 'content_translation', 'entity_test');
/**
* {@inheritdoc}
*/
protected $defaultCacheContexts = [
'languages:language_interface',
'theme',
'url.path',
'url.query_args',
'user.permissions',
'user.roles:authenticated',
];
/**
* Overrides \Drupal\simpletest\WebTestBase::setUp().
*/
@ -34,7 +51,7 @@ class ContentTestTranslationUITest extends ContentTranslationUITestBase {
* Overrides \Drupal\content_translation\Tests\ContentTranslationUITestBase::getTranslatorPermission().
*/
protected function getTranslatorPermissions() {
return array_merge(parent::getTranslatorPermissions(), array('administer entity_test content'));
return array_merge(parent::getTranslatorPermissions(), array('administer entity_test content', 'view test entity'));
}
}

View file

@ -61,7 +61,7 @@ class ContentTranslationMetadataFieldsTest extends ContentTranslationTestBase {
// Create a new test entity with original values in the default language.
$default_langcode = $this->langcodes[0];
$entity_id = $this->createEntity([], $default_langcode);
$entity_id = $this->createEntity(['title' => $this->randomString()], $default_langcode);
$storage = $entity_manager->getStorage($this->entityTypeId);
$storage->resetCache();
$entity = $storage->load($entity_id);
@ -118,7 +118,7 @@ class ContentTranslationMetadataFieldsTest extends ContentTranslationTestBase {
// Create a new test entity with original values in the default language.
$default_langcode = $this->langcodes[0];
$entity_id = $this->createEntity(['status' => FALSE], $default_langcode);
$entity_id = $this->createEntity(['title' => $this->randomString(), 'status' => FALSE], $default_langcode);
$storage = $entity_manager->getStorage($this->entityTypeId);
$storage->resetCache();
$entity = $storage->load($entity_id);

View file

@ -9,6 +9,7 @@ namespace Drupal\content_translation\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\node\Tests\NodeTestBase;
use Drupal\user\Entity\Role;
/**
* Tests the content translation operations available in the content listing.
@ -75,6 +76,63 @@ class ContentTranslationOperationsTest extends NodeTestBase {
$this->drupalLogin($this->baseUser2);
$this->drupalGet('admin/content');
$this->assertLinkByHref('node/' . $node->id() . '/translations');
// Ensure that an unintended misconfiguration of permissions does not open
// access to the translation form, see https://www.drupal.org/node/2558905.
$this->drupalLogout();
user_role_change_permissions(
Role::AUTHENTICATED_ID,
[
'create content translations' => TRUE,
'access content' => FALSE,
]
);
$this->drupalLogin($this->baseUser1);
$this->drupalGet($node->urlInfo('drupal:content-translation-overview'));
$this->assertResponse(403);
// Ensure that the translation overview is also not accessible when the user
// has 'access content', but the node is not published.
user_role_change_permissions(
Role::AUTHENTICATED_ID,
[
'create content translations' => TRUE,
'access content' => TRUE,
]
);
$node->setPublished(FALSE)->save();
$this->drupalGet($node->urlInfo('drupal:content-translation-overview'));
$this->assertResponse(403);
}
/**
* @see content_translation_translate_access()
*/
public function testContentTranslationOverviewAccess() {
$access_control_handler = \Drupal::entityManager()->getAccessControlHandler('node');
$user = $this->createUser(['create content translations', 'access content']);
$this->drupalLogin($user);
$node = $this->drupalCreateNode(['status' => FALSE, 'type' => 'article']);
$this->assertFalse(content_translation_translate_access($node)->isAllowed());
$access_control_handler->resetCache();
$node->setPublished(TRUE);
$node->save();
$this->assertTrue(content_translation_translate_access($node)->isAllowed());
$access_control_handler->resetCache();
user_role_change_permissions(
Role::AUTHENTICATED_ID,
[
'access content' => FALSE,
]
);
$user = $this->createUser(['create content translations']);
$this->drupalLogin($user);
$this->assertFalse(content_translation_translate_access($node)->isAllowed());
$access_control_handler->resetCache();
}
}

View file

@ -37,6 +37,14 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
*/
protected $testLanguageSelector = TRUE;
/**
* Flag that tells whether the HTML escaping of all languages works or not
* after SafeMarkup change.
*
* @var bool
*/
protected $testHTMLEscapeForAllLanguages = FALSE;
/**
* Default cache contexts expected on a non-translated entity.
*
@ -44,7 +52,7 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
*
* @var string[]
*/
protected $defaultCacheContexts = ['languages:language_interface', 'theme', 'user.permissions'];
protected $defaultCacheContexts = ['languages:language_interface', 'theme', 'url.query_args:_wrapper_format', 'user.permissions'];
/**
* Tests the basic translation UI.
@ -105,6 +113,13 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
], array('language' => $language));
$this->drupalPostForm($add_url, $this->getEditValues($values, $langcode), $this->getFormSubmitActionForNewTranslation($entity, $langcode));
// Assert that HTML is escaped in "all languages" in UI after SafeMarkup
// change.
if ($this->testHTMLEscapeForAllLanguages) {
$this->assertNoRaw('&lt;span class=&quot;translation-entity-all-languages&quot;&gt;(all languages)&lt;/span&gt;');
$this->assertRaw('<span class="translation-entity-all-languages">(all languages)</span>');
}
// Ensure that the content language cache context is not yet added to the
// page.
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);

View file

@ -38,6 +38,16 @@ class ContentTranslationWorkflowsTest extends ContentTranslationTestBase {
$this->setupEntity();
}
/**
* {@inheritdoc}
*/
protected function getTranslatorPermissions() {
$permissions = parent::getTranslatorPermissions();
$permissions[] = 'view test entity';
return $permissions;
}
/**
* Overrides \Drupal\content_translation\Tests\ContentTranslationTestBase::getEditorPermissions().
*/
@ -109,7 +119,7 @@ class ContentTranslationWorkflowsTest extends ContentTranslationTestBase {
$ops = array('create' => t('Add'), 'update' => t('Edit'), 'delete' => t('Delete'));
$translations_url = $this->entity->urlInfo('drupal:content-translation-overview');
foreach ($ops as $current_op => $item) {
$user = $this->drupalCreateUser(array($this->getTranslatePermission(), "$current_op content translations"));
$user = $this->drupalCreateUser(array($this->getTranslatePermission(), "$current_op content translations", 'view test entity'));
$this->drupalLogin($user);
$this->drupalGet($translations_url);

View file

@ -54,6 +54,15 @@ class TranslationLinkTest extends ContentTranslationTestBase {
ViewTestData::createTestViews(get_class($this), array('content_translation_test_views'));
}
/**
* {@inheritdoc}
*/
protected function getTranslatorPermissions() {
$permissions = parent::getTranslatorPermissions();
$permissions[] = 'access user profiles';
return $permissions;
}
/**
* Tests the content translation overview link field handler.
*/

View file

@ -10,6 +10,7 @@ namespace Drupal\Tests\content_translation\Unit\Access;
use Drupal\content_translation\Access\ContentTranslationManageAccessCheck;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Language\Language;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\Routing\Route;
@ -96,6 +97,12 @@ class ContentTranslationManageAccessCheckTest extends UnitTestCase {
->method('getTranslationLanguages')
->with()
->will($this->returnValue(array()));
$entity->expects($this->once())
->method('getCacheContexts')
->willReturn([]);
$entity->expects($this->once())
->method('getCacheMaxAge')
->willReturn(Cache::PERMANENT);
$entity->expects($this->once())
->method('getCacheTags')
->will($this->returnValue(array('node:1337')));