Commit cead42ce authored by xjm's avatar xjm

Issue #2569289 by lauriii, dawehner, stefan.r: Replace remaining !placeholder...

Issue #2569289 by lauriii, dawehner, stefan.r: Replace remaining !placeholder for Non-URL HTML outputs only in #title in file widgets
parent 1a4fb654
......@@ -372,19 +372,25 @@ public static function validateManagedFile(&$element, FormStateInterface $form_s
if ($file->isPermanent()) {
$references = static::fileUsage()->listUsage($file);
if (empty($references)) {
$form_state->setError($element, t('The file used in the !name field may not be referenced.', ['!name' => $element['#title']]));
// We expect the field name placeholder value to be wrapped in t()
// here, so it won't be escaped again as it's already marked safe.
$form_state->setError($element, t('The file used in the @name field may not be referenced.', ['@name' => $element['#title']]));
}
}
}
else {
$form_state->setError($element, t('The file referenced by the !name field does not exist.', ['!name' => $element['#title']]));
// We expect the field name placeholder value to be wrapped in t()
// here, so it won't be escaped again as it's already marked safe.
$form_state->setError($element, t('The file referenced by the @name field does not exist.', ['@name' => $element['#title']]));
}
}
}
// Check required property based on the FID.
if ($element['#required'] && empty($element['fids']['#value']) && !in_array($clicked_button, ['upload_button', 'remove_button'])) {
$form_state->setError($element, t('!name is required.', ['!name' => $element['#title']]));
// We expect the field name placeholder value to be wrapped in t()
// here, so it won't be escaped again as it's already marked safe.
$form_state->setError($element, t('@name is required.', ['@name' => $element['#title']]));
}
// Consolidate the array value of this field to array of FIDs.
......
......@@ -154,4 +154,26 @@ function testManagedFile() {
$this->assertNoFieldByXpath('//input[@name="nested[file][file_' . $fid_list[0] . '][selected]"]', NULL, 'An individual file can be deleted from a multiple file element.');
$this->assertFieldByXpath('//input[@name="nested[file][file_' . $fid_list[1] . '][selected]"]', NULL, 'Second individual file not deleted when the first file is deleted from a multiple file element.');
}
/**
* Ensure that warning is shown if file on the field has been removed.
*/
public function testManagedFileRemoved() {
$this->drupalGet('file/test/1/0/1');
$test_file = $this->getTestFile('text');
$file_field_name = 'files[nested_file][]';
$edit = [$file_field_name => drupal_realpath($test_file->getFileUri())];
$this->drupalPostForm(NULL, $edit, t('Upload'));
$fid = $this->getLastFileId();
$file = \Drupal::entityManager()->getStorage('file')->load($fid);
$file->delete();
$this->drupalPostForm(NULL, $edit, t('Upload'));
// We expect the title 'Managed <em>file & butter</em>' which got escaped
// via a t() call before.
$this->assertRaw('The file referenced by the Managed <em>file &amp; butter</em> field does not exist.');
}
}
......@@ -43,7 +43,7 @@ public function buildForm(array $form, FormStateInterface $form_state, $tree = T
$form['nested']['file'] = array(
'#type' => 'managed_file',
'#title' => $this->t('Managed file'),
'#title' => $this->t('Managed <em>@type</em>', ['@type' => 'file & butter']),
'#upload_location' => 'public://test',
'#progress_message' => $this->t('Please wait...'),
'#extended' => (bool) $extended,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment