public function insertElement(&$nodes, $element, &$optionals, $fn, $orig_context)
{
list($element, $attributes, $switch_context) = $this->handleOptionals($element, $optionals);
$new_nodes = [];
foreach ($nodes as $n) {
foreach ($element as $k => $v) {
$cx = $this->handleInsertion($n, $k, $v, $fn, $optionals);
$new_nodes = \array_merge($new_nodes, $cx);
}
}
$new_context = $this->newContext($new_nodes);
// Setting the attributes is an help that the addChild method
// offers to the user and is the same of:
// 1. appending a child switching the context
// 2. setting the attributes over the new context.
if (!empty($attributes)) {
$new_context->setAttribute($attributes);
}
return $switch_context ? $new_context : $orig_context;
}