? Success

User tests: Successful: Unsuccessful:

avatar WooDzu
WooDzu
21 Dec 2013

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

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

<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>

Field definition we want to set instead and also the expected result

(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>

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

<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

avatar WooDzu WooDzu - open - 21 Dec 2013
avatar WooDzu WooDzu - change - 21 Dec 2013
The description was changed
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">-&gt;</span><span class="na">getName</span><span class="p">()</span> <span class="o">==</span> <span class="nv">$formName</span> <span class="o">&amp;&amp;</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">-&gt;</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">&lt;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">&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"mail"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_PHP_MAIL<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"sendmail"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_SENDMAIL<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"smtp"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_SMTP<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;/field&gt;</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">&lt;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">&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"gae"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_GAE_MAIL<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"mail"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_PHP_MAIL<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"sendmail"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_SENDMAIL<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"smtp"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_SMTP<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;/field&gt;</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">&lt;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">&gt;</span> <span class="nt">&lt;/field&gt;</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">-&gt;</span><span class="na">getName</span><span class="p">()</span> <span class="o">==</span> <span class="nv">$formName</span> <span class="o">&amp;&amp;</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">-&gt;</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">&lt;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">&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"mail"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_PHP_MAIL<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"sendmail"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_SENDMAIL<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"smtp"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_SMTP<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;/field&gt;</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">&lt;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">&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"gae"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_GAE_MAIL<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"mail"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_PHP_MAIL<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"sendmail"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_SENDMAIL<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;option</span> <span class="na">value=</span><span class="s">"smtp"</span><span class="nt">&gt;</span>COM_CONFIG_FIELD_VALUE_SMTP<span class="nt">&lt;/option&gt;</span> <span class="nt">&lt;/field&gt;</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">&lt;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">&gt;</span> <span class="nt">&lt;/field&gt;</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&amp;tracker_item_id=33028">http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&amp;tracker_item_id=33028</a></p>
Labels Added: ?
be87d34 21 Dec 2013 avatar WooDzu typo
avatar brianteeman brianteeman - change - 21 Aug 2014
The description was changed
Status New Pending
avatar nicksavov nicksavov - change - 21 Aug 2014
Labels Removed: ?
avatar roland-d
roland-d - comment - 3 May 2015

@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

avatar roland-d roland-d - test_item - 3 May 2015 - Tested successfully
avatar zero-24 zero-24 - change - 3 May 2015
Category Libraries Plugins
avatar zero-24 zero-24 - change - 3 May 2015
Status Pending Ready to Commit
Easy No Yes
avatar zero-24
zero-24 - comment - 3 May 2015

@test success thanks for the PR @WooDzu and @roland-d for the instructions :smile: RTC


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/2708.

avatar zero-24 zero-24 - test_item - 3 May 2015 - Tested successfully
avatar zero-24 zero-24 - change - 3 May 2015
Labels Added: ?
avatar zero-24 zero-24 - change - 3 May 2015
Title
[PR] Allow replacing xml form field's descendants
[#33028] [PR] Allow replacing xml form field's descendants
avatar joomla-cms-bot joomla-cms-bot - change - 3 May 2015
Title
[PR] Allow replacing xml form field's descendants
[#33028] [PR] Allow replacing xml form field's descendants
avatar roland-d roland-d - change - 3 May 2015
Status Ready to Commit Closed
Closed_Date 0000-00-00 00:00:00 2015-05-03 21:19:13
Closed_By roland-d
avatar roland-d roland-d - close - 3 May 2015
avatar roland-d roland-d - close - 3 May 2015
avatar roland-d roland-d - change - 3 May 2015
Milestone Added:
avatar WooDzu WooDzu - head_ref_deleted - 3 May 2015
avatar johanjanssens johanjanssens - reference | 9bc4ad4 - 19 Jun 15

Add a Comment

Login with GitHub to post a comment