You are here

public function ConfigActionsPluginBase::setOptions in Config Actions 8

Process an Options array to set various internal variable defaults.

Parameters

array $options:

1 call to ConfigActionsPluginBase::setOptions()
ConfigActionsPluginBase::initPlugin in src/ConfigActionsPluginBase.php
Initialize a plugin.

File

src/ConfigActionsPluginBase.php, line 209

Class

ConfigActionsPluginBase
Base class for config_actions plugins.

Namespace

Drupal\config_actions

Code

public function setOptions(array $options) {
  $default_list = [];

  // Loop through $options to look for simple @var@ definitions that
  // belong in the $replace list.
  foreach ($options as $key => $value) {
    if (preg_match('/^\\@[A-Za-z0-9_\\-]+\\@$/', $key) === 1) {

      // Only set simple @var@ if not already defined in replacements.
      if (!isset($options['replace'][$key])) {
        $options['replace'][$key] = $value;
      }
      unset($options[$key]);
    }
  }

  // Load any supplied and allowed options into class properties.
  foreach ($this->allowedOptions as $key => $default) {
    if (array_key_exists($key, $options)) {
      $this->{$key} = $options[$key];
    }
    elseif (property_exists($this, $key) && is_null($this->{$key})) {
      $this->{$key} = $default;
      $default_list[] = $key;
    }
  }
  $parsed_options = $this
    ->parseOptions($options, [
    'source',
    'dest',
  ]);

  // Extract any variables from the key/id
  if (!empty($this->key)) {
    $this->replace = array_merge(ConfigActionsTransform::parseWildcards($this->key, $this->id), $this->replace);
  }
  if (!empty($this->replace_in)) {
    foreach ($this->replace_in as $option) {
      if (isset($parsed_options[$option])) {
        $this->{$option} = $this
          ->replaceData($parsed_options[$option], $this->replace, $option);
      }
    }
  }
  if (!isset($this->dest) && !is_array($this->source)) {
    $this->dest = $this->source;
    $this->dest_type = $this->source_type;
  }
}