Perforce Chronicle 2012.2/486814
API Documentation

Content_Form_Content Class Reference

This is the content entry form. More...

Inheritance diagram for Content_Form_Content:
P4Cms_Form_PubSubForm P4Cms_Form

List of all members.

Public Member Functions

 addSubForm ($form, $name)
 Ensure consistent presentation of sub-forms.
 getEntry ()
 Get the content entry instance we are constructing a form for.
 init ()
 Sets up the content entry form Called automatically when the form object is created.
 populate ($values=null)
 Extends parent to populate from entry when called without values.
 setEntry (P4Cms_Content $entry)
 Set the content entry instance we are constructing a form for.

Protected Attributes

 $_contentEntry = null

Detailed Description

This is the content entry 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

Content_Form_Content::addSubForm ( form,
name 
)

Ensure consistent presentation of sub-forms.

Extended to make sub-forms into dijits.

Parameters:
Zend_Form$formthe sub-form to normalize.
string$namethe name of the sub-form.
Returns:
Zend_Form the updated form.
    {
        parent::addSubForm($form, $name);

        // set dojoType from the attribute if its present or assign default value
        // clear the dojoType attribute to avoid turning another element into the
        // same dijit as well
        $type = $form->getAttrib('dojoType');
        if ($type) {
            $form->removeAttrib('dojoType');
        } else {
            $type = 'p4cms.content.SubForm';
        }

        $fieldset = $form->getDecorator('DdTag');
        $fieldset->setOption('formName',    $name)
                 ->setOption('id',          $this->getIdPrefix() . $name . '-sub-form')
                 ->setOption('class',       'content-sub-form')
                 ->setOption('dojoType',    $type);

        return $form;
    }
Content_Form_Content::getEntry ( )

Get the content entry instance we are constructing a form for.

Returns:
P4Cms_Content the content entry this form is for.
    {
        if (!$this->_contentEntry instanceof P4Cms_Content) {
            throw new Content_Exception(
                "Cannot get content entry. No entry has been set."
            );
        }

        return $this->_contentEntry;
    }
Content_Form_Content::init ( )

Sets up the content entry form Called automatically when the form object is created.

Reimplemented from P4Cms_Form_PubSubForm.

    {
        // we need the content entry and type to make the form.
        $entry = $this->getEntry();
        $type  = $entry->getContentType();

        // set the pub/sub topic so others can influence form
        $this->setTopic('p4cms.content.form');

        $this->setMethod('post');
        $this->setAttrib('class', 'p4cms-ui content-form');

        // add a hidden content type field.
        $this->addElement(
            'hidden',
            P4Cms_Content::TYPE_FIELD,
            array('value' => $type->getId())
        );

        // add the type specific elements to the form.
        $this->addElements($type->getFormElements());

        // if form contains an id element, disable it for edits
        // and apply special validation rules for adds.
        $id = $this->getElement('id');
        if ($id && $entry->getId()) {
            $id->setValue($entry->getId())
               ->setAttrib('disabled', true);
        } else if ($id) {
            if (!array_key_exists('ContentId', $id->getValidators())) {
                $id->addValidator('ContentId');
            }

            $id->getValidator('ContentId')
               ->setAllowExisting(false)
               ->setAllowEmpty(false);
        }

        // decorate each form element so that we can easily identify them in the dom.
        foreach ($this->getElements() as $element) {
            $element->addDecorator(
                array('DivTag' => 'HtmlTag'),
                array(
                    'tag'   => 'div',
                    'id'    => 'content-form-' . $element->getName(),
                    'class' => 'content-form-element'
                )
            );
        }

        // put all of the general content elements into a display-group.
        $this->addDisplayGroup(
            array_keys($this->getElements()),
            'content-form-elements',
            array(
                'class' => 'content-form-elements',
                'order' => -1000
            )
        );

        // create save sub-form to provide save button and comment field.
        $saveForm = new Content_Form_Save(
            array(
                'idPrefix'  => $this->getIdPrefix(),
                'dojoType'  => 'p4cms.content.SaveSubForm',
                'order'     => 1000
            )
        );

        // normalize sub-form (e.g. to have the same decorators as
        // sub-forms added via pub/sub sub-form topic) - we must
        // set is-array to false after normalization because part of
        // the normalization is to set is-array to true.
        static::normalizeSubForm($saveForm, 'save');
        $saveForm->setIsArray(false);
        $this->addSubForm($saveForm, 'save');

        // call parent to publish the form.
        parent::init();
    }
Content_Form_Content::populate ( values = null)

Extends parent to populate from entry when called without values.

Parameters:
P4Cms_Record | array | null$valuesoptional - values to populate the form from. if null, populates from entry.
Returns:
P4Cms_Form provides fluent interface.

Reimplemented from P4Cms_Form_PubSubForm.

    {
        // if values input is empty, populate from entry.
        if (empty($values)) {
            $values = $this->getEntry();
        }

        return parent::populate($values);
    }
Content_Form_Content::setEntry ( P4Cms_Content entry)

Set the content entry instance we are constructing a form for.

Parameters:
P4Cms_Content$entrythe entry instance to make a form for
Returns:
Content_Form_Content provides fluent interface.
    {
        $this->_contentEntry = $entry;

        return $this;
    }

Member Data Documentation

Content_Form_Content::$_contentEntry = null [protected]

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