Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542

This commit is contained in:
Pantheon Automation 2015-08-27 12:03:05 -07:00 committed by Greg Anderson
parent 3b2511d96d
commit 81ccda77eb
2155 changed files with 54307 additions and 46870 deletions

View file

@ -13,6 +13,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\TranslationWrapper;
/**
* Implements hook_help().
@ -251,8 +252,8 @@ function content_translation_views_data_alter(array &$data) {
*/
function content_translation_menu_links_discovered_alter(array &$links) {
// Clarify where translation settings are located.
$links['language.content_settings_page']['title'] = 'Content language and translation';
$links['language.content_settings_page']['description'] = 'Configure language and translation support for content.';
$links['language.content_settings_page']['title'] = new TranslationWrapper('Content language and translation');
$links['language.content_settings_page']['description'] = new TranslationWrapper('Configure language and translation support for content.');
}
/**
@ -466,7 +467,6 @@ function content_translation_language_configuration_element_process(array $eleme
// default to no translatability.
'#default_value' => $context['bundle'] ? \Drupal::service('content_translation.manager')->isEnabled($context['entity_type'], $context['bundle']) : FALSE,
'#element_validate' => array('content_translation_language_configuration_element_validate'),
'#prefix' => '<label>' . t('Translation') . '</label>',
);
$submit_name = isset($form['actions']['save_continue']) ? 'save_continue' : 'submit';

View file

@ -473,9 +473,7 @@ class ContentTranslationHandler implements ContentTranslationHandlerInterface, E
$form['#entity_builders'][] = array($this, 'entityFormEntityBuild');
// Handle entity validation.
if (isset($form['actions']['submit'])) {
$form['actions']['submit']['#validate'][] = array($this, 'entityFormValidate');
}
$form['#validate'][] = array($this, 'entityFormValidate');
// Handle entity deletion.
if (isset($form['actions']['delete'])) {

View file

@ -8,6 +8,7 @@
namespace Drupal\content_translation\Controller;
use Drupal\content_translation\ContentTranslationManagerInterface;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Language\LanguageInterface;
@ -92,6 +93,10 @@ class ContentTranslationController extends ControllerBase {
$manager = $this->manager;
$entity_type = $entity->getEntityType();
// Start collecting the cacheability metadata, starting with the entity and
// later merge in the access result cacheability metadata.
$cacheability = CacheableMetadata::createFromObject($entity);
$languages = $this->languageManager()->getLanguages();
$original = $entity->getUntranslated()->language()->getId();
$translations = $entity->getTranslationLanguages();
@ -180,11 +185,16 @@ class ContentTranslationController extends ControllerBase {
// If the user is allowed to edit the entity we point the edit link to
// the entity form, otherwise if we are not dealing with the original
// language we point the link to the translation form.
if ($entity->access('update') && $entity_type->hasLinkTemplate('edit-form')) {
$update_access = $entity->access('update', NULL, TRUE);
$translation_access = $handler->getTranslationAccess($entity, 'update');
$cacheability = $cacheability
->merge(CacheableMetadata::createFromObject($update_access))
->merge(CacheableMetadata::createFromObject($translation_access));
if ($update_access->isAllowed() && $entity_type->hasLinkTemplate('edit-form')) {
$links['edit']['url'] = $entity->urlInfo('edit-form');
$links['edit']['language'] = $language;
}
elseif (!$is_original && $handler->getTranslationAccess($entity, 'update')->isAllowed()) {
elseif (!$is_original && $translation_access->isAllowed()) {
$links['edit']['url'] = $edit_url;
}
@ -206,6 +216,11 @@ class ContentTranslationController extends ControllerBase {
}
else {
$source_name = isset($languages[$source]) ? $languages[$source]->getName() : $this->t('n/a');
$delete_access = $entity->access('delete', NULL, TRUE);
$translation_access = $handler->getTranslationAccess($entity, 'delete');
$cacheability = $cacheability
->merge(CacheableMetadata::createFromObject($delete_access))
->merge(CacheableMetadata::createFromObject($translation_access));
if ($entity->access('delete') && $entity_type->hasLinkTemplate('delete-form')) {
$links['delete'] = array(
'title' => $this->t('Delete'),
@ -213,7 +228,7 @@ class ContentTranslationController extends ControllerBase {
'language' => $language,
);
}
elseif ($handler->getTranslationAccess($entity, 'delete')->isAllowed()) {
elseif ($translation_access->isAllowed()) {
$links['delete'] = array(
'title' => $this->t('Delete'),
'url' => $delete_url,
@ -226,7 +241,10 @@ class ContentTranslationController extends ControllerBase {
$row_title = $source_name = $this->t('n/a');
$source = $entity->language()->getId();
if ($source != $langcode && $handler->getTranslationAccess($entity, 'create')->isAllowed()) {
$create_translation_access = $handler->getTranslationAccess($entity, 'create');
$cacheability = $cacheability
->merge(CacheableMetadata::createFromObject($create_translation_access));
if ($source != $langcode && $create_translation_access->isAllowed()) {
if ($translatable) {
$links['add'] = array(
'title' => $this->t('Add'),
@ -284,6 +302,9 @@ class ContentTranslationController extends ControllerBase {
// Add metadata to the build render array to let other modules know about
// which entity this is.
$build['#entity'] = $entity;
$cacheability
->addCacheTags($entity->getCacheTags())
->applyTo($build);
$build['content_translation_overview'] = array(
'#theme' => 'table',

View file

@ -231,7 +231,7 @@ class ContentTranslationSettingsTest extends WebTestBase {
* @param array $edit
* An array of values to submit to the content translation settings page.
*
* @return boolean
* @return bool
* TRUE if the assertion succeeded, FALSE otherwise.
*/
protected function assertSettings($entity_type, $bundle, $enabled, $edit) {

View file

@ -7,18 +7,22 @@
namespace Drupal\content_translation\Tests;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Url;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\system\Tests\Cache\AssertPageCacheContextsAndTagsTrait;
/**
* Tests the Content Translation UI.
*/
abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
use AssertPageCacheContextsAndTagsTrait;
/**
* The id of the entity being translated.
*
@ -33,6 +37,15 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
*/
protected $testLanguageSelector = TRUE;
/**
* Default cache contexts expected on a non-translated entity.
*
* Cache contexts will not be checked if this list is empty.
*
* @var string[]
*/
protected $defaultCacheContexts = ['languages:language_interface', 'theme', 'user.permissions'];
/**
* Tests the basic translation UI.
*/
@ -64,6 +77,11 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
$this->assertTrue($entity, 'Entity found in the database.');
$this->drupalGet($entity->urlInfo());
$this->assertResponse(200, 'Entity URL is valid.');
// Ensure that the content language cache context is not yet added to the
// page.
$this->assertCacheContexts($this->defaultCacheContexts);
$this->drupalGet($entity->urlInfo('drupal:content-translation-overview'));
$this->assertNoText('Source language', 'Source language column correctly hidden.');
@ -87,9 +105,14 @@ abstract class ContentTranslationUITestBase extends ContentTranslationTestBase {
], array('language' => $language));
$this->drupalPostForm($add_url, $this->getEditValues($values, $langcode), $this->getFormSubmitActionForNewTranslation($entity, $langcode));
// Get the entity and reset its cache, so that the new translation gets the
// updated values.
// Ensure that the content language cache context is not yet added to the
// page.
$entity = entity_load($this->entityTypeId, $this->entityId, TRUE);
$this->drupalGet($entity->urlInfo());
$this->assertCacheContexts(Cache::mergeContexts(['languages:language_content'], $this->defaultCacheContexts));
// Reset the cache of the entity, so that the new translation gets the
// updated values.
$metadata_source_translation = $this->manager->getTranslationMetadata($entity->getTranslation($default_langcode));
$metadata_target_translation = $this->manager->getTranslationMetadata($entity->getTranslation($langcode));

