You are here

public function CustomFilter::updateRule in Custom filter 8

Same name and namespace in other branches
  1. 2.0.x src/Entity/CustomFilter.php \Drupal\customfilter\Entity\CustomFilter::updateRule()

Update a existing rule.

@todo trown an exception when the rule do not exist.

Parameters

array $rule: An array with a rule.

File

src/Entity/CustomFilter.php, line 285

Class

CustomFilter
Defines the entify for a filter in customfilter.

Namespace

Drupal\customfilter\Entity

Code

public function updateRule(array $rule) {

  // If the rule is not complete, use the previous values of the rule.
  $previous = $this->rules[$rule['rid']];
  $property = array(
    'prid',
    'fid',
    'name',
    'description',
    'enabled',
    'matches',
    'pattern',
    'replacement',
    'code',
    'weight',
  );
  foreach ($property as $p) {
    if (!isset($rule[$p])) {
      $rule[$p] = $previous[$p];
    }
  }
  $this->rules[$rule['rid']] = $rule;
}