private function cf_dom::p_remove_element in Common Functionality 7.2
Removes the given element from its parent.
This preserves child elements. To remove entirely, use removeElement() directly.
Parameters
DOMNode $element: The object to convert to markup text.
bool $preserve_children: (optional) If TRUE, children are re-attached to the parent node to preserved their location in the markup. If FALSE, the children remain attached to the removed element.
Return value
bool The removed element on success, FALSE otherwise.
2 calls to cf_dom::p_remove_element()
- cf_dom::p_remove_elements in modules/
cf_dom/ classes/ cf_dom.php - Remove all elements of a given element type.
- cf_dom::remove_element in modules/
cf_dom/ classes/ cf_dom.php - Removes the given element from its parent.
File
- modules/
cf_dom/ classes/ cf_dom.php, line 633 - Provides the cf_dom handling class.
Class
- cf_dom
- The cf_dom class assists in setting up and managing the custom dom object.
Code
private function p_remove_element($element, $preserve_children = TRUE) {
$parent = $element->parentNode;
if (!$parent instanceof DOMNode) {
return FALSE;
}
if ($preserve_children && $element
->hasChildNodes()) {
$children = array();
foreach ($element->childNodes as $child) {
$children[] = $child;
}
foreach ($children as $child) {
$removed_child = $element
->removeChild($child);
if (is_object($removed_child)) {
$parent
->insertBefore($removed_child, $element);
}
}
}
$child = $parent
->removeChild($element);
if ($child instanceof DOMNode) {
return $child;
}
return FALSE;
}