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

eZImageType::fromString() doesn't support alternative image text

    Details

      Description

      eZImageType::fromString() doesn't support alternative image text. It only accepts the image path.

      Specifying an alternative text is mandatory for good accessibility support. This should unfortunately also be added to toString(), and this will break BC.

        Activity

        Hide
        Bertrand Dunogier added a comment -

        Patch suggestion for this is attached, in 2 separate parts:

        ezimage-alternativetext-fromstring.diff: patch for fromString
        ezimage-alternativetext-tostring.diff: patch for toString

        both add support for a pipe separated string:

        path/to/image.jpg|alternative textezimage-alternativetext.tgz

        Show
        Bertrand Dunogier added a comment - Patch suggestion for this is attached, in 2 separate parts: ezimage-alternativetext-fromstring.diff: patch for fromString ezimage-alternativetext-tostring.diff: patch for toString both add support for a pipe separated string: path/to/image.jpg|alternative text ezimage-alternativetext.tgz
        Hide
        André R added a comment -

        Patch using strpos instead (in case alternative text contains |):

        Index: kernel/classes/datatypes/ezimage/ezimagetype.php
        ===================================================================
        --- kernel/classes/datatypes/ezimage/ezimagetype.php	(revision 23864)
        +++ kernel/classes/datatypes/ezimage/ezimagetype.php	(working copy)
        @@ -470,13 +470,24 @@
             {
                 $content = $objectAttribute->content();
                 $original = $content->attribute( 'original' );
        -        return $original['url'];
        +        $alternativeText = $content->attribute( 'alternative_text' );
        +        return $original['url'] . '|' . $alternativeText;
             }
         
             function fromString( $objectAttribute, $string )
             {
        +        $delimiterPos = strpos( $string, '|' );
        +
                 $content = $objectAttribute->attribute( 'content' );
        -        $content->initializeFromFile( $string, "" );
        +        if ( $delimiterPos === false )
        +        {
        +        	$content->initializeFromFile( $string, '' );
        +        }
        +        else
        +        {
        +            $content->initializeFromFile( substr( $string, 0, $delimiterPos ), '' );
        +            $content->setAttribute( 'alternative_text', substr( $string, $delimiterPos + 1 ) );
        +        }
                 $content->store( $objectAttribute );
                 return true;
             }
        

        Show
        André R added a comment - Patch using strpos instead (in case alternative text contains |): Index: kernel/classes/datatypes/ezimage/ezimagetype.php =================================================================== --- kernel/classes/datatypes/ezimage/ezimagetype.php (revision 23864) +++ kernel/classes/datatypes/ezimage/ezimagetype.php (working copy) @@ -470,13 +470,24 @@ { $content = $objectAttribute->content(); $original = $content->attribute( 'original' ); - return $original['url']; + $alternativeText = $content->attribute( 'alternative_text' ); + return $original['url'] . '|' . $alternativeText; } function fromString( $objectAttribute, $string ) { + $delimiterPos = strpos( $string, '|' ); + $content = $objectAttribute->attribute( 'content' ); - $content->initializeFromFile( $string, "" ); + if ( $delimiterPos === false ) + { + $content->initializeFromFile( $string, '' ); + } + else + { + $content->initializeFromFile( substr( $string, 0, $delimiterPos ), '' ); + $content->setAttribute( 'alternative_text', substr( $string, $delimiterPos + 1 ) ); + } $content->store( $objectAttribute ); return true; }
        Hide
        André R added a comment -

        Fixed in
        trunk (4.2.0Alpha2) Rev. 23871
        stable/4.1 (4.1.4) Rev. 23872
        stable/4.0 (4.0.7) Rev. 23873

        Only trunk got toString() support, so that packages within 4.0 and 4.1 versions are compatible.

        Show
        André R added a comment - Fixed in trunk (4.2.0Alpha2) Rev. 23871 stable/4.1 (4.1.4) Rev. 23872 stable/4.0 (4.0.7) Rev. 23873 Only trunk got toString() support, so that packages within 4.0 and 4.1 versions are compatible.
        Hide
        ezrobot added a comment -

        This issue has been automatically closed due to the lack of activity over a long period of time. It is very likely that it is obsolete, but if you think it is still valid, do not hesitate to reopen it and mention why.

        Show
        ezrobot added a comment - This issue has been automatically closed due to the lack of activity over a long period of time. It is very likely that it is obsolete, but if you think it is still valid, do not hesitate to reopen it and mention why.

          People

          • Assignee:
            André R
            Reporter:
            Bertrand Dunogier
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: