如何创建在Drupal形式下拉列表中所有语言的数组

如何创建在Drupal形式下拉列表中所有语言的数组

本文介绍了如何创建在Drupal形式下拉列表中所有语言的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为我的Drupal形式的所有语言创建下拉列表中,是否有任何PHP函数来实现这一目标。我想创建的所有语言的数组,并把它传递给Drupal的形式。

I need to create dropdown list for all languages in my Drupal form, Is there any function in PHP to achieve this. I want to create an array of all languages and pass it to drupal form.

function video_upload_subtitles_form($form, &$form_state) {
 $form = array('#attributes' => array('enctype' => 'multipart/form-data'));
 $lang_list = array();//**how to create this array**
 $form['video_name'] = array(
    '#title' => t('Name Of the video'),
    '#type' => 'textfield',
 );

 $form['sub_file'] = array(
        '#type' => 'file',
        '#title' => t('Upload video'),
        '#description' => t('Pick a video file to upload.'),
    );
$form['user_list']=array(
    '#type'=>'select',
    '#title' => t('Language'),
    '#options' => $lang_list,//array of language
    '#multiple' => false,
    '#attributes'=>array('size'=>4),
    '#weight'=>8,
);
 $form['submit_button'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
 );

 return $form;

}

我知道语言的上市可以在PHP通过列出并手动制作阵列但有可能与任何PHP函数做的,只是在寻找一些简单的方法来节省时间来完成。

I know listing of language can be done in php by listing and making a array manually but is it possible to do with any php function, just looking for some easy way to save time.

对于得到这个很酷的网站。有什么像这样的语言

Got this cool website for Country List . Is there anything for the Language like this

推荐答案

试试这个,

    $select = db_select('Your table name', 's');
    $select = $select->fields('s',array('languages_name','id'));
    // 'languages_name' , 'id' this is a column
    $queried_nodes = $select->execute()
    ->fetchAllAssoc('id');
    $lang_list = array();
    foreach ($queried_nodes as $result)
    {
       $lang_list[$result->languages_name] = t($result->languages_name);
    }

后,设置$ lang_list变量

after set a $lang_list variable

$form['user_list']=array(
     '#type'=>'select',
     '#title' => t('Language'),
     '#options' => $lang_list,//array of language
     '#multiple' => false,
     '#attributes'=>array('size'=>4),
     '#weight'=>8,
);

你是创建一个新的语言表或内容类型和使用一个Drupal内置的语言列表,以便尝试这个code。

you are create a new Language table or content types and you use a drupal inbuilt language list so try this code.

  include_once DRUPAL_ROOT . '/includes/iso.inc';
  $lang = _locale_get_predefined_list();

  $lang_list = array();

  foreach ($lang as $key => $value)
  {
    $lang_list[$value[0]] = t($value[0]);
  }

使用后 $ lang_list varible形式API

after use a $lang_list varible in form api

这篇关于如何创建在Drupal形式下拉列表中所有语言的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 23:27