This patch introduces the concept of wrappers to the configuration system. It works by adding a wrapper argument to the config->set() method.

  $html = '<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>';
  $config = config('test.wrapper');
  $test = array(
    'test' => $html,
    'test2' => array(
      'test3' => $html,
    ),
  );

  $config->set('test_cdata', $html, CONFIG_HTML_WRAPPER);
  $config->set('test_cdata_array',$test, CONFIG_HTML_WRAPPER);
  $config->save();

This produces xml like this:

<?xml version="1.0"?>
<config>
  <test_cdata><![CDATA[<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>]]></test_cdata>
  <test_cdata_array>
    <test><![CDATA[<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>]]></test>
    <test2>
      <test3><![CDATA[<a> <b> <br> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>]]></test3>
    </test2>
  </test_cdata_array>
</config>

Currently we have xml like this:

<?xml version="1.0"?>
<config>
  <test_no_cdata>&lt;a&gt; &lt;b&gt; &lt;br&gt; &lt;dd&gt; &lt;dl&gt; &lt;dt&gt; &lt;em&gt; &lt;i&gt; &lt;li&gt; &lt;ol&gt; &lt;p&gt; &lt;strong&gt; &lt;u&gt; &lt;ul&gt;</test_no_cdata>
  <test_no_cdata_array>
    <test>&lt;a&gt; &lt;b&gt; &lt;br&gt; &lt;dd&gt; &lt;dl&gt; &lt;dt&gt; &lt;em&gt; &lt;i&gt; &lt;li&gt; &lt;ol&gt; &lt;p&gt; &lt;strong&gt; &lt;u&gt; &lt;ul&gt;</test>
    <test2>
      <test3>&lt;a&gt; &lt;b&gt; &lt;br&gt; &lt;dd&gt; &lt;dl&gt; &lt;dt&gt; &lt;em&gt; &lt;i&gt; &lt;li&gt; &lt;ol&gt; &lt;p&gt; &lt;strong&gt; &lt;u&gt; &lt;ul&gt;</test3>
    </test2>
  </test_no_cdata_array>
</config>

The obvious downside of this approach is that we will always have to save the files on config->save() as the wrapper mapping to config keys is only stored in memory.

The upside of this approach is that through using the LIBXML_NOCDATA flag on simplexml_load_string() we don't have to do anything on $config->get().

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott’s picture

Issue tags: +Configuration system

Updating tag...

Status: Needs review » Needs work

The last submitted patch, config_html_wrapper.patch, failed testing.

alexpott’s picture

Status: Needs work » Needs review
FileSize
5.77 KB

New patch to resolve issues when nested keys like biff.bang

sun’s picture

Status: Needs review » Closed (won't fix)