You are here

public function CustomFilter::updateRule in Custom filter 2.0.x

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

Update a existing rule.

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

Parameters

array $rule: An array with a rule.

Return value

$this

File

src/Entity/CustomFilter.php, line 307

Class

CustomFilter
Defines the entity 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 = [
    '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;
  return $this;
}