joomla/joomla-cms — pull request #2708 by WooDzu (2013-12-21 12:55:08+00:00)
Title: [PR] Allow replacing xml form field's descendants

This PR addresses the issue of replacing XML for fields definitions which contain descendants like
nodes for list field.

Lets consider a content plugin with the following implementation:

```php
public function onContentPrepareForm($form, $data)
{
// The name of the form we want to process
$formName = 'com_config.application';

// The xml definition of our additions/replacements
$fileName = __DIR__.'/forms/'.$formName.'.xml';

// Only process com_config application forms and only process it if the override file exists
if ($form->getName() == $formName && is_file($fileName))
{
// Attempt to load the XML file as a simpleXml object
$gaeXml = simplexml_load_file($fileName);

// Replace XML nodes[aka Joomla Form fields] in this form with ones that have been defined in our replacement file
$form->load($gaeXml);
}
}
```

Basically, its intention is to add/replace elements from a form,
Joomla 'Global Configuration' form in this case

#### Extracted, original definition of a form field from com_config.application

```xml

COM_CONFIG_FIELD_VALUE_PHP_MAIL

COM_CONFIG_FIELD_VALUE_SENDMAIL

COM_CONFIG_FIELD_VALUE_SMTP

```

#### Field definition we want to set instead and also the expected result
(added 'gae' option and changed 'default' attribute)

```xml

COM_CONFIG_FIELD_VALUE_GAE_MAIL

COM_CONFIG_FIELD_VALUE_PHP_MAIL

COM_CONFIG_FIELD_VALUE_SENDMAIL

COM_CONFIG_FIELD_VALUE_SMTP

```

#### Actual result is as follows (the descendants options are not copied over):

```xml

```

I think, when replacing a form this way, all nodes should be copied.