Ejemplo n.º 1
0
 /**
  * Parse field declaration to render input.
  *
  * @return  void
  */
 public function getInput()
 {
     // Make sure we have options declared
     if (!isset($this->element->option)) {
         return JText::_('JSN_TPLFW_ERROR_MISSING_OPTIONS');
     }
     // Get template model
     $templateModel = class_exists('JModelLegacy') ? JModelLegacy::getInstance('Style', 'TemplatesModel') : JModel::getInstance('Style', 'TemplatesModel');
     // Get style data
     $this->data = $templateModel->getItem(JFactory::getApplication()->input->getInt('id'));
     // Instantiate helper class of JSN Template Framework
     $helper = JSNTplTemplateHelper::getInstance();
     // Finalize template parameters
     $this->data->params = $helper->loadParams($this->data->params, $this->data->template);
     // Initialize field value
     if (isset($this->data->params[(string) $this->element['name']])) {
         $this->value = $this->data->params[(string) $this->element['name']];
     } elseif (empty($this->value)) {
         $this->value = (string) $this->element['default'];
     }
     if (is_string($this->value)) {
         $this->value = (substr($this->value, 0, 1) == '{' and substr($this->value, -1) == '}') ? json_decode($this->value, true) : array($this->value => 1);
     }
     // Parse field attributes
     $options['class'] = isset($this->element['class']) ? (string) $this->element['class'] : '';
     $options['disabled'] = '';
     if (isset($this->element['disabled']) and $this->element['disabled'] == 'true') {
         $options['class'] .= ' disabled';
         $options['disabled'] = ' disabled="disabled"';
     }
     // Get all checkbox options from xml
     $data = array();
     foreach ($this->element->children() as $option) {
         // Check if option is checked
         if (is_array($this->value)) {
             $checked = (array_key_exists((string) $option['value'], $this->value) and $this->value[(string) $option['value']]);
         } else {
             $checked = (isset($option['default']) and (string) $option['default'] == 'checked');
         }
         $data[] = array('value' => (string) $option['value'], 'text' => (string) $option, 'checked' => $checked ? ' checked="checked"' : '');
     }
     return JSNTplFormHelper::checkbox($this->name, $data, $options);
 }
Ejemplo n.º 2
0
 /**
  * Parse field declaration to render input.
  *
  * @return  void
  */
 public function getInput()
 {
     // Make sure we have options declared
     if (!isset($this->element->option)) {
         return JText::_('JSN_TPLFW_ERROR_MISSING_OPTIONS');
     }
     // Get template data
     $data = JSNTplHelper::getEditingTemplate();
     // Initialize field value
     if (isset($data->params[(string) $this->element['name']])) {
         $this->value = $data->params[(string) $this->element['name']];
     } elseif (empty($this->value)) {
         $this->value = (string) $this->element['default'];
     }
     if (is_string($this->value)) {
         $this->value = (substr($this->value, 0, 1) == '{' and substr($this->value, -1) == '}') ? json_decode($this->value, true) : array($this->value => 1);
     }
     // Parse field attributes
     $options['class'] = isset($this->element['class']) ? (string) $this->element['class'] : '';
     $options['disabled'] = '';
     if (isset($this->element['disabled']) and $this->element['disabled'] == 'true') {
         $options['class'] .= ' disabled';
         $options['disabled'] = ' disabled="disabled"';
     }
     // Get all checkbox options from xml
     $data = array();
     foreach ($this->element->children() as $option) {
         // Check if option is checked
         if (is_array($this->value)) {
             $checked = (array_key_exists((string) $option['value'], $this->value) and $this->value[(string) $option['value']]);
         } else {
             $checked = (isset($option['default']) and (string) $option['default'] == 'checked');
         }
         $data[] = array('value' => (string) $option['value'], 'text' => (string) $option, 'checked' => $checked ? ' checked="checked"' : '');
     }
     return JSNTplFormHelper::checkbox($this->name, $data, $options);
 }