private function removeLastNodeFromField($field_name) { if (!$this->data_definition->hasIdentifier($field_name)) { throw new e\NoSuchFieldException(S_SPAN . "The field name {$field_name} does not exist." . E_SPAN); } if (!$this->data_definition->isMultiple($field_name)) { throw new e\NodeException(S_SPAN . "The field {$field_name} is not multiple." . E_SPAN); } $first_node = $this->getNode($field_name . a\DataDefinition::DELIMITER . '0'); $par_id = $first_node->getParentId(); if ($par_id == '') { $last_pos = StructuredDataNode::getPositionOfLastNode($this->children, $field_name); $first_pos = StructuredDataNode::getPositionOfFirstNode($this->children, $field_name); $last_id = $this->children[$last_pos]->getIdentifier(); if ($first_pos == $last_pos) { throw new e\NodeException(S_SPAN . "Cannot remove the only node in the field." . E_SPAN); } $child_count = count($this->children); if ($child_count > $last_pos) { $before = array_slice($this->children, 0, $last_pos); $after = array_slice($this->children, $last_pos + 1); $this->children = array_merge($before, $after); } } else { $this->getNode($par_id)->removeLastChildNode($field_name); } if (isset($last_id) && isset($this->node_map[$last_id])) { unset($this->node_map[$last_id]); } $this->identifiers = array_keys($this->node_map); return $this; }