Issue #2023091 by djevans, badrange: Drupal does not allow W3C compliant language codes where you target a numeric region
parent
c9b8b83809
commit
7d01643eb6
|
@ -100,8 +100,11 @@ abstract class LanguageFormBase extends EntityForm {
|
|||
*/
|
||||
public function validateCommon(array $form, FormStateInterface $form_state) {
|
||||
// Ensure sane field values for langcode and name.
|
||||
if (!isset($form['langcode_view']) && preg_match('@[^a-zA-Z_-]@', $form_state->getValue('langcode'))) {
|
||||
$form_state->setErrorByName('langcode', $this->t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => $form['langcode']['#title'])));
|
||||
if (!isset($form['langcode_view']) && !preg_match('@^[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*$@', $form_state->getValue('langcode'))) {
|
||||
$form_state->setErrorByName('langcode', $this->t('%field must be a valid language tag as <a href="@url">defined by the W3C</a>.', array(
|
||||
'%field' => $form['langcode']['#title'],
|
||||
'@url' => 'http://www.w3.org/International/articles/language-tags/',
|
||||
)));
|
||||
}
|
||||
if ($form_state->getValue('label') != String::checkPlain($form_state->getValue('label'))) {
|
||||
$form_state->setErrorByName('label', $this->t('%field cannot contain any markup.', array('%field' => $form['label']['#title'])));
|
||||
|
|
|
@ -54,10 +54,30 @@ class LanguageCustomLanguageConfigurationTest extends WebTestBase {
|
|||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
$this->assertRaw(t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => t('Language code'))));
|
||||
|
||||
$this->assertRaw(t('%field must be a valid language tag as <a href="@url">defined by the W3C</a>.', array(
|
||||
'%field' => t('Language code'),
|
||||
'@url' => 'http://www.w3.org/International/articles/language-tags/',
|
||||
)));
|
||||
|
||||
$this->assertRaw(t('%field cannot contain any markup.', array('%field' => t('Language name in English'))));
|
||||
$this->assertUrl(\Drupal::url('language.add', array(), array('absolute' => TRUE)), [], 'Correct page redirection.');
|
||||
|
||||
// Test adding a custom language with a numeric region code.
|
||||
$edit = array(
|
||||
'predefined_langcode' => 'custom',
|
||||
'langcode' => 'es-419',
|
||||
'label' => 'Latin American Spanish',
|
||||
'direction' => LanguageInterface::DIRECTION_LTR,
|
||||
);
|
||||
|
||||
$this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
|
||||
$this->assertRaw(t(
|
||||
'The language %language has been created and can now be used.',
|
||||
array('%language' => $edit['label'])
|
||||
));
|
||||
$this->assertUrl(\Drupal::url('language.admin_overview', array(), array('absolute' => TRUE)), [], 'Correct page redirection.');
|
||||
|
||||
// Test validation of existing language values.
|
||||
$edit = array(
|
||||
'predefined_langcode' => 'custom',
|
||||
|
|
Loading…
Reference in New Issue