Perforce Chronicle 2012.2/486814
API Documentation

Widget_Form_ImageWidget Class Reference

This is the image widget configuration form. More...

Inheritance diagram for Widget_Form_ImageWidget:
P4Cms_Form_SubForm

List of all members.

Public Member Functions

 init ()
 Defines the elements that make up the image form.
 isValid ($data)
 Extend parent to additionally validate image source data.
 setDefaults (array $defaults)
 Override parent to expand macros in the image url.

Public Attributes

const E_EMPTY_IMAGE_CONTENT = "Please select an image from the content"
const E_EMPTY_IMAGE_SOURCE = "Image source type is required"
const E_EMPTY_IMAGE_URL = "Please enter a URL of the remote image"

Detailed Description

This is the image widget configuration form.

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

Widget_Form_ImageWidget::init ( )

Defines the elements that make up the image form.

Called automatically when the form object is created.

    {
        // define associate dijit for this form, which will handle all javascript
        // such as selecting an image from the content, autodetecting dimensions etc.
        $this->setAttrib('dojoType', 'p4cms.widget.ImageForm');

        // add field to hold content entry id value
        $this->addElement('hidden', 'contentId');

        // add field to specify content source
        $this->addElement(
            'radio',
            'imageSource',
            array(
                'label'         => 'Content Source',
                'multiOptions'  => array(
                    'content'   => 'Content',
                    'remote'    => 'External'
                )
            )
        );

        // add field to specify content title
        $this->addElement(
            'text',
            'contentTitle',
            array(
                'label'         => 'Content'
            )
        );

        // add field to specify remote image url
        $this->addElement(
            'text',
            'imageUrl',
            array(
                'label'         => 'URL',
                'value'         => 'http://'
            )
        );

        // add field to specify image size options
        $this->addElement(
            'select',
            'sizeType',
            array(
                'label'         => 'Size',
                'multiOptions'  => array(
                    'full'      => 'Full Size',
                    'custom'    => 'Custom Size'
                )
            )
        );

        // add field to specify image width
        $this->addElement(
            'text',
            'imageWidth',
            array(
                'label'         => 'Width'
            )
        );

        // add field to specify image height
        $this->addElement(
            'text',
            'imageHeight',
            array(
                'label'         => 'Height'
            )
        );

        // add field to specify lock image size ratio option
        $this->addElement(
            'checkbox',
            'lockRatio',
            array(
                'label'         => 'Scale Proportionally'
            )
        );
        // put the checkbox input before its labels
        P4Cms_Form::moveCheckboxLabel($this->getElement('lockRatio'));

        // add field to specify image margin
        $this->addElement(
            'text',
            'margin',
            array(
                'label'         => 'Margin'
            )
        );

        // add field to specify image alternate text
        $this->addElement(
            'text',
            'imageAlt',
            array(
                'label'         => 'Alt Text'
            )
        );

        // add field to collect optional link href
        $this->addElement(
            'text',
            'link',
            array(
                'label'         => 'Link',
                'description'   => 'Enter a url to visit when the image is clicked.'
            )
        );

        $this->addElement(
            'select',
            'linkTarget',
            array(
                'label'         => 'Open Link In',
                'multiOptions'  => array(
                    '_self'     => 'Current Window',
                    '_blank'    => 'A New Window',
                    '_lightbox' => 'A Light Box'
                )
            )
        );

        // add field to specify image alignment
        $this->addElement(
            'radio',
            'alignment',
            array(
                'label'         => 'Alignment',
                'multiOptions'  => array(
                    'none'      => 'None',
                    'left'      => 'Left',
                    'center'    => 'Center',
                    'right'     => 'Right',
                ),
                'value'         => 'none'
            )
        );
    }
Widget_Form_ImageWidget::isValid ( data)

Extend parent to additionally validate image source data.

Parameters:
array$dataform data to validate
Returns:
bool true if form is valid, false otherwise
    {
        $valid = parent::isValid($data);

        $belongsTo = $this->getElementsBelongTo();
        $data      = $belongsTo && isset($data[$belongsTo]) ? $data[$belongsTo] : $data;

        // ensure image source is specified:
        //  - image source radio value is present
        //  - image url is specified either via the content or by the remote url
        $imageSource = $data['imageSource'];
        if ($imageSource === 'content' && !$data['contentTitle']) {
            $this->getElement('contentTitle')->addError(self::E_EMPTY_IMAGE_CONTENT);
            $valid = false;
        } else if ($imageSource === 'remote' && !$data['imageUrl']) {
            $this->getElement('imageUrl')->addError(self::E_EMPTY_IMAGE_URL);
            $valid = false;
        } else if (!$imageSource) {
            $this->getElement('imageUrl')->addError(self::E_EMPTY_IMAGE_SOURCE);
            $valid = false;
        }

        return $valid;
    }
Widget_Form_ImageWidget::setDefaults ( array $  defaults)

Override parent to expand macros in the image url.

Parameters:
array$defaultsform values to set
Returns:
Widget_Form_ImageWidget provides fluent interface
    {
        parent::setDefaults($defaults);

        // replace umage url with fully qualified image source path by expanding
        // macros it may contain
        $imageUrlElement = $this->getElement('imageUrl');
        if ($imageUrlElement) {
            $filter = new P4Cms_Filter_Macro;
            $imageUrlElement->setValue(
                $filter->filter($imageUrlElement->getValue())
            );
        }

        return $this;
    }

Member Data Documentation

const Widget_Form_ImageWidget::E_EMPTY_IMAGE_CONTENT = "Please select an image from the content"
const Widget_Form_ImageWidget::E_EMPTY_IMAGE_SOURCE = "Image source type is required"
const Widget_Form_ImageWidget::E_EMPTY_IMAGE_URL = "Please enter a URL of the remote image"

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