/** * Returns the frontend filter widget information for the filter setting. * * The returning array will hold the following keys: * * class - The CSS classes for the widget. * * label - The label text for the widget. * * formfield - The parsed default widget object for this filter setting. * * raw - The widget information that was used for rendering "formfield" as raw array (this means * prior calling prepareForWidget()). * * urlparam - The URL parameter used for this widget. * * options - The filter options available to be used in selects etc. see prepareFrontendFilterOptions * for details on the contained array. * * autosubmit - True if the frontend filter shall perform auto form submitting, false otherwise. * * urlvalue - The current value selected in the filtersetting. Will use "urlvalue" from $arrWidget with * fallback to the value of the url param in the filter url. * * @param array $arrWidget The widget information to use for generating. * * @param array $arrFilterUrl The filter url parameters to use. * * @param array $arrJumpTo The jumpTo page to use for URL generating - if empty, the current * frontend page will get used. * * @param bool $blnAutoSubmit Determines if the generated options/widgets shall perform auto submitting * or not. * * @return array */ protected function prepareFrontendFilterWidget($arrWidget, $arrFilterUrl, $arrJumpTo, MetaModelFrontendFilterOptions $objFrontendFilterOptions) { $strClass = $GLOBALS['TL_FFL'][$arrWidget['inputType']]; // No widget? no output! that's it. if (!$strClass) { return array(); } // Determine current value. $arrWidget['value'] = $arrFilterUrl[$arrWidget['eval']['urlparam']]; $arrData = MetaModelController::getInstance()->prepareForWidget($arrWidget, $arrWidget['eval']['urlparam'], $arrWidget['value']); if ($objFrontendFilterOptions->isAutoSubmit() && TL_MODE == 'FE') { $GLOBALS['TL_JAVASCRIPT']['metamodels'] = 'system/modules/metamodels/html/metamodels.js'; } /** @var Widget $objWidget */ $objWidget = new $strClass($arrData); $strField = $objWidget->generate(); return array('class' => sprintf('mm_%s %s%s%s', $arrWidget['inputType'], $arrWidget['eval']['urlparam'], $arrWidget['value'] !== null ? ' used' : ' unused', $objFrontendFilterOptions->isAutoSubmit() ? ' submitonchange' : ''), 'label' => $objWidget->generateLabel(), 'formfield' => $strField, 'raw' => $arrWidget, 'urlparam' => $arrWidget['eval']['urlparam'], 'options' => $this->prepareFrontendFilterOptions($arrWidget, $arrFilterUrl, $arrJumpTo, $objFrontendFilterOptions->isAutoSubmit()), 'count' => $arrWidget['count'], 'showCount' => $objFrontendFilterOptions->isShowCountValues(), 'autosubmit' => $objFrontendFilterOptions->isAutoSubmit(), 'urlvalue' => array_key_exists('urlvalue', $arrWidget) ? $arrWidget['urlvalue'] : $arrWidget['value']); }
/** * Get the filters */ protected function getFilters() { $strAction = ''; /** * @var IMetaModelFilterSettings */ $objFilterSetting = MetaModelFilterSettingsFactory::byId($this->objFilterConfig->metamodel_filtering); $objFrontendFilterOptions = new MetaModelFrontendFilterOptions(); $objFrontendFilterOptions->setAutoSubmit($this->objFilterConfig->metamodel_fef_autosubmit ? true : false); $objFrontendFilterOptions->setHideClearFilter($this->objFilterConfig->metamodel_fef_hideclearfilter ? true : false); $objFrontendFilterOptions->setShowCountValues($this->objFilterConfig->metamodel_available_values ? true : false); $arrJumpTo = $this->objFilterConfig->arrJumpTo; $arrParams = $this->getParams(); $arrWidgets = $objFilterSetting->getParameterFilterWidgets($arrParams['all'], $arrJumpTo, $objFrontendFilterOptions); // filter the widgets we do not want to show. $arrWanted = $this->getWantedNames(); // if we have POST data, we need to redirect now. if ($_POST && $this->Input->post('FORM_SUBMIT') == $this->formId) { $arrRedirectParams = $arrParams['other']; foreach ($arrWanted as $strWidget) { $arrFilter = $arrWidgets[$strWidget]; if (!empty($arrFilter['urlvalue'])) { $arrRedirectParams[$strWidget] = $arrFilter['urlvalue']; } } $this->redirectPost($arrRedirectParams); } $arrRendered = array(); // render the widgets through the filter templates. foreach ($this->getWantedNames() as $strWidget) { $arrFilter = $arrWidgets[$strWidget]; $strTemplate = $arrFilter['raw']['eval']['template']; // parse sub template $objSubTemplate = new FrontendTemplate($strTemplate ? $strTemplate : 'mm_filteritem_default'); $objSubTemplate->setData($arrFilter); $objSubTemplate->submit = $objFrontendFilterOptions->isAutoSubmit(); $arrFilter['value'] = $objSubTemplate->parse(); $arrRendered[$strWidget] = $arrFilter; } // return filter data return array('action' => $this->generateFrontendUrl($arrJumpTo, $this->getJumpToUrl($arrParams['other'])), 'formid' => $this->formId, 'filters' => $arrRendered, 'submit' => $objFrontendFilterOptions->isAutoSubmit() ? '' : $GLOBALS['TL_LANG']['metamodels_frontendfilter']['submit']); }
/** * {@inheritdoc} */ public function getParameterFilterWidgets($arrIds, $arrFilterUrl, $arrJumpTo, MetaModelFrontendFilterOptions $objFrontendFilterOptions) { // if defined as static, return nothing as not to be manipulated via editors. if (!$this->enableFEFilterWidget()) { return array(); } $objAttribute = $this->getMetaModel()->getAttributeById($this->get('attr_id')); $GLOBALS['MM_FILTER_PARAMS'][] = $this->getParamName(); $arrCount = array(); $arrWidget = array('label' => array($this->get('label') ? $this->get('label') : $objAttribute->getName(), 'GET: ' . $this->getParamName()), 'inputType' => 'select', 'options' => $this->getParameterFilterOptions($objAttribute, $arrIds, $arrCount), 'count' => $arrCount, 'showCount' => $objFrontendFilterOptions->isShowCountValues(), 'eval' => array('includeBlankOption' => $this->get('blankoption') && !$objFrontendFilterOptions->isHideClearFilter() ? true : false, 'blankOptionLabel' => &$GLOBALS['TL_LANG']['metamodels_frontendfilter']['do_not_filter'], 'colname' => $objAttribute->getColname(), 'urlparam' => $this->getParamName(), 'onlyused' => $this->get('onlyused'), 'onlypossible' => $this->get('onlypossible'), 'template' => $this->get('template'))); return array($this->getParamName() => $this->prepareFrontendFilterWidget($arrWidget, $arrFilterUrl, $arrJumpTo, $objFrontendFilterOptions)); }