Skip to content
Snippets Groups Projects
Commit c4ea981a authored by Kristof De Jaeger's avatar Kristof De Jaeger
Browse files

Merge branch '2761767-' into '8.x-3.x'

Fix prefix and suffix tokens

See merge request !44
parents 63816a99 b8e79a48
No related branches found
No related tags found
No related merge requests found
Pipeline #437249 passed with warnings
...@@ -11,6 +11,7 @@ use Drupal\Core\Cache\CacheableMetadata; ...@@ -11,6 +11,7 @@ use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Entity\Display\EntityDisplayInterface; use Drupal\Core\Entity\Display\EntityDisplayInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FormatterInterface; use Drupal\Core\Field\FormatterInterface;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
...@@ -1200,7 +1201,7 @@ function template_preprocess_field__ds_field_expert(&$variables) { ...@@ -1200,7 +1201,7 @@ function template_preprocess_field__ds_field_expert(&$variables) {
if (!empty($variables['settings'][$key . '-at'])) { if (!empty($variables['settings'][$key . '-at'])) {
$attributes = explode(' ', $variables['settings'][$key . '-at']); $attributes = explode(' ', $variables['settings'][$key . '-at']);
foreach ($attributes as $key => $attribute) { foreach ($attributes as $key => $attribute) {
if (strpos($attribute, '=') !== FALSE) { if (str_contains($attribute, '=')) {
$attribute_parts = explode('=', $attribute, 2); $attribute_parts = explode('=', $attribute, 2);
$var_attributes[$attribute_parts[0]] = trim($attribute_parts[1], '\"'); $var_attributes[$attribute_parts[0]] = trim($attribute_parts[1], '\"');
} }
......
...@@ -239,22 +239,21 @@ class Expert extends DsFieldTemplateBase { ...@@ -239,22 +239,21 @@ class Expert extends DsFieldTemplateBase {
$field_settings[$wrapper_key . '-cl'] = !(empty($values[$wrapper_key . '-cl'])) ? $values[$wrapper_key . '-cl'] : ''; $field_settings[$wrapper_key . '-cl'] = !(empty($values[$wrapper_key . '-cl'])) ? $values[$wrapper_key . '-cl'] : '';
// Default Classes. // Default Classes.
if (in_array($wrapper_key, ['ow', 'lb'])) { if (in_array($wrapper_key, ['ow', 'lb'])) {
$field_settings[$wrapper_key . '-def-cl'] = !(empty($values[$wrapper_key . '-def-cl'])) ? TRUE : FALSE; $field_settings[$wrapper_key . '-def-cl'] = !(empty($values[$wrapper_key . '-def-cl']));
} }
// Attributes. // Attributes.
$field_settings[$wrapper_key . '-at'] = !(empty($values[$wrapper_key . '-at'])) ? $values[$wrapper_key . '-at'] : ''; $field_settings[$wrapper_key . '-at'] = !(empty($values[$wrapper_key . '-at'])) ? $values[$wrapper_key . '-at'] : '';
// Default attributes. // Default attributes.
$field_settings[$wrapper_key . '-def-at'] = !(empty($values[$wrapper_key . '-def-at'])) ? TRUE : FALSE; $field_settings[$wrapper_key . '-def-at'] = !(empty($values[$wrapper_key . '-def-at']));
// Token replacement.
// Token replacement for the wrappers.
/* @var \Drupal\Core\Entity\EntityInterface $entity */ /* @var \Drupal\Core\Entity\EntityInterface $entity */
if ($entity = $this->getEntity()) { if ($entity = $this->getEntity()) {
// Tokens. // Tokens.
$apply_to = [ $apply_to = [
'prefix',
$wrapper_key . '-el', $wrapper_key . '-el',
$wrapper_key . '-cl', $wrapper_key . '-cl',
$wrapper_key . '-at', $wrapper_key . '-at',
'suffix',
]; ];
foreach ($apply_to as $identifier) { foreach ($apply_to as $identifier) {
...@@ -264,7 +263,9 @@ class Expert extends DsFieldTemplateBase { ...@@ -264,7 +263,9 @@ class Expert extends DsFieldTemplateBase {
[$entity->getEntityTypeId() => $entity], [$entity->getEntityTypeId() => $entity],
[ [
'clear' => TRUE, 'clear' => TRUE,
'langcode' => \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId() 'langcode' => \Drupal::languageManager()
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId()
] ]
); );
} }
...@@ -272,6 +273,29 @@ class Expert extends DsFieldTemplateBase { ...@@ -272,6 +273,29 @@ class Expert extends DsFieldTemplateBase {
} }
} }
} }
// Token replacement for the prefix and suffix.
/* @var \Drupal\Core\Entity\EntityInterface $entity */
if ($entity = $this->getEntity()) {
$apply_to = [
'prefix',
'suffix',
];
foreach ($apply_to as $identifier) {
if (!empty($field_settings[$identifier])) {
$field_settings[$identifier] = \Drupal::token()->replace(
$field_settings[$identifier],
[$entity->getEntityTypeId() => $entity],
[
'clear' => TRUE,
'langcode' => \Drupal::languageManager()
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId()
]
);
}
}
}
} }
} }
...@@ -12,7 +12,7 @@ use Drupal\Core\Url; ...@@ -12,7 +12,7 @@ use Drupal\Core\Url;
* on the pipeline, no idea why. So this file is currently located in this * on the pipeline, no idea why. So this file is currently located in this
* directory and only runs locally from time to time. * directory and only runs locally from time to time.
* *
* @group ds * @group ds_single
*/ */
class FieldTemplateTest extends TestBase { class FieldTemplateTest extends TestBase {
...@@ -649,7 +649,6 @@ class FieldTemplateTest extends TestBase { ...@@ -649,7 +649,6 @@ class FieldTemplateTest extends TestBase {
$edit = [ $edit = [
'fields[body][settings_edit_form][third_party_settings][ds][ft][id]' => 'expert', 'fields[body][settings_edit_form][third_party_settings][ds][ft][id]' => 'expert',
'fields[body][settings_edit_form][third_party_settings][ds][ft][settings][fi]' => '1',
]; ];
$this->dsEditFormatterSettings($edit); $this->dsEditFormatterSettings($edit);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment