Perforce Chronicle 2012.2/486814
API Documentation
|
This is the content list widget configuration form. More...
Public Member Functions | |
init () | |
Defines the elements that make up the recent content widget config form. |
This is the content list widget configuration form.
Content_Form_ListWidget::init | ( | ) |
Defines the elements that make up the recent content widget config form.
Called automatically when the form object is created.
{ // add option to limit number of displayed content entries. $options = array('' => 'Unlimited') + array_combine(range(1, 10), range(1, 10)) + array_combine(range(15, 50, 5), range(15, 50, 5)) + array_combine(range(60, 100, 10), range(60, 100, 10)); $this->addElement( 'select', 'count', array( 'label' => 'Maximum Items', 'description' => "Enter the maximum number of content entries to display.", 'multiOptions' => $options ) ); // checkbox to show/hide icon $this->addElement( 'checkbox', 'showIcons', array( 'label' => 'Show Icons' ) ); // content type filter (checklist) so users can pick multiple content types $this->addElement( 'typeGroup', 'contentType', array( 'label' => 'Content Types' ) ); // build a list of element names and labels for later use $fieldLabels = array(); $fieldNames = array(); $types = P4Cms_Content_Type::fetchAll(); foreach ($types->invoke('getFormElements') as $elements) { foreach ($elements as $element) { $name = $element->getName(); $label = $element->getLabel(); if (!isset($fieldLabels[$name])) { $fieldLabels[$name] = array(); } if (!isset($fieldNames[$label])) { $fieldNames[$label] = array(); } if (!in_array($label, $fieldLabels[$name])) { $fieldLabels[$name][] = $label; } if (!in_array($name, $fieldNames[$label])) { $fieldNames[$label][] = $name; } } } // Build sort field multioptions based on the following rules: // If a given field label appears for multiple keys, add the key name to the option // to help disambiguate them: Title (title), Title (articleTitle) // If a content type field 'key' has various labels, list all of the // unique/nat-case-sorted labels for that key (as a single select option): // Article Title, Page Title, Title $sortMultiOptions = array(); foreach ($fieldLabels as $name => $labels) { natcasesort($labels); $sortMultiOptions[$name] = implode(', ', $labels); foreach ($labels as $label) { if (count($fieldNames[$label]) > 1) { $sortMultiOptions[$name] .= ' (' . $name . ')'; break; } } } // add Last Modified, which is a non-element sort option built into P4Cms_Record_Query $sortMultiOptions[P4Cms_Record_Query::SORT_DATE] = 'Last Modified'; natcasesort($sortMultiOptions); $sortOrder = array( P4Cms_Record_Query::SORT_ASCENDING => 'Ascending', P4Cms_Record_Query::SORT_DESCENDING => 'Descending' ); $this->addElement( 'select', 'primarySortField', array( 'label' => 'Primary Sort', 'multiOptions' => $sortMultiOptions ) ); $this->getElement('primarySortField') ->getDecorator('htmlTag') ->setOption('class', 'content-list-config-sort-field'); $this->addElement( 'select', 'primarySortOrder', array( 'multiOptions' => $sortOrder ) ); $this->getElement('primarySortOrder') ->getDecorator('label') ->setOption('tagClass', 'content-list-config-sort-order'); $this->addElement( 'select', 'secondarySortField', array( 'label' => 'Secondary Sort', 'multiOptions' => array('' => '') + $sortMultiOptions ) ); $this->getElement('secondarySortField') ->getDecorator('htmlTag') ->setOption('class', 'content-list-config-sort-field'); $this->addElement( 'select', 'secondarySortOrder', array( 'multiOptions' => $sortOrder ) ); $this->getElement('secondarySortOrder') ->getDecorator('label') ->setOption('tagClass', 'content-list-config-sort-order'); }