Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-20079

custom attributes not working for embed tag due to improper xml handling

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: High High
    • Resolution: Unresolved
    • Affects Version/s: 2012.8
    • Fix Version/s: None
    • Labels:
      None
    • Environment:

      PHP 5.3.18

      Description

      When the embed tag has custom attributes defined, the don't get saved after publishing content that has embed object in some OE attribute.
      The values entered into custom attributes in OE popup, just disappear after publishing the object.

      After inspecting the code I have found that there's a problem in handling xml of the embed element and it's namespaces.
      The generated xml for the embed element ends up like this:

      <embed xmlns:default="http://ez.no/namespaces/ezpublish3/custom/" xmlns:default1="http://ez.no/namespaces/ezpublish3/custom/" xmlns:default2="http://ez.no/namespaces/ezpublish3/custom/" title="test file" customattributes="test_attr1|1111attribute_separationtest_attr2|icon_right" view="embed" size="medium" object_id="106" default:test_attr1="1111" default2:test_attr2="222"/>

      while it should be like this:

      <embed xmlns:default="http://ez.no/namespaces/ezpublish3/custom/" xmlns:default1="http://ez.no/namespaces/ezpublish3/custom/" xmlns:default2="http://ez.no/namespaces/ezpublish3/custom/" title="test file" customattributes="test_attr1|1111attribute_separationtest_attr2|icon_right" view="embed" size="medium" object_id="106" custom:test_attr1="1111" custom:test_attr2="222"/>

      After further inspecting I found out that the thing that helps is adding the namespace "xmlns:custom" BEFORE and AFTER adding the attribute with setAttributeNS() while processing custom tags.
      Also the $removeAttr variable should be set to false for custom tags.

      So in order to work I had to make changes in 2 file. Change in kernel/classes/datatypes/ezxmltext/ezxmlinputparser.php this code:

                      elseif ( in_array( $fullName, $schemaCustomAttributes ) )
                      {
                          // add 'custom' prefix if it is not given
                          $allowed = true;
                          $removeAttr = true;
                          $element->setAttributeNS( $this->Namespaces['custom'], 'custom:' . $fullName, $attr->value );
                      }
      

      into this:

                      elseif ( in_array( $fullName, $schemaCustomAttributes ) )
                      {
                          // add 'custom' prefix if it is not given
                          $allowed = true;
                          $removeAttr = false;
                          $element->setAttributeNS( 'http://www.w3.org/2000/xmlns/', 'xmlns:custom',  $this->Namespaces['custom'] );
                          $element->setAttributeNS( $this->Namespaces['custom'], 'custom:' . $fullName, $attr->value );
                          $element->setAttributeNS( 'http://www.w3.org/2000/xmlns/', 'xmlns:custom',  $this->Namespaces['custom'] );
       
                      }
      

      And change in extension/ezoe/ezxmltext/handlers/input/ezoeinputparser.php this code:

                      if ( $attr !== '' && strpos( $attr, '|' ) !== false )
                      {
                          list( $attrName, $attrValue ) = explode( '|', $attr, 2 );
                          $element->setAttributeNS( 'http://ez.no/namespaces/ezpublish3/custom/',
                                                    'custom:' . $attrName,
                                                    $attrValue );
                      }
      

      into this:

                      if ( $attr !== '' && strpos( $attr, '|' ) !== false )
                      {
                          list( $attrName, $attrValue ) = explode( '|', $attr, 2 );
                          $element->setAttributeNS( 'http://www.w3.org/2000/xmlns/', 'xmlns:custom', 'http://ez.no/namespaces/ezpublish3/custom/' );
                          $element->setAttributeNS( 'http://ez.no/namespaces/ezpublish3/custom/',
                                                    'custom:' . $attrName,
                                                    $attrValue );
                          $element->setAttributeNS( 'http://www.w3.org/2000/xmlns/', 'xmlns:custom', 'http://ez.no/namespaces/ezpublish3/custom/' );
       
                      }
      

      I don't know why this worked (I'm not that much of an XML expert), but it works.

      Anyone from the eZ crew wishes to inspect this?

      P.S. This was all on PHP 5.3.15

        Activity

          People

          • Assignee:
            Unassigned
            Reporter:
            Mavko Žmak - Žmale
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: