You are here

public function TokenSettingTypeBase::settingsPreprocess in UI Patterns Settings 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/TokenSettingTypeBase.php \Drupal\ui_patterns_settings\Plugin\TokenSettingTypeBase::settingsPreprocess()

Preprocess setting variable.

Parameters

string $value: The stored value.

array $context: Context informations. Keys:

  • entity.

\Drupal\ui_patterns_settings\Definition\PatternDefinitionSetting $def: The pattern definition.

Return value

string The processed value.

Overrides PatternSettingTypeBase::settingsPreprocess

1 call to TokenSettingTypeBase::settingsPreprocess()
UrlSettingType::settingsPreprocess in src/Plugin/UiPatterns/SettingType/UrlSettingType.php
Preprocess setting variable.
1 method overrides TokenSettingTypeBase::settingsPreprocess()
UrlSettingType::settingsPreprocess in src/Plugin/UiPatterns/SettingType/UrlSettingType.php
Preprocess setting variable.

File

src/Plugin/TokenSettingTypeBase.php, line 72

Class

TokenSettingTypeBase

Namespace

Drupal\ui_patterns_settings\Plugin

Code

public function settingsPreprocess($value, array $context, PatternDefinitionSetting $def) {
  $return_value = '';
  if (isset($value['input'])) {
    $value = $value['input'];
  }
  if (is_string($value)) {
    $token_data = [];

    /** @var \Drupal\Core\Entity\EntityInterface $entity */
    $entity = isset($context['entity']) ? $context['entity'] : NULL;
    if ($entity !== NULL) {
      $token_data[$entity
        ->getEntityTypeId()] = $entity;
    }
    $return_value = $this
      ->getTokenService()
      ->replace($value, $token_data, [
      'clear' => TRUE,
    ]);
  }
  return $return_value;
}