You are here

public function Filter::parse in Access Filter 8

Parses YAML serialized properties.

Overrides FilterInterface::parse

File

src/Entity/Filter.php, line 134

Class

Filter
Defines the Filter entity.

Namespace

Drupal\access_filter\Entity

Code

public function parse() {

  /* @var \Drupal\access_filter\Plugin\AccessFilterPluginManager $condition_plugin_manager */
  $condition_plugin_manager = \Drupal::service('plugin.manager.access_filter.condition');
  $condition_plugins = $condition_plugin_manager
    ->getDefinitions();
  $parsed_conditions = $this
    ->parseYaml($this->conditions);
  $this->parsedConditions = [];
  foreach ($parsed_conditions as $condition) {
    $plugin_id = $condition['type'];
    if (isset($condition_plugins[$plugin_id])) {
      $this->parsedConditions[] = $condition_plugin_manager
        ->createInstance($plugin_id, $condition);
    }
  }

  /* @var \Drupal\access_filter\Plugin\AccessFilterPluginManager $rule_plugin_manager */
  $rule_plugin_manager = \Drupal::service('plugin.manager.access_filter.rule');
  $rule_plugins = $rule_plugin_manager
    ->getDefinitions();
  $parsed_rules = $this
    ->parseYaml($this->rules);
  $this->parsedRules = [];
  foreach ($parsed_rules as $rule) {
    $plugin_id = $rule['type'];
    if (isset($rule_plugins[$plugin_id])) {
      $this->parsedRules[] = $rule_plugin_manager
        ->createInstance($plugin_id, $rule);
    }
  }
  $this->parsedResponse = $this
    ->parseYaml($this->response) + [
    'code' => 403,
    'redirect_url' => NULL,
    'body' => NULL,
  ];
}