`serializeBlock` does not return anything. Here you just appends $variables['prototype'] fields to the current $parentElement;
I guess that you'd need to pass a DOMElement not related to the current $parrentElement (create a new DOMDocument ?), and then get it's xml content to add it to the attributes