You are here

protected function ConfigActionsPluginBase::replaceData in Config Actions 8

Perform string replacement on the $data and return the result.

@result mixed

Parameters

mixed $data:

array $replacements: If specified, overrides the stored replacement string list

string $in: Name of "replace_in" option to restrict replacements

3 calls to ConfigActionsPluginBase::replaceData()
ConfigActionsPluginBase::execute in src/ConfigActionsPluginBase.php
Execute the action for this plugin.
ConfigActionsPluginBase::parseOptions in src/ConfigActionsPluginBase.php
Parse any property references in the options.
ConfigActionsPluginBase::setOptions in src/ConfigActionsPluginBase.php
Process an Options array to set various internal variable defaults.

File

src/ConfigActionsPluginBase.php, line 340

Class

ConfigActionsPluginBase
Base class for config_actions plugins.

Namespace

Drupal\config_actions

Code

protected function replaceData($data, $replacements = NULL, $in = '') {
  $replacements = isset($replacements) ? $replacements : (!empty($this->replace) ? $this->replace : []);
  $replace = [];
  $replace_keys = [];
  foreach ($replacements as $pattern => $value) {
    if (is_array($value)) {
      $replace_in = isset($value['in']) ? $value['in'] : $this->replace_in;
      $pattern = isset($value['pattern']) ? $value['pattern'] : $pattern;
      if (empty($in) || in_array($in, $replace_in)) {
        $with = isset($value['with']) ? $value['with'] : '';
        $type = isset($value['type']) ? $value['type'] : 'value';
        if (is_string($type)) {
          $type = explode(',', $type);
        }
        if (in_array('key', $type)) {
          $replace_keys[$pattern] = $with;
        }
        if (in_array('value', $type)) {
          $replace[$pattern] = $with;
        }
      }
    }
    else {
      $replace[$pattern] = $value;
      $replace_keys[$pattern] = $value;
    }
  }
  return ConfigActionsTransform::replace($data, $replace, $replace_keys);
}