View file

@ -113,6 +113,13 @@ class ContentTranslationWorkflowsTest extends ContentTranslationTestBase {
$this->drupalLogin($user);
$this->drupalGet($translations_url);
// Make sure that the user.permissions cache context and the cache tags
// for the entity are present.
$this->assertCacheContext('user.permissions');
foreach ($this->entity->getCacheTags() as $cache_tag) {
$this->assertCacheTag($cache_tag);
}
foreach ($ops as $op => $label) {
if ($op != $current_op) {
$this->assertNoLink($label, format_string('No %op link found.', array('%op' => $label)));

View file

@ -9,6 +9,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\Language\Language;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\Routing\Route;
@ -22,6 +23,28 @@ use Symfony\Component\Routing\Route;
*/
class ContentTranslationManageAccessCheckTest extends UnitTestCase {
/**
* The cache contexts manager.
*
* @var \Drupal\Core\Cache\Context\CacheContextsManager|\PHPUnit_Framework_MockObject_MockObject
*/
protected $cacheContextsManager;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->cacheContextsManager = $this->getMockBuilder('Drupal\Core\Cache\Context\CacheContextsManager')
->disableOriginalConstructor()
->getMock();
$container = new ContainerBuilder();
$container->set('cache_contexts_manager', $this->cacheContextsManager);
\Drupal::setContainer($container);
}
/**
* Tests the create access method.
*
@ -76,6 +99,9 @@ class ContentTranslationManageAccessCheckTest extends UnitTestCase {
$entity->expects($this->once())
->method('getCacheTags')
->will($this->returnValue(array('node:1337')));
$entity->expects($this->once())
->method('getCacheContexts')
->willReturn(array());
// Set the route requirements.
$route = new Route('test_route');