Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663
This commit is contained in:
parent
eb34d130a8
commit
f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions
|
@ -53,7 +53,7 @@ function hook_config_translation_info(&$info) {
|
|||
$info[$entity_type_id . '_fields'] = array(
|
||||
'base_route_name' => 'entity.field_config.' . $entity_type_id . '_field_edit_form',
|
||||
'entity_type' => 'field_config',
|
||||
'title' => t('!label field'),
|
||||
'title' => t('Title'),
|
||||
'class' => '\Drupal\config_translation\ConfigFieldMapper',
|
||||
'base_entity_type' => $entity_type_id,
|
||||
'weight' => 10,
|
||||
|
|
|
@ -19,15 +19,15 @@ function config_translation_help($route_name, RouteMatchInterface $route_match)
|
|||
case 'help.page.config_translation':
|
||||
$output = '';
|
||||
$output .= '<h3>' . t('About') . '</h3>';
|
||||
$output .= '<p>' . t('The Configuration Translation module allows you to translate configuration text; for example, the site name, vocabularies, menus, or date formats. Together with the modules <a href="!language">Language</a>, <a href="!content-translation">Content Translation</a>, and <a href="!locale">Interface Translation</a>, it allows you to build multilingual websites. For more information, see the <a href="!doc_url">online documentation for the Configuration Translation module</a>.', array('!doc_url' => 'https://www.drupal.org/documentation/modules/config_translation', '!config' => \Drupal::url('help.page', array('name' => 'config')), '!language' => \Drupal::url('help.page', array('name' => 'language')), '!locale' => \Drupal::url('help.page', array('name' => 'locale')), '!content-translation' => (\Drupal::moduleHandler()->moduleExists('content_translation')) ? \Drupal::url('help.page', array('name' => 'content_translation')) : '#')) . '</p>';
|
||||
$output .= '<p>' . t('The Configuration Translation module allows you to translate configuration text; for example, the site name, vocabularies, menus, or date formats. Together with the modules <a href=":language">Language</a>, <a href=":content-translation">Content Translation</a>, and <a href=":locale">Interface Translation</a>, it allows you to build multilingual websites. For more information, see the <a href=":doc_url">online documentation for the Configuration Translation module</a>.', array(':doc_url' => 'https://www.drupal.org/documentation/modules/config_translation', ':config' => \Drupal::url('help.page', array('name' => 'config')), ':language' => \Drupal::url('help.page', array('name' => 'language')), ':locale' => \Drupal::url('help.page', array('name' => 'locale')), ':content-translation' => (\Drupal::moduleHandler()->moduleExists('content_translation')) ? \Drupal::url('help.page', array('name' => 'content_translation')) : '#')) . '</p>';
|
||||
$output .= '<h3>' . t('Uses') . '</h3>';
|
||||
$output .= '<dl>';
|
||||
$output .= '<dt>' . t('Enabling translation') . '</dt>';
|
||||
$output .= '<dd>' . t('In order to translate configuration, the website must have at least two <a href="!url">languages</a>.', array('!url' => \Drupal::url('entity.configurable_language.collection'))) . '</dd>';
|
||||
$output .= '<dd>' . t('In order to translate configuration, the website must have at least two <a href=":url">languages</a>.', array(':url' => \Drupal::url('entity.configurable_language.collection'))) . '</dd>';
|
||||
$output .= '<dt>' . t('Translating configuration text') . '</dt>';
|
||||
$output .= '<dd>' . t('Users with the <em>Translate user edited configuration</em> permission can access the configuration translation overview, and manage translations for specific languages. The <a href="!translation-page">Configuration translation</a> page shows a list of all configuration text that can be translated, either as individual items or as lists. After you click on <em>Translate</em>, you are provided with a list of all languages. You can <em>add</em> or <em>edit</em> a translation for a specific language. Users with specific configuration permissions can also <em>edit</em> the text for the site\'s default language. For some configuration text items (for example for the site information), the specific translation pages can also be accessed directly from their configuration pages.', array('!translation-page' => \Drupal::url('config_translation.mapper_list'))) . '</dd>';
|
||||
$output .= '<dd>' . t('Users with the <em>Translate user edited configuration</em> permission can access the configuration translation overview, and manage translations for specific languages. The <a href=":translation-page">Configuration translation</a> page shows a list of all configuration text that can be translated, either as individual items or as lists. After you click on <em>Translate</em>, you are provided with a list of all languages. You can <em>add</em> or <em>edit</em> a translation for a specific language. Users with specific configuration permissions can also <em>edit</em> the text for the site\'s default language. For some configuration text items (for example for the site information), the specific translation pages can also be accessed directly from their configuration pages.', array(':translation-page' => \Drupal::url('config_translation.mapper_list'))) . '</dd>';
|
||||
$output .= '<dt>' . t('Translating date formats') . '</dt>';
|
||||
$output .= '<dd>' . t('You can choose to translate date formats on the <a href="!translation-page">Configuration translation</a> page. This allows you not only to translate the label text, but also to set a language-specific <em>PHP date format</em>.', array('!translation-page' => \Drupal::url('config_translation.mapper_list'))) . '</dd>';
|
||||
$output .= '<dd>' . t('You can choose to translate date formats on the <a href=":translation-page">Configuration translation</a> page. This allows you not only to translate the label text, but also to set a language-specific <em>PHP date format</em>.', array(':translation-page' => \Drupal::url('config_translation.mapper_list'))) . '</dd>';
|
||||
$output .= '</dl>';
|
||||
return $output;
|
||||
|
||||
|
@ -115,7 +115,6 @@ function config_translation_config_translation_info(&$info) {
|
|||
$info[$entity_type_id . '_fields'] = array(
|
||||
'base_route_name' => "entity.field_config.{$entity_type_id}_field_edit_form",
|
||||
'entity_type' => 'field_config',
|
||||
'title' => '!label field',
|
||||
'class' => '\Drupal\config_translation\ConfigFieldMapper',
|
||||
'base_entity_type' => $entity_type_id,
|
||||
'weight' => 10,
|
||||
|
@ -144,7 +143,7 @@ function config_translation_config_translation_info(&$info) {
|
|||
$info[$entity_type_id] = array(
|
||||
'class' => '\Drupal\config_translation\ConfigEntityMapper',
|
||||
'base_route_name' => $base_route_name,
|
||||
'title' => '!label !entity_type',
|
||||
'title' => $entity_type->getLowercaseLabel(),
|
||||
'names' => array(),
|
||||
'entity_type' => $entity_type_id,
|
||||
'weight' => 10,
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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'];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 [
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -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]');
|
||||
}
|
||||
|
||||
}
|
|
@ -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'.
|
||||
|
|
|
@ -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>');
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -15,10 +15,10 @@
|
|||
*/
|
||||
#}
|
||||
<div class="translation-set clearfix">
|
||||
<div class="layout-column half translation-set__source">
|
||||
<div class="layout-column layout-column--half translation-set__source">
|
||||
{{ element.source }}
|
||||
</div>
|
||||
<div class="layout-column half translation-set__translated">
|
||||
<div class="layout-column layout-column--half translation-set__translated">
|
||||
{{ element.translation }}
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -70,7 +70,7 @@ class ConfigEntityMapperTest extends UnitTestCase {
|
|||
$definition = array(
|
||||
'class' => '\Drupal\config_translation\ConfigEntityMapper',
|
||||
'base_route_name' => 'entity.configurable_language.edit_form',
|
||||
'title' => '!label language',
|
||||
'title' => '@label language',
|
||||
'names' => array(),
|
||||
'entity_type' => 'configurable_language',
|
||||
'route_name' => 'config_translation.item.overview.entity.configurable_language.edit_form',
|
||||
|
@ -99,9 +99,9 @@ class ConfigEntityMapperTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigEntityMapper::setEntity().
|
||||
* Tests ConfigEntityMapper::setEntity() and ConfigEntityMapper::getEntity().
|
||||
*/
|
||||
public function testSetEntity() {
|
||||
public function testEntityGetterAndSetter() {
|
||||
$this->entity
|
||||
->expects($this->once())
|
||||
->method('id')
|
||||
|
@ -119,9 +119,15 @@ class ConfigEntityMapperTest extends UnitTestCase {
|
|||
->with('configurable_language')
|
||||
->will($this->returnValue($entity_type));
|
||||
|
||||
// No entity is set.
|
||||
$this->assertNull($this->configEntityMapper->getEntity());
|
||||
|
||||
$result = $this->configEntityMapper->setEntity($this->entity);
|
||||
$this->assertTrue($result);
|
||||
|
||||
// Ensure that the getter provides the entity.
|
||||
$this->assertEquals($this->entity, $this->configEntityMapper->getEntity());
|
||||
|
||||
// Ensure that the configuration name was added to the mapper.
|
||||
$plugin_definition = $this->configEntityMapper->getPluginDefinition();
|
||||
$this->assertTrue(in_array('config_prefix.entity_id', $plugin_definition['names']));
|
||||
|
|
|
@ -50,7 +50,7 @@ class ConfigFieldMapperTest extends UnitTestCase {
|
|||
$definition = array(
|
||||
'class' => '\Drupal\config_translation\ConfigFieldMapper',
|
||||
'base_route_name' => 'entity.field_config.node_field_edit_form',
|
||||
'title' => '!label field',
|
||||
'title' => '@label field',
|
||||
'names' => array(),
|
||||
'entity_type' => 'field_config',
|
||||
);
|
||||
|
|
|
@ -11,6 +11,7 @@ use Drupal\config_translation\ConfigNamesMapper;
|
|||
use Drupal\Core\Config\ConfigFactoryInterface;
|
||||
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||||
use Drupal\Core\Language\Language;
|
||||
use Drupal\Core\Routing\RouteMatch;
|
||||
use Drupal\Core\Url;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
@ -140,7 +141,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
|
|||
*/
|
||||
public function testGetTitle() {
|
||||
$result = $this->configNamesMapper->getTitle();
|
||||
$this->assertSame($this->pluginDefinition['title'], $result);
|
||||
$this->assertSame($this->pluginDefinition['title'], (string) $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -239,9 +240,8 @@ class ConfigNamesMapperTest extends UnitTestCase {
|
|||
* Tests ConfigNamesMapper::getAddRouteParameters().
|
||||
*/
|
||||
public function testGetAddRouteParameters() {
|
||||
$request = Request::create('');
|
||||
$request->attributes->set('langcode', 'xx');
|
||||
$this->configNamesMapper->populateFromRequest($request);
|
||||
$route_match = new RouteMatch('example', new Route('/test/{langcode}'), ['langcode' => 'xx']);
|
||||
$this->configNamesMapper->populateFromRouteMatch($route_match);
|
||||
|
||||
$expected = array('langcode' => 'xx');
|
||||
$result = $this->configNamesMapper->getAddRouteParameters();
|
||||
|
@ -278,9 +278,8 @@ class ConfigNamesMapperTest extends UnitTestCase {
|
|||
* Tests ConfigNamesMapper::getEditRouteParameters().
|
||||
*/
|
||||
public function testGetEditRouteParameters() {
|
||||
$request = Request::create('');
|
||||
$request->attributes->set('langcode', 'xx');
|
||||
$this->configNamesMapper->populateFromRequest($request);
|
||||
$route_match = new RouteMatch('example', new Route('/test/{langcode}'), ['langcode' => 'xx']);
|
||||
$this->configNamesMapper->populateFromRouteMatch($route_match);
|
||||
|
||||
$expected = array('langcode' => 'xx');
|
||||
$result = $this->configNamesMapper->getEditRouteParameters();
|
||||
|
@ -317,9 +316,8 @@ class ConfigNamesMapperTest extends UnitTestCase {
|
|||
* Tests ConfigNamesMapper::getDeleteRouteParameters().
|
||||
*/
|
||||
public function testGetDeleteRouteParameters() {
|
||||
$request = Request::create('');
|
||||
$request->attributes->set('langcode', 'xx');
|
||||
$this->configNamesMapper->populateFromRequest($request);
|
||||
$route_match = new RouteMatch('example', new Route('/test/{langcode}'), ['langcode' => 'xx']);
|
||||
$this->configNamesMapper->populateFromRouteMatch($route_match);
|
||||
|
||||
$expected = array('langcode' => 'xx'); $result = $this->configNamesMapper->getDeleteRouteParameters();
|
||||
$this->assertSame($expected, $result);
|
||||
|
@ -370,25 +368,25 @@ class ConfigNamesMapperTest extends UnitTestCase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tests ConfigNamesMapper::populateFromRequest().
|
||||
* Tests ConfigNamesMapper::populateFromRouteMatch().
|
||||
*/
|
||||
public function testPopulateFromRequest() {
|
||||
public function testPopulateFromRouteMatch() {
|
||||
// Make sure the language code is not set initially.
|
||||
$this->assertSame(NULL, $this->configNamesMapper->getInternalLangcode());
|
||||
|
||||
// Test that an empty request does not set the language code.
|
||||
$request = Request::create('');
|
||||
$this->configNamesMapper->populateFromRequest($request);
|
||||
$route_match = new RouteMatch('example', new Route('/test/{langcode}'));
|
||||
$this->configNamesMapper->populateFromRouteMatch($route_match);
|
||||
$this->assertSame(NULL, $this->configNamesMapper->getInternalLangcode());
|
||||
|
||||
// Test that a request with a 'langcode' attribute sets the language code.
|
||||
$request->attributes->set('langcode', 'xx');
|
||||
$this->configNamesMapper->populateFromRequest($request);
|
||||
$route_match = new RouteMatch('example', new Route('/test/{langcode}'), ['langcode' => 'xx']);
|
||||
$this->configNamesMapper->populateFromRouteMatch($route_match);
|
||||
$this->assertSame('xx', $this->configNamesMapper->getInternalLangcode());
|
||||
|
||||
// Test that the language code gets unset with the wrong request.
|
||||
$request->attributes->remove('langcode');
|
||||
$this->configNamesMapper->populateFromRequest($request);
|
||||
$route_match = new RouteMatch('example', new Route('/test/{langcode}'));
|
||||
$this->configNamesMapper->populateFromRouteMatch($route_match);
|
||||
$this->assertSame(NULL, $this->configNamesMapper->getInternalLangcode());
|
||||
}
|
||||
|
||||
|
@ -397,7 +395,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
|
|||
*/
|
||||
public function testGetTypeLabel() {
|
||||
$result = $this->configNamesMapper->getTypeLabel();
|
||||
$this->assertSame($this->pluginDefinition['title'], $result);
|
||||
$this->assertSame($this->pluginDefinition['title'], (string) $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -540,7 +538,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
|
|||
|
||||
$map = array();
|
||||
foreach ($config_names as $i => $config_name) {
|
||||
$map[] = array($config_name, $mock_return_values[$i]);
|
||||
$map[] = isset($mock_return_values[$i]) ? array($config_name, $mock_return_values[$i]) : array();
|
||||
}
|
||||
$this->configMapperManager
|
||||
->expects($this->any())
|
||||
|
@ -562,10 +560,12 @@ class ConfigNamesMapperTest extends UnitTestCase {
|
|||
*/
|
||||
public function providerTestHasTranslatable() {
|
||||
return array(
|
||||
array(array(), FALSE),
|
||||
array(array(TRUE), TRUE),
|
||||
array(array(FALSE), FALSE),
|
||||
array(array(TRUE, TRUE, TRUE), TRUE),
|
||||
array(array(TRUE, FALSE, TRUE), FALSE),
|
||||
array(array(FALSE, FALSE, FALSE), FALSE),
|
||||
array(array(TRUE, FALSE, TRUE), TRUE),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -624,7 +624,7 @@ class ConfigNamesMapperTest extends UnitTestCase {
|
|||
*/
|
||||
public function testGetTypeName() {
|
||||
$result = $this->configNamesMapper->getTypeName();
|
||||
$this->assertSame('Settings', $result);
|
||||
$this->assertSame('Settings', (string) $result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue