protected function RulesConditionalElement::checkSiblings in Conditional Rules 7
Same name and namespace in other branches
- 8 includes/rules_conditional.core.inc \RulesConditionalElement::checkSiblings()
Checks basic conditional element integrity.
1 call to RulesConditionalElement::checkSiblings()
- RulesConditionalElement::integrityCheck in includes/
rules_conditional.core.inc - Makes sure the plugin is configured right.
File
- includes/
rules_conditional.core.inc, line 327 - Conditional Rules framework implementation.
Class
- RulesConditionalElement
- Base conditional element plugin implementation.
Code
protected function checkSiblings() {
// Check a default element is the last.
if ($this
->isDefault() && $this
->getNextSibling()) {
throw new RulesIntegrityException(t('The "%plugin" cannot precede another element.', array(
'%plugin' => $this
->plugin(),
)), $this);
}
$pluginInfo = $this
->pluginInfo();
// Check dependent element.
if (!empty($pluginInfo['conditional depends'])) {
if (!($previous = $this
->getPreviousSibling()) || !in_array($previous
->plugin(), $pluginInfo['conditional depends'])) {
$depends = $pluginInfo['conditional depends'];
$list = t('"%plugin"', array(
'%plugin' => array_shift($depends),
));
foreach ($depends as $depend) {
$list = t('!preceding, "%plugin"', array(
'!preceding' => $list,
'%plugin' => $depend,
));
}
throw new RulesIntegrityException(t('The "%plugin" must be preceded by one of: !list.', array(
'%plugin' => $this
->plugin(),
'!list' => $list,
)), $this);
}
}
// Check single element in a conditional container.
if (!$this
->isRoot() && $this
->parentElement() instanceof RulesConditionalContainer && !empty($pluginInfo['conditional single'])) {
$plugin = $this
->plugin();
$previous = $this
->getPreviousSibling();
$next = $this
->getNextSibling();
do {
if ($previous && $previous
->plugin() == $plugin || $next && $next
->plugin() == $plugin) {
throw new RulesIntegrityException(t('The "%plugin" cannot occur more than once within the enclosing container.', array(
'%plugin' => $this
->plugin(),
)), $this);
}
} while ($previous && ($previous = $previous
->getPreviousSibling()) || $next && ($next = $next
->getNextSibling()));
}
}