Exemplo n.º 1
0
 public function repeat($value, $element, $rule)
 {
     foreach ($value as $iteration) {
         $clone = $element->cloneNode(true);
         $this->data->bind($clone, $iteration);
         $element->parentNode->insertBefore($clone, $element);
         //Re-run the hook on the new element, but use the iterated data
         $newRules = $rule->getRules();
         //Don't run repeat on the clones element or it will loop forever
         unset($newRules['repeat']);
         $hook = new Rule($newRules, $rule->getPseudoMatcher(), $this->data);
         foreach ($rule->getProperties() as $obj) {
             $hook->registerProperties($obj);
         }
         $hook->run($clone);
     }
     //Remove the original element so only the ones that have been looped over will show
     $element->parentNode->removeChild($element);
     return false;
 }
Exemplo n.º 2
0
 public function repeat($value, $element, $rule)
 {
     if ($element->getAttribute('transphporm') === 'added') {
         return $element->parentNode->removeChild($element);
     }
     foreach ($value as $key => $iteration) {
         $clone = $element->cloneNode(true);
         //Mark this node as having been added by transphporm
         $clone->setAttribute('transphporm', 'added');
         $this->data->bind($clone, $iteration, 'iteration');
         $this->data->bind($clone, $key, 'key');
         $element->parentNode->insertBefore($clone, $element);
         //Re-run the hook on the new element, but use the iterated data
         $newRules = $rule->getRules();
         //Don't run repeat on the clones element or it will loop forever
         unset($newRules['repeat']);
         $hook = new Rule($newRules, $rule->getPseudoMatcher(), $this->data);
         foreach ($rule->getProperties() as $obj) {
             $hook->registerProperties($obj);
         }
         $hook->run($clone);
     }
     //Flag the original element for removal
     $element->setAttribute('transphporm', 'remove');
     return false;
 }