You are here

public function RulesPlugin::setParent in Rules 7.2

Sets a new parent element.

File

includes/rules.core.inc, line 488
Rules base classes and interfaces needed for any rule evaluation.

Class

RulesPlugin
Base class for rules plugins.

Code

public function setParent(RulesContainerPlugin $parent) {
  if ($this->parent == $parent) {
    return;
  }
  if (isset($this->parent) && ($key = array_search($this, $this->parent->children)) !== FALSE) {

    // Remove element from any previous parent.
    unset($this->parent->children[$key]);
    $this->parent
      ->resetInternalCache();
  }

  // Make sure the interface matches the type of the container.
  if ($parent instanceof RulesActionContainer && $this instanceof RulesActionInterface || $parent instanceof RulesConditionContainer && $this instanceof RulesConditionInterface) {
    $this->parent = $parent;
    $parent->children[] = $this;
    $this->parent
      ->resetInternalCache();
  }
  else {
    throw new RulesEvaluationException('The given container is incompatible with this element.', array(), $this, RulesLog::ERROR);
  }
}