Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -8,8 +8,8 @@
namespace Drupal\config_translation\Access;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\Routing\Route;
/**
* Checks access for displaying the translation add, edit, and delete forms.
@ -19,10 +19,10 @@ class ConfigTranslationFormAccess extends ConfigTranslationOverviewAccess {
/**
* {@inheritdoc}
*/
public function access(Route $route, AccountInterface $account, $langcode = NULL) {
public function access(RouteMatchInterface $route_match, AccountInterface $account, $langcode = NULL) {
// For the translation forms we have a target language, so we need some
// checks in addition to the checks performed for the translation overview.
$base_access = parent::access($route, $account);
$base_access = parent::access($route_match, $account);
if ($base_access->isAllowed()) {
$target_language = $this->languageManager->getLanguage($langcode);

View file

@ -11,8 +11,8 @@ use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\config_translation\ConfigMapperManagerInterface;
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Routing\Access\AccessInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Symfony\Component\Routing\Route;
/**
* Checks access for displaying the configuration translation overview.
@ -54,17 +54,20 @@ class ConfigTranslationOverviewAccess implements AccessInterface {
/**
* Checks access to the overview based on permissions and translatability.
*
* @param \Symfony\Component\Routing\Route $route
* The route to check against.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route_match to check against.
* @param \Drupal\Core\Session\AccountInterface $account
* The currently logged in account.
*
* @return \Drupal\Core\Access\AccessResultInterface
* The access result.
*/
public function access(Route $route, AccountInterface $account) {
public function access(RouteMatchInterface $route_match, AccountInterface $account) {
$route = $route_match->getRouteObject();
/** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
$mapper = $this->configMapperManager->createInstance($route->getDefault('plugin_id'));
$mapper->populateFromRouteMatch($route_match);
$this->sourceLanguage = $this->languageManager->getLanguage($mapper->getLangcode());
// Allow access to the translation overview if the proper permission is

View file

@ -13,12 +13,12 @@ use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Url;
use Drupal\locale\LocaleConfigManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
/**
@ -110,13 +110,23 @@ class ConfigEntityMapper extends ConfigNamesMapper {
/**
* {@inheritdoc}
*/
public function populateFromRequest(Request $request) {
parent::populateFromRequest($request);
$entity = $request->attributes->get($this->entityType);
public function populateFromRouteMatch(RouteMatchInterface $route_match) {
parent::populateFromRouteMatch($route_match);
$entity = $route_match->getParameter($this->entityType);
$this->setEntity($entity);
}
/**
* Gets the entity instance for this mapper.
*
* @return \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
* The configuration entity.
*/
public function getEntity() {
return $this->entity;
}
/**
* Sets the entity instance for this mapper.
*
* This method can only be invoked when the concrete entity is known, that is
@ -154,11 +164,7 @@ class ConfigEntityMapper extends ConfigNamesMapper {
* {@inheritdoc}
*/
public function getTitle() {
// Title based on the entity label. Should be translated for display in the
// current page language. The title placeholder is later escaped for
// display.
$entity_type_info = $this->entityManager->getDefinition($this->entityType);
return $this->t($this->pluginDefinition['title'], array('!label' => $this->entity->label(), '!entity_type' => $entity_type_info->getLowercaseLabel()));
return $this->entity->label() . ' ' . $this->pluginDefinition['title'];
}
/**

View file

@ -8,6 +8,7 @@
namespace Drupal\config_translation;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouteCollection;
@ -204,6 +205,16 @@ interface ConfigMapperInterface {
*/
public function getLangcode();
/**
* Sets the original language code.
*
* @param string $langcode
* The langcode.
*
* @return $this
*/
public function setLangcode($langcode);
/**
* Returns the name of the type of data the mapper encapsulates.
*
@ -242,11 +253,11 @@ interface ConfigMapperInterface {
public function hasSchema();
/**
* Checks that all pieces of this configuration mapper have translatables.
* Checks if pieces of this configuration mapper have translatables.
*
* @return bool
* TRUE if all of the configuration elements have translatables, FALSE
* otherwise.
* TRUE if at least one of the configuration elements has translatables,
* FALSE otherwise.
*/
public function hasTranslatable();
@ -267,10 +278,10 @@ interface ConfigMapperInterface {
*
* @todo Replace $request with RouteMatch https://www.drupal.org/node/2295255.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* Page request object.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
*/
public function populateFromRequest(Request $request);
public function populateFromRouteMatch(RouteMatchInterface $route_match);
/**
* Returns the name of the contextual link group to add contextual links to.

View file

@ -13,13 +13,13 @@ use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\TranslationInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Url;
use Drupal\locale\LocaleConfigManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
@ -371,13 +371,8 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
/**
* {@inheritdoc}
*/
public function populateFromRequest(Request $request) {
if ($request->attributes->has('langcode')) {
$this->langcode = $request->attributes->get('langcode');
}
else {
$this->langcode = NULL;
}
public function populateFromRouteMatch(RouteMatchInterface $route_match) {
$this->langcode = $route_match->getParameter('langcode');
}
/**
@ -407,6 +402,14 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
return reset($langcodes);
}
/**
* {@inheritdoc}
*/
public function setLangcode($langcode) {
$this->langcode = $langcode;
return $this;
}
/**
* {@inheritdoc}
*/
@ -435,11 +438,11 @@ class ConfigNamesMapper extends PluginBase implements ConfigMapperInterface, Con
*/
public function hasTranslatable() {
foreach ($this->getConfigNames() as $name) {
if (!$this->configMapperManager->hasTranslatable($name)) {
return FALSE;
if ($this->configMapperManager->hasTranslatable($name)) {
return TRUE;
}
}
return TRUE;
return FALSE;
}
/**

View file

@ -13,6 +13,7 @@ use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Language\Language;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
@ -122,14 +123,14 @@ class ConfigTranslationController extends ControllerBase {
public function itemPage(Request $request, RouteMatchInterface $route_match, $plugin_id) {
/** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
$mapper = $this->configMapperManager->createInstance($plugin_id);
$mapper->populateFromRequest($request);
$mapper->populateFromRouteMatch($route_match);
$page = array();
$page['#title'] = $this->t('Translations for %label', array('%label' => $mapper->getTitle()));
$languages = $this->languageManager->getLanguages();
if (count($languages) == 1) {
drupal_set_message($this->t('In order to translate configuration, the website must have at least two <a href="@url">languages</a>.', array('@url' => $this->url('entity.configurable_language.collection'))), 'warning');
drupal_set_message($this->t('In order to translate configuration, the website must have at least two <a href=":url">languages</a>.', array(':url' => $this->url('entity.configurable_language.collection'))), 'warning');
}
$original_langcode = $mapper->getLangcode();
if (!isset($languages[$original_langcode])) {
@ -140,7 +141,7 @@ class ConfigTranslationController extends ControllerBase {
}
// We create a fake request object to pass into
// ConfigMapperInterface::populateFromRequest() for the different languages.
// ConfigMapperInterface::populateFromRouteMatch() for the different languages.
// Creating a separate request for each language and route is neither easily
// possible nor performant.
$fake_request = $request->duplicate();
@ -155,8 +156,9 @@ class ConfigTranslationController extends ControllerBase {
// This is needed because
// ConfigMapperInterface::getAddRouteParameters(), for example,
// needs to return the correct language code for each table row.
$fake_request->attributes->set('langcode', $langcode);
$mapper->populateFromRequest($fake_request);
$fake_route_match = RouteMatch::createFromRequest($fake_request);
$mapper->populateFromRouteMatch($fake_route_match);
$mapper->setLangcode($langcode);
// Prepare the language name and the operations depending on whether this
// is the original language or not.

View file

@ -8,7 +8,7 @@
namespace Drupal\config_translation\Form;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Defines a form for adding configuration translations.
@ -25,8 +25,8 @@ class ConfigTranslationAddForm extends ConfigTranslationFormBase {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL, $plugin_id = NULL, $langcode = NULL) {
$form = parent::buildForm($form, $form_state, $request, $plugin_id, $langcode);
public function buildForm(array $form, FormStateInterface $form_state, RouteMatchInterface $route_match = NULL, $plugin_id = NULL, $langcode = NULL) {
$form = parent::buildForm($form, $form_state, $route_match, $plugin_id, $langcode);
$form['#title'] = $this->t('Add @language translation for %label', array(
'%label' => $this->mapper->getTitle(),
'@language' => $this->language->getName(),

View file

@ -12,6 +12,7 @@ use Drupal\Core\Cache\Cache;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -116,10 +117,10 @@ class ConfigTranslationDeleteForm extends ConfirmFormBase {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL, $plugin_id = NULL, $langcode = NULL) {
public function buildForm(array $form, FormStateInterface $form_state, RouteMatchInterface $route_match = NULL, $plugin_id = NULL, $langcode = NULL) {
/** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
$mapper = $this->configMapperManager->createInstance($plugin_id);
$mapper->populateFromRequest($request);
$mapper->populateFromRouteMatch($route_match);
$language = $this->languageManager->getLanguage($langcode);
if (!$language) {

View file

@ -8,7 +8,7 @@
namespace Drupal\config_translation\Form;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Defines a form for editing configuration translations.
@ -25,8 +25,8 @@ class ConfigTranslationEditForm extends ConfigTranslationFormBase {
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL, $plugin_id = NULL, $langcode = NULL) {
$form = parent::buildForm($form, $form_state, $request, $plugin_id, $langcode);
public function buildForm(array $form, FormStateInterface $form_state, RouteMatchInterface $route_match = NULL, $plugin_id = NULL, $langcode = NULL) {
$form = parent::buildForm($form, $form_state, $route_match, $plugin_id, $langcode);
$form['#title'] = $this->t('Edit @language translation for %label', array(
'%label' => $this->mapper->getTitle(),
'@language' => $this->language->getName(),

View file

@ -9,6 +9,7 @@ namespace Drupal\config_translation\Form;
use Drupal\config_translation\ConfigMapperManagerInterface;
use Drupal\Core\Config\TypedConfigManagerInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\TypedData\TypedDataInterface;
use Drupal\Core\TypedData\TraversableTypedDataInterface;
use Drupal\Core\Form\BaseFormIdInterface;
@ -16,7 +17,6 @@ use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\language\ConfigurableLanguageManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
/**
@ -132,10 +132,10 @@ abstract class ConfigTranslationFormBase extends FormBase implements BaseFormIdI
* Throws an exception if the language code provided as a query parameter in
* the request does not match an active language.
*/
public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL, $plugin_id = NULL, $langcode = NULL) {
public function buildForm(array $form, FormStateInterface $form_state, RouteMatchInterface $route_match = NULL, $plugin_id = NULL, $langcode = NULL) {
/** @var \Drupal\config_translation\ConfigMapperInterface $mapper */
$mapper = $this->configMapperManager->createInstance($plugin_id);
$mapper->populateFromRequest($request);
$mapper->populateFromRouteMatch($route_match);
$language = $this->languageManager->getLanguage($langcode);
if (!$language) {

View file

@ -18,9 +18,9 @@ class DateFormat extends FormElementBase {
* {@inheritdoc}
*/
public function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
/** @var \Drupal\Core\Datetime\DateFormatter $date_formatter */
/** @var \Drupal\Core\Datetime\DateFormatterInterface $date_formatter */
$date_formatter = \Drupal::service('date.formatter');
$description = $this->t('A user-defined date format. See the <a href="@url">PHP manual</a> for available options.', array('@url' => 'http://php.net/manual/function.date.php'));
$description = $this->t('A user-defined date format. See the <a href=":url">PHP manual</a> for available options.', array(':url' => 'http://php.net/manual/function.date.php'));
$format = $this->t('Displayed as %date_format', array('%date_format' => $date_formatter->format(REQUEST_TIME, 'custom', $translation_config)));
return [

View file

@ -100,9 +100,9 @@ abstract class FormElementBase implements ElementInterface {
return array(
'#type' => 'item',
'#title' => $this->t('!label <span class="visually-hidden">(!source_language)</span>', array(
'!label' => $this->t($this->definition->getLabel()),
'!source_language' => $source_language->getName(),
'#title' => $this->t('@label <span class="visually-hidden">(@source_language)</span>', array(
'@label' => $this->definition->getLabel(),
'@source_language' => $source_language->getName(),
)),
'#markup' => $value,
);
@ -162,9 +162,9 @@ abstract class FormElementBase implements ElementInterface {
protected function getTranslationElement(LanguageInterface $translation_language, $source_config, $translation_config) {
// Add basic properties that apply to all form elements.
return array(
'#title' => $this->t('!label <span class="visually-hidden">(!source_language)</span>', array(
'!label' => $this->t($this->definition['label']),
'!source_language' => $translation_language->getName(),
'#title' => $this->t('@label <span class="visually-hidden">(@source_language)</span>', array(
'@label' => $this->definition['label'],
'@source_language' => $translation_language->getName(),
)),
'#default_value' => $translation_config,
'#attributes' => array('lang' => $translation_language->getId()),

View file

@ -0,0 +1,63 @@
<?php
/**
* @file
* Contains \Drupal\config_translation\Tests\ConfigTranslationDateFormatUiTest.
*/
namespace Drupal\config_translation\Tests;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
/**
* Tests the content translation behaviours on date formats.
*
* @group config_translation
*/
class ConfigTranslationDateFormatUiTest extends WebTestBase {
public static $modules = array(
'language',
'config_translation',
'system'
);
protected function setUp() {
parent::setUp();
// Enable additional languages.
$langcodes = ['de', 'es'];
foreach ($langcodes as $langcode) {
ConfigurableLanguage::createFromLangcode($langcode)->save();
}
$user = $this->drupalCreateUser(array(
'administer site configuration',
'translate configuration',
));
$this->drupalLogin($user);
}
/**
* Tests date format translation behaviour.
*/
public function testDateFormatUI() {
$this->drupalGet('admin/config/regional/date-time');
// Assert translation link unlocked date format.
$this->assertLinkByHref('admin/config/regional/date-time/formats/manage/medium/translate');
// Assert translation link locked date format.
$this->assertLinkByHref('admin/config/regional/date-time/formats/manage/html_datetime/translate');
// Date pattern is visible on unlocked date formats.
$this->drupalGet('admin/config/regional/date-time/formats/manage/medium/translate/de/add');
$this->assertField('translation[config_names][core.date_format.medium][pattern]');
// Date pattern is not visible on locked date formats.
$this->drupalGet('admin/config/regional/date-time/formats/manage/html_datetime/translate/es/add');
$this->assertNoField('translation[config_names][core.date_format.html_datetime][pattern]');
}
}

View file

@ -55,8 +55,8 @@ class ConfigTranslationFormTest extends WebTestBase {
*/
public function testConfigTranslationFormAlter() {
$form_builder = \Drupal::formBuilder();
$add_form = $form_builder->getForm('Drupal\config_translation\Form\ConfigTranslationAddForm', \Drupal::request(), $this->pluginId, $this->langcode);
$edit_form = $form_builder->getForm('Drupal\config_translation\Form\ConfigTranslationEditForm', \Drupal::request(), $this->pluginId, $this->langcode);
$add_form = $form_builder->getForm('Drupal\config_translation\Form\ConfigTranslationAddForm', \Drupal::routeMatch(), $this->pluginId, $this->langcode);
$edit_form = $form_builder->getForm('Drupal\config_translation\Form\ConfigTranslationEditForm', \Drupal::routeMatch(), $this->pluginId, $this->langcode);
// Test that hook_form_BASE_FORM_ID_alter() was called for the base form ID
// 'config_translation_form'.

View file

@ -7,6 +7,7 @@
namespace Drupal\config_translation\Tests;
use Drupal\Component\Utility\Html;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\simpletest\WebTestBase;
@ -68,6 +69,7 @@ class ConfigTranslationOverviewTest extends WebTestBase {
}
$this->localeStorage = $this->container->get('locale.storage');
$this->drupalPlaceBlock('local_tasks_block');
$this->drupalPlaceBlock('page_title_block');
}
/**
@ -116,8 +118,8 @@ class ConfigTranslationOverviewTest extends WebTestBase {
$entity_type = \Drupal::entityManager()->getDefinition($test_entity->getEntityTypeId());
$this->drupalGet($base_url . '/translate');
$title = t('!label !entity_type', array('!label' => $test_entity->label(), '!entity_type' => $entity_type->getLowercaseLabel()));
$title = t('Translations for %label', array('%label' => $title));
$title = $test_entity->label() . ' ' . $entity_type->getLowercaseLabel();
$title = 'Translations for <em class="placeholder">' . Html::escape($title) . '</em>';
$this->assertRaw($title);
$this->assertRaw('<th>' . t('Language') . '</th>');

View file

@ -119,6 +119,7 @@ class ConfigTranslationUiTest extends WebTestBase {
}
$this->localeStorage = $this->container->get('locale.storage');
$this->drupalPlaceBlock('local_tasks_block');
$this->drupalPlaceBlock('page_title_block');
}
/**
@ -176,6 +177,9 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->assertFieldByName('translation[config_names][system.site][name]', $fr_site_name);
$this->assertFieldByName('translation[config_names][system.site][slogan]', $fr_site_slogan);
// Place branding block with site name and slogan into header region.
$this->drupalPlaceBlock('system_branding_block', ['region' => 'header']);
// Check French translation of site name and slogan are in place.
$this->drupalGet('fr');
$this->assertRaw($fr_site_name);
@ -367,7 +371,7 @@ class ConfigTranslationUiTest extends WebTestBase {
// Test that delete links work and operations perform properly.
foreach ($this->langcodes as $langcode) {
$replacements = array('%label' => t('!label !entity_type', array('!label' => $label, '!entity_type' => Unicode::strtolower(t('Contact form')))), '@language' => \Drupal::languageManager()->getLanguage($langcode)->getName());
$replacements = array('%label' => t('@label @entity_type', array('@label' => $label, '@entity_type' => Unicode::strtolower(t('Contact form')))), '@language' => \Drupal::languageManager()->getLanguage($langcode)->getName());
$this->drupalGet("$translation_base_url/$langcode/delete");
$this->assertRaw(t('Are you sure you want to delete the @language translation of %label?', $replacements));
@ -400,34 +404,6 @@ class ConfigTranslationUiTest extends WebTestBase {
$this->assertLinkByHref("$translation_base_url/fr/add");
}
/**
* Tests the node type translation.
*/
public function testNodeTypeTranslation() {
$type = Unicode::strtolower($this->randomMachineName(16));
$name = $this->randomString();
$this->drupalLogin($this->adminUser);
$this->drupalCreateContentType(array('type' => $type, 'name' => $name));
// Translate the node type name.
$langcode = $this->langcodes[0];
$translated_name = $langcode . '-' . $name;
$edit = array(
"translation[config_names][node.type.$type][name]" => $translated_name,
);
$this->drupalPostForm("admin/structure/types/manage/$type/translate/$langcode/add", $edit, t('Save translation'));
// Check the name is translated without admin theme for editing.
$this->drupalPostForm('admin/appearance', array('use_admin_theme' => '0'), t('Save configuration'));
$this->drupalGet("$langcode/node/add/$type");
$this->assertRaw(t('Create @name', array('@name' => $translated_name)));
// Check the name is translated with admin theme for editing.
$this->drupalPostForm('admin/appearance', array('use_admin_theme' => '1'), t('Save configuration'));
$this->drupalGet("$langcode/node/add/$type");
$this->assertRaw(t('Create @name', array('@name' => $translated_name)));
}
/**
* Tests date format translation.
*/
@ -656,7 +632,7 @@ class ConfigTranslationUiTest extends WebTestBase {
$config->save();
// Go to the translation page of the 'files' view.
$translation_url = 'admin/structure/views/view/files/translate/' . $langcode . '/add';
$translation_url = 'admin/structure/views/view/files/translate/en/add';
$this->drupalGet($translation_url);
// Check if the expected number of source elements are present.