Perforce Chronicle 2012.2/486814
API Documentation
|
Allows the user to select one or more content entries. More...
Public Member Functions | |
getContentRecord () | |
Get the associated content record (if set). | |
getDefaultDisplayDecorators () | |
Get the default display decorators to use when rendering content elements of this type. | |
isValid ($value, $context=null) | |
Extends validate to ensure that value is not an array when multiple select is disabled (and vice-versa) and to verify that selected content ids exist. | |
setContentRecord ($content) | |
Set the associated content record for this element. | |
Public Attributes | |
$helper = 'ContentSelect' | |
Protected Attributes | |
$_contentRecord = null |
Allows the user to select one or more content entries.
The value is a single content id string, or an array of content ids. To allow for multiple selection, set the 'multiple' to true.
Content_Form_Element_ContentSelect::getContentRecord | ( | ) |
Get the associated content record (if set).
Implements P4Cms_Content_EnhancedElementInterface.
{
return $this->_contentRecord;
}
Content_Form_Element_ContentSelect::getDefaultDisplayDecorators | ( | ) |
Get the default display decorators to use when rendering content elements of this type.
Renders using the purpose built display selected content decorator (which is a wrapper of the content list view helper).
Configures it not to display a message when no content is selected. This allows placeholder values to work.
Implements P4Cms_Content_EnhancedElementInterface.
Reimplemented in Content_Form_Element_ImageSelect.
{ return array( array( 'decorator' => 'DisplaySelectedContent', 'options' => array( 'emptyMessage' => '' ) ) ); }
Content_Form_Element_ContentSelect::isValid | ( | $ | value, |
$ | context = null |
||
) |
Extends validate to ensure that value is not an array when multiple select is disabled (and vice-versa) and to verify that selected content ids exist.
string | array | $value | the selected content id(s). |
mixed | $context | optional context |
{ if (!$this->getValidator('P4Cms_Validate_Callback')) { $element = $this; $validator = new P4Cms_Validate_Callback; $validator->setCallback( function ($value) use ($element, $validator) { $multiple = $element->getAttrib('multiple'); $validTypes = (array) $element->getAttrib('validTypes'); // ensure type is array or scalar as appropriate. if (is_array($value) && !$multiple) { $validator->setMessage( "You may only select one content entry.", $validator::INVALID_VALUE ); return false; } if (!is_array($value) && $multiple) { $validator->setMessage( "The selected content must be in the form of a list.", $validator::INVALID_VALUE ); return false; } // validate the content id(s). $invalidIds = array(); $idValidator = new P4Cms_Validate_ContentId; $idValidator->setAllowNonExistent(false)->setAllowEmpty(true); foreach ((array) $value as $id) { if (!$idValidator->isValid($id)) { $invalidIds[] = $id; } } if ($invalidIds) { $validator->setMessage( "One or more of the selected entries could not be found. " . "Please review and clear these selections.", $validator::INVALID_VALUE ); return false; } // ensure that entries have valid content types if ($validTypes) { $entries = P4Cms_Content::fetchAll( array( 'ids' => array_filter((array) $value), 'limitFields' => array('contentType') ) ); foreach ($entries as $entry) { if (!in_array($entry->getContentTypeId(), $validTypes)) { $validator->setMessage( "One or more entries have an invalid content type" . " (allowed types: " . implode(', ', $validTypes) . ').', $validator::INVALID_VALUE ); return false; } } } return true; } ); $this->addValidator($validator); } return parent::isValid($value, $context); }
Content_Form_Element_ContentSelect::setContentRecord | ( | $ | content | ) |
Set the associated content record for this element.
P4Cms_Content | $content | the associated content record for this element. |
Implements P4Cms_Content_EnhancedElementInterface.
{ $this->_contentRecord = $content; }
Content_Form_Element_ContentSelect::$_contentRecord = null [protected] |
Content_Form_Element_ContentSelect::$helper = 'ContentSelect' |