Commit 6872eec3 authored by catch's avatar catch

Issue #2642674 by swentel, hussainweb: Tokens not replaced in file/widget field descriptions

parent 4f76cde4
......@@ -567,4 +567,14 @@ protected function isDefaultValueWidget(FormStateInterface $form_state) {
return (bool) $form_state->get('default_value_widget');
}
/**
* Returns the filtered field description.
*
* @return \Drupal\Core\Field\FieldFilteredMarkup
* The filtered field description, with tokens replaced.
*/
protected function getFilteredDescription() {
return FieldFilteredMarkup::create(\Drupal::token()->replace($this->fieldDefinition->getDescription()));
}
}
......@@ -119,7 +119,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f
}
$title = $this->fieldDefinition->getLabel();
$description = FieldFilteredMarkup::create($this->fieldDefinition->getDescription());
$description = $this->getFilteredDescription();
$elements = array();
......
......@@ -7,6 +7,7 @@
namespace Drupal\image\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
......@@ -98,7 +99,7 @@ protected function formMultipleElements(FieldItemListInterface $items, array &$f
if ($cardinality == 1) {
// If there's only one field, return it as delta 0.
if (empty($elements[0]['#default_value']['fids'])) {
$file_upload_help['#description'] = $this->fieldDefinition->getDescription();
$file_upload_help['#description'] = $this->getFilteredDescription();
$elements[0]['#description'] = \Drupal::service('renderer')->renderPlain($file_upload_help);
}
}
......
......@@ -70,8 +70,10 @@ protected function setUp() {
* Widget settings to be added to the widget defaults.
* @param array $formatter_settings
* Formatter settings to be added to the formatter defaults.
* @param string $description
* A description for the field.
*/
function createImageField($name, $type_name, $storage_settings = array(), $field_settings = array(), $widget_settings = array(), $formatter_settings = array()) {
function createImageField($name, $type_name, $storage_settings = array(), $field_settings = array(), $widget_settings = array(), $formatter_settings = array(), $description = '') {
FieldStorageConfig::create(array(
'field_name' => $name,
'entity_type' => 'node',
......@@ -87,6 +89,7 @@ function createImageField($name, $type_name, $storage_settings = array(), $field
'bundle' => $type_name,
'required' => !empty($field_settings['required']),
'settings' => $field_settings,
'description' => $description,
));
$field_config->save();
......
......@@ -27,9 +27,10 @@ public function testWidgetElement() {
'min_resolution' => $min_resolution . 'x' . $min_resolution,
'alt_field' => 0,
);
$this->createImageField($field_name, 'article', array(), $field_settings);
$this->createImageField($field_name, 'article', array(), $field_settings, array(), array(), 'Image test on [site:name]');
$this->drupalGet('node/add/article');
$this->assertNotEqual(0, count($this->xpath('//div[contains(@class, "field--widget-image-image")]')), 'Image field widget found on add/node page', 'Browser');
$this->assertNoText('Image test on [site:name]');
}
}
......
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