User tests: Successful: Unsuccessful:
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:
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
<field
name="mailer"
type="list"
default="mail"
label="COM_CONFIG_FIELD_MAIL_MAILER_LABEL"
description="COM_CONFIG_FIELD_MAIL_MAILER_DESC"
required="true"
filter="word">
<option value="mail">COM_CONFIG_FIELD_VALUE_PHP_MAIL</option>
<option value="sendmail">COM_CONFIG_FIELD_VALUE_SENDMAIL</option>
<option value="smtp">COM_CONFIG_FIELD_VALUE_SMTP</option>
</field>
(added 'gae' option and changed 'default' attribute)
<field
name="mailer"
type="list"
default="gae"
label="COM_CONFIG_FIELD_MAIL_MAILER_LABEL"
description="COM_CONFIG_FIELD_MAIL_MAILER_DESC"
required="true"
filter="word">
<option value="gae">COM_CONFIG_FIELD_VALUE_GAE_MAIL</option>
<option value="mail">COM_CONFIG_FIELD_VALUE_PHP_MAIL</option>
<option value="sendmail">COM_CONFIG_FIELD_VALUE_SENDMAIL</option>
<option value="smtp">COM_CONFIG_FIELD_VALUE_SMTP</option>
</field>
<field
name="mailer"
type="list"
default="gae"
label="COM_CONFIG_FIELD_MAIL_MAILER_LABEL"
description="COM_CONFIG_FIELD_MAIL_MAILER_DESC"
required="true"
filter="word">
</field>
I think, when replacing a form this way, all nodes should be copied.
The nice tracker url: http://issues.joomla.org/tracker/joomla-cms/2708
The ugly tracker url: http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33028
Description | <p>This PR addresses the issue of replacing XML for fields definitions which contain descendants like nodes for list field.</p> <p>Lets consider a content plugin with the following implementation:</p> <div class="highlight highlight-php"><pre><span class="k">public</span> <span class="k">function</span> <span class="nf">onContentPrepareForm</span><span class="p">(</span><span class="nv">$form</span><span class="p">,</span> <span class="nv">$data</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// The name of the form we want to process</span> <span class="nv">$formName</span> <span class="o">=</span> <span class="s1">'com_config.application'</span><span class="p">;</span> <span class="c1">// The xml definition of our additions/replacements</span> <span class="nv">$fileName</span> <span class="o">=</span> <span class="nx">__DIR__</span><span class="o">.</span><span class="s1">'/forms/'</span><span class="o">.</span><span class="nv">$formName</span><span class="o">.</span><span class="s1">'.xml'</span><span class="p">;</span> <span class="c1">// Only process com_config application forms and only process it if the override file exists</span> <span class="k">if</span> <span class="p">(</span><span class="nv">$form</span><span class="o">-></span><span class="na">getName</span><span class="p">()</span> <span class="o">==</span> <span class="nv">$formName</span> <span class="o">&&</span> <span class="nb">is_file</span><span class="p">(</span><span class="nv">$fileName</span><span class="p">))</span> <span class="p">{</span> <span class="c1">// Attempt to load the XML file as a simpleXml object</span> <span class="nv">$gaeXml</span> <span class="o">=</span> <span class="nb">simplexml_load_file</span><span class="p">(</span><span class="nv">$fileName</span><span class="p">);</span> <span class="c1">// Replace XML nodes[aka Joomla Form fields] in this form with ones that have been defined in our replacement file</span> <span class="nv">$form</span><span class="o">-></span><span class="na">load</span><span class="p">(</span><span class="nv">$gaeXml</span><span class="p">);</span> <span class="p">}</span> <span class="p">}</span> </pre></div> <p>Basically, its intention is to add/replace elements from a form,<br> Joomla 'Global Configuration' form in this case</p> <h4>Extracted, original definition of a form field from com_config.application</h4> <div class="highlight highlight-xml"><pre><span class="nt"><field</span> <span class="na">name=</span><span class="s">"mailer"</span> <span class="na">type=</span><span class="s">"list"</span> <span class="na">default=</span><span class="s">"mail"</span> <span class="na">label=</span><span class="s">"COM_CONFIG_FIELD_MAIL_MAILER_LABEL"</span> <span class="na">description=</span><span class="s">"COM_CONFIG_FIELD_MAIL_MAILER_DESC"</span> <span class="na">required=</span><span class="s">"true"</span> <span class="na">filter=</span><span class="s">"word"</span><span class="nt">></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"mail"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_PHP_MAIL<span class="nt"></option></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"sendmail"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_SENDMAIL<span class="nt"></option></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"smtp"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_SMTP<span class="nt"></option></span> <span class="nt"></field></span> </pre></div> <h4>Field definition we want to set instead and also the expected result</h4> <p>(added 'gae' option and changed 'default' attribute)</p> <div class="highlight highlight-xml"><pre><span class="nt"><field</span> <span class="na">name=</span><span class="s">"mailer"</span> <span class="na">type=</span><span class="s">"list"</span> <span class="na">default=</span><span class="s">"gae"</span> <span class="na">label=</span><span class="s">"COM_CONFIG_FIELD_MAIL_MAILER_LABEL"</span> <span class="na">description=</span><span class="s">"COM_CONFIG_FIELD_MAIL_MAILER_DESC"</span> <span class="na">required=</span><span class="s">"true"</span> <span class="na">filter=</span><span class="s">"word"</span><span class="nt">></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"gae"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_GAE_MAIL<span class="nt"></option></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"mail"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_PHP_MAIL<span class="nt"></option></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"sendmail"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_SENDMAIL<span class="nt"></option></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"smtp"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_SMTP<span class="nt"></option></span> <span class="nt"></field></span> </pre></div> <h4>Actual result is as follows (the descendants options are not copied over):</h4> <div class="highlight highlight-xml"><pre><span class="nt"><field</span> <span class="na">name=</span><span class="s">"mailer"</span> <span class="na">type=</span><span class="s">"list"</span> <span class="na">default=</span><span class="s">"gae"</span> <span class="na">label=</span><span class="s">"COM_CONFIG_FIELD_MAIL_MAILER_LABEL"</span> <span class="na">description=</span><span class="s">"COM_CONFIG_FIELD_MAIL_MAILER_DESC"</span> <span class="na">required=</span><span class="s">"true"</span> <span class="na">filter=</span><span class="s">"word"</span><span class="nt">></span> <span class="nt"></field></span> </pre></div> <p>I think, when replacing a form this way, all nodes should be copied.</p> | ⇒ | <p>This PR addresses the issue of replacing XML for fields definitions which contain descendants like nodes for list field.</p> <p>Lets consider a content plugin with the following implementation:</p> <div class="highlight highlight-php"><pre><span class="k">public</span> <span class="k">function</span> <span class="nf">onContentPrepareForm</span><span class="p">(</span><span class="nv">$form</span><span class="p">,</span> <span class="nv">$data</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// The name of the form we want to process</span> <span class="nv">$formName</span> <span class="o">=</span> <span class="s1">'com_config.application'</span><span class="p">;</span> <span class="c1">// The xml definition of our additions/replacements</span> <span class="nv">$fileName</span> <span class="o">=</span> <span class="nx">__DIR__</span><span class="o">.</span><span class="s1">'/forms/'</span><span class="o">.</span><span class="nv">$formName</span><span class="o">.</span><span class="s1">'.xml'</span><span class="p">;</span> <span class="c1">// Only process com_config application forms and only process it if the override file exists</span> <span class="k">if</span> <span class="p">(</span><span class="nv">$form</span><span class="o">-></span><span class="na">getName</span><span class="p">()</span> <span class="o">==</span> <span class="nv">$formName</span> <span class="o">&&</span> <span class="nb">is_file</span><span class="p">(</span><span class="nv">$fileName</span><span class="p">))</span> <span class="p">{</span> <span class="c1">// Attempt to load the XML file as a simpleXml object</span> <span class="nv">$gaeXml</span> <span class="o">=</span> <span class="nb">simplexml_load_file</span><span class="p">(</span><span class="nv">$fileName</span><span class="p">);</span> <span class="c1">// Replace XML nodes[aka Joomla Form fields] in this form with ones that have been defined in our replacement file</span> <span class="nv">$form</span><span class="o">-></span><span class="na">load</span><span class="p">(</span><span class="nv">$gaeXml</span><span class="p">);</span> <span class="p">}</span> <span class="p">}</span> </pre></div> <p>Basically, its intention is to add/replace elements from a form,<br> Joomla 'Global Configuration' form in this case</p> <h4>Extracted, original definition of a form field from com_config.application</h4> <div class="highlight highlight-xml"><pre><span class="nt"><field</span> <span class="na">name=</span><span class="s">"mailer"</span> <span class="na">type=</span><span class="s">"list"</span> <span class="na">default=</span><span class="s">"mail"</span> <span class="na">label=</span><span class="s">"COM_CONFIG_FIELD_MAIL_MAILER_LABEL"</span> <span class="na">description=</span><span class="s">"COM_CONFIG_FIELD_MAIL_MAILER_DESC"</span> <span class="na">required=</span><span class="s">"true"</span> <span class="na">filter=</span><span class="s">"word"</span><span class="nt">></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"mail"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_PHP_MAIL<span class="nt"></option></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"sendmail"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_SENDMAIL<span class="nt"></option></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"smtp"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_SMTP<span class="nt"></option></span> <span class="nt"></field></span> </pre></div> <h4>Field definition we want to set instead and also the expected result</h4> <p>(added 'gae' option and changed 'default' attribute)</p> <div class="highlight highlight-xml"><pre><span class="nt"><field</span> <span class="na">name=</span><span class="s">"mailer"</span> <span class="na">type=</span><span class="s">"list"</span> <span class="na">default=</span><span class="s">"gae"</span> <span class="na">label=</span><span class="s">"COM_CONFIG_FIELD_MAIL_MAILER_LABEL"</span> <span class="na">description=</span><span class="s">"COM_CONFIG_FIELD_MAIL_MAILER_DESC"</span> <span class="na">required=</span><span class="s">"true"</span> <span class="na">filter=</span><span class="s">"word"</span><span class="nt">></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"gae"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_GAE_MAIL<span class="nt"></option></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"mail"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_PHP_MAIL<span class="nt"></option></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"sendmail"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_SENDMAIL<span class="nt"></option></span> <span class="nt"><option</span> <span class="na">value=</span><span class="s">"smtp"</span><span class="nt">></span>COM_CONFIG_FIELD_VALUE_SMTP<span class="nt"></option></span> <span class="nt"></field></span> </pre></div> <h4>Actual result is as follows (the descendants options are not copied over):</h4> <div class="highlight highlight-xml"><pre><span class="nt"><field</span> <span class="na">name=</span><span class="s">"mailer"</span> <span class="na">type=</span><span class="s">"list"</span> <span class="na">default=</span><span class="s">"gae"</span> <span class="na">label=</span><span class="s">"COM_CONFIG_FIELD_MAIL_MAILER_LABEL"</span> <span class="na">description=</span><span class="s">"COM_CONFIG_FIELD_MAIL_MAILER_DESC"</span> <span class="na">required=</span><span class="s">"true"</span> <span class="na">filter=</span><span class="s">"word"</span><span class="nt">></span> <span class="nt"></field></span> </pre></div> <p>I think, when replacing a form this way, all nodes should be copied.</p> <p>The nice tracker url: <a href="http://issues.joomla.org/tracker/joomla-cms/2708">http://issues.joomla.org/tracker/joomla-cms/2708</a><br> The ugly tracker url: <a href="http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33028">http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=33028</a></p> |
Labels |
Added:
?
|
Status | New | ⇒ | Pending |
Labels |
Removed:
?
|
Category | ⇒ | Libraries Plugins |
Status | Pending | ⇒ | Ready to Commit |
Easy | No | ⇒ | Yes |
@test success thanks for the PR @WooDzu and @roland-d for the instructions RTC
Labels |
Added:
?
|
Title |
|
Title |
|
Status | Ready to Commit | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2015-05-03 21:19:13 |
Closed_By | ⇒ | roland-d |
Milestone |
Added: |
@test: Works as described. Before applying the patch, the XML is not loaded correctly, with the patch, the XML is loaded correctly and I see the options.
To help out the next tester, I created an installable plugin you can find here: http://www.csvimproved.com/joomla/plg_form_2708.zip
1. Download the plugin
2. Install the plugin via the extension manager
3. Enable the plugin via Plugin manager
4. Go to System -> Global configuration
5. Click on the Server tab
6. Notice that under Mail settings the Mailer has no options now
7. Apply the patch
8. Reload the Global configuration page
9. Click on the Server tab
10. Notice that under Mail settings the Mailer has now 4 options where the default is the untranslated string