コード例 #1
0
 /**
  * Parse the template file and return it as string
  * @param array
  * @return string
  */
 public function parse($arrAttributes = null)
 {
     if ($this->formcontrol_template) {
         $this->strTemplate = $this->formcontrol_template;
         $strClass = 'select';
         $blnHasGroups = false;
         if ($this->multiple) {
             $this->strName .= '[]';
             $strClass = 'multiselect';
         } elseif (is_array($this->varValue)) {
             $this->varValue = $this->varValue[0];
         }
         // Add empty option (XHTML) if there are none
         if (empty($this->arrOptions)) {
             $this->arrOptions = array(array('value' => '', 'label' => '-'));
         }
         // Chosen
         if ($this->chosen) {
             $strClass .= ' tl_chosen';
         }
         $this->class = $strClass . (strlen($this->strClass) ? ' ' . $this->strClass : '');
         $arrOptions = array();
         // Generate options
         foreach ($this->arrOptions as $arrOption) {
             if ($arrOption['group']) {
                 if ($blnHasGroups) {
                     $arrOptions[] = array('type' => 'group_end');
                 }
                 $arrOptions[] = array('type' => 'group_start', 'label' => specialchars($arrOption['label']));
                 $blnHasGroups = true;
                 continue;
             }
             $arrOptions[] = array('type' => 'option', 'value' => $arrOption['value'], 'selected' => $this->isSelected($arrOption), 'label' => $arrOption['label']);
         }
         if ($blnHasGroups) {
             $arrOptions[] = array('type' => 'group_end');
         }
         $this->options = $arrOptions;
     }
     return parent::parse($arrAttributes);
 }
 /**
  * Parse the template file and return it as string
  *
  * @param array $arrAttributes An optional attributes array
  *
  * @return string The template markup
  */
 public function parse($arrAttributes = null)
 {
     $this->arrOptions = ConditionalSelectMenu::prepareOptions($this->arrOptions);
     $GLOBALS['TL_JAVASCRIPT']['conditionalselect'] = 'system/modules/conditionalselectmenu/assets/conditionalselect' . ($GLOBALS['TL_CONFIG']['debugMode'] ? '' : '.min') . '.js';
     $strOptions = '';
     $strClass = 'select';
     if ($this->multiple) {
         $this->strName .= '[]';
         $strClass = 'multiselect';
     }
     // Add empty option (XHTML) if there are none
     if (empty($this->arrOptions)) {
         $this->arrOptions = array(array('value' => '', 'label' => strlen($this->blankOptionLabel) ? $this->blankOptionLabel : '-'));
     }
     // Custom class
     if ($this->strClass != '') {
         $strClass .= ' ' . $this->strClass;
     }
     $this->strClass = $strClass;
     // Prepare Javascript
     if ($this->includeBlankOption) {
         $this->classOptions = ", {includeBlankOption: true" . (strlen($this->blankOptionLabel) ? ", blankOptionLabel: '" . $this->blankOptionLabel . "'" : '') . "}";
     }
     return parent::parse($arrAttributes);
 }