/**
 * Zikula_View function to display a drop down list of languages
 *
 * Available parameters:
 *   - assign:   If set, the results are assigned to the corresponding variable instead of printed out
 *   - name:     Name for the control
 *   - id:       ID for the control
 *   - selected: Selected value
 *   - installed: if set only show languages existing in languages folder
 *   - all:      show dummy entry '_ALL' on top of the list with empty value
 *
 * Example
 *   {html_select_languages name=language selected=en}
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the Zikula_View object.
 *
 * @deprecated smarty_function_html_select_locales()
 * @return string The value of the last status message posted, or void if no status message exists.
 */
function smarty_function_html_select_languages($params, Zikula_View $view)
{
    if (!isset($params['name']) || empty($params['name'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('html_select_languages', 'name')));
        return false;
    }
    require_once $view->_get_plugin_filepath('function', 'html_options');
    $params['output'] = array();
    $params['values'] = array();
    if (isset($params['all']) && $params['all']) {
        $params['values'][] = '';
        $params['output'][] = DataUtil::formatForDisplay(__('All'));
        unset($params['all']);
    }
    if (isset($params['installed']) && $params['installed']) {
        $languagelist = ZLanguage::getInstalledLanguageNames();
        unset($params['installed']);
    } else {
        $languagelist = ZLanguage::languageMap();
    }
    $params['output'] = array_merge($params['output'], DataUtil::formatForDisplay(array_values($languagelist)));
    $params['values'] = array_merge($params['values'], DataUtil::formatForDisplay(array_keys($languagelist)));
    $assign = isset($params['assign']) ? $params['assign'] : null;
    unset($params['assign']);
    $html_result = smarty_function_html_options($params, $view);
    if (!empty($assign)) {
        $view->assign($assign, $html_result);
    } else {
        return $html_result;
    }
}
Esempio n. 2
0
 /**
  * Load event handler.
  *
  * @param Zikula_Form_View $view Reference to Zikula_Form_View object.
  * @param array            &$params Parameters passed from the Smarty plugin function.
  *
  * @return void
  */
 public function load(Zikula_Form_View $view, &$params)
 {
     if ($this->mandatory) {
         $this->addItem('---', null);
     }
     if ($this->addAllOption) {
         $this->addItem(DataUtil::formatForDisplay(__('All')), '');
     }
     if ($this->onlyInstalledLanguages) {
         $langList = ZLanguage::getInstalledLanguageNames();
         foreach ($langList as $code => $name) {
             $this->addItem($name, $code);
         }
     } else {
         $langList = ZLanguage::languageMap();
         foreach ($langList as $code => $name) {
             $this->addItem($name, $code);
         }
     }
     parent::load($view, $params);
 }
Esempio n. 3
0
 public function getAddLanguageSelectData($all = false)
 {
     $languages_map = \ZLanguage::languageMap();
     if ($all) {
         return $languages_map;
     } else {
         return array_diff_key($languages_map, $this->installed);
     }
 }
Esempio n. 4
0
 /**
  * Checks if string field value is a valid language code.
  *
  * @param string  $fieldName     The name of the property to be checked
  * @param boolean $onlyInstalled Whether to accept only installed languages (default false)
  * @return boolean result of this check
  */
 public function isValidLanguage($fieldName, $onlyInstalled = false)
 {
     $languageMap = ZLanguage::languageMap();
     $result = in_array($this->entity[$fieldName], array_keys($languageMap));
     if (!$result || !$onlyInstalled) {
         return $result;
     }
     $available = ZLanguage::getInstalledLanguages();
     return in_array($this->entity[$fieldName], $available);
 }