You are here

public function cf_dom::remove_elements in Common Functionality 7.2

Remove all elements of a given element type.

This preserves child elements. To remove elements entirely, use removeElement() directly.

Parameters

string $type: The new element type to use.

bool $on_body: If TRUE, operate on body element. If FALSE, operate on head element. This defaults to TRUE.

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 TRUE on success, FALSE otherwise.

File

modules/cf_dom/classes/cf_dom.php, line 463
Provides the cf_dom handling class.

Class

cf_dom
The cf_dom class assists in setting up and managing the custom dom object.

Code

public function remove_elements($type, $on_body = TRUE, $preserve_children = TRUE) {
  if (!is_bool($on_body)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_bool('on_body');
    }
    return FALSE;
  }
  if (cf_is_empty_or_non_string('type', $type)) {
    return FALSE;
  }
  if (!is_bool($preserve_children)) {
    if (class_exists('cf_error')) {
      cf_error::invalid_bool('preserve_children');
    }
    return FALSE;
  }
  if ($on_body) {
    if (!$this->body instanceof DOMNode) {
      if (class_exists('cf_error')) {
        cf_error::invalid_object('this->body');
      }
      return FALSE;
    }
    return $this
      ->p_remove_elements($type, $this->body, $preserve_children);
  }
  if (!$this->head instanceof DOMNode) {
    if (class_exists('cf_error')) {
      cf_error::invalid_object('this->head');
    }
    return FALSE;
  }
  return $this
    ->p_remove_elements($type, $this->head, $preserve_children);
}