Perforce Chronicle 2012.2/486814
API Documentation

Content_Form_Element_ImageFile Class Reference

Extends Zend_Form_Element_File to provide special validation and handling for image files. More...

Inheritance diagram for Content_Form_Element_ImageFile:
Content_Form_Element_File P4Cms_Content_EnhancedElementInterface P4Cms_Record_EnhancedElementInterface

List of all members.

Public Member Functions

 getDefaultDisplayDecorators ()
 Get the default display decorators to use when rendering content elements of this type.
 init ()
 Extend parent to include image validator.
 populateRecord (P4Cms_Record $record)
 Overrides the population of file specific metadata in order to include some image specific data.

Detailed Description

Extends Zend_Form_Element_File to provide special validation and handling for image files.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

Content_Form_Element_ImageFile::getDefaultDisplayDecorators ( )

Get the default display decorators to use when rendering content elements of this type.

Returns:
array decorators configuration array suitable for passing to element setDecorators().

Reimplemented from Content_Form_Element_File.

    {
        return array(
            array(
                'decorator' => 'DisplayImage',
                'options'   => array(
                    'placement' => Content_Form_Decorator_DisplayImage::REPLACE
                )
            )
        );
    }
Content_Form_Element_ImageFile::init ( )

Extend parent to include image validator.

    {
        parent::init();
        $this->addValidator(
            'File_Extension',
            false,
            "gif, ico, jpg, jpeg, png, svg"
        );
    }
Content_Form_Element_ImageFile::populateRecord ( P4Cms_Record record)

Overrides the population of file specific metadata in order to include some image specific data.

Parameters:
P4Cms_Record$recordthe record to populate

Reimplemented from Content_Form_Element_File.

    {
        parent::populateRecord($record);
        
        if ($this->isUploaded() && ($this->isReplaced() || !$this->hasExistingFile())) {
            $tempFileName = $this->getFileTempName();
            $size     = getimagesize($tempFileName);

            $metadata = $record->getFieldMetadata($this->getName());
            $metadata['dimensions'] = array('width' => $size[0], 'height' => $size[1]);
            $record->setFieldMetadata(
                $this->getName(),
                $metadata
            );
        }
        
        return $this;
    }

The documentation for this class was generated from the following file: