// 语言字串,除了可以获取对应语言外,还可以设置字串变量。可以是@var或 %var,%var就添加元素外层
t('my name is @name', array('@name' => 'willam'));
// 一个链接
l('User Edit', 'user/1/edit');
drupal_is_front_page();
$GLOBALS['base_url'] // URL root
GLOBAL 文档
module_load_include('inc', 'mymodule', 'mymodule.field');
getcwd()
DRUPAL_ROOT
把URI(public://)地址转换为绝对地址
drupal_realpath('public://xxx.csv'); // 得到系统路径
file_create_url('public://xxx.csv'); // 得到URL
drupal_add_js('misc/collapse.js');
drupal_add_js('misc/collapse.js', 'file');
drupal_add_js(drupal_get_path('module', 'content_glider'). '/srcipt.js');
drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });', 'inline');
drupal_add_js('jQuery(document).ready(function () { alert("Hello!"); });',
array('type' => 'inline', 'scope' => 'footer', 'weight' => 5)
);
drupal_add_js('http://example.com/example.js', 'external');
drupal_add_js(array('myModule' => array('key' => 'value')), 'setting');
https://drupal.org/node/756722
Drupal.attachBehaviors(document);
drupal_add_library('system', 'ui.tabs');
SELECT * FROM dp_menu_router where path='admin/config/search/path/patterns'
drupal_goto('node/1');
drupal_goto(current_path());
drupal_not_found(); // 跳转到404页面
drupal_goto('<front>', array(), 301); // 301跳转
arg(1); // 提取URL第2个参数,例如node/1,会提取1
$_GET['q']; // 得到当前URL路径
url('node/1'); // 网站相对地址
url('node/1', array('absolute' => true); // 绝对地址
url('' , array('query' => 'action=do', 'fragment' => 'top'));
image_style_url('image_style_name', $node->field_image[LANGUAGE_NONE][0]['uri']); // 图片URL
format_date($timestamp, $type = 'custom', $format = '');
strtotime('2013-6-5 20:11');
echo drupal_json(array('xxx'));
drupal_json_output(array('xxx'));
drupal_exit();得到请求
arg(1); // 得到URI的第二个值
任何表单,只要在URL上加?destination=xxx,提交后都会跳转到相应地址
url('xxx',
array('query' => array('destination' => 'yyyy'))
);
drupal_goto('user', array('query' => array('destination'=>'user/myorder')));
drupal_goto(drupal_get_destination());
watchdog('event_type', 'name is :name', array(':name' => $name), WATCHDOG_WARNING);
file_load($fid)->uri;
file_move($file, 'public://xxx/');
file_copy($file, 'public://xxx/');
file_delete($file);
http://drupal.org/node/1537950
$form = array();
field_attach_form('profile2', profile2_load_by_user($user, 'general'),$form, $form_state);
// node
field_attach_form('node', $node, $form, $form_state);
注意$form_state必须是form参数$form_state的原变量,clone的会报错。执行后会填充$form变量,可以附加到当前的form中。
如果想只提取部分的field,可以使用multiple_entity_form module。
element可以互相嵌套,通过render可以把element转换为HTML,而render之前,element只是一个大型数组,一般的数组操作很难区分element部分,所以可以用element_children:
foreach (element_children($element) as $key) {
$sub_element[]= $element[$key];
}
$static = &drupal_static(__FUNCTION__, array());
$cache_key = md5(serialize($values));
if($cached = cache_get($cache_key)) {
$data = $cached->data;
} else {
$data = getData();
cache_set($cache_key, $data);
}
drupal_session_start();
$_SESSION[$key] = $value;
hook_username_alter();
format_username($account); // 显示用户名
function topaz_financial_preprocess_html(&$variables, $hook){
if(!drupal_match_path(current_path(), '' ) && !(user_access("administer users") || drupal_match_path(current_path(), "user\nuser/*"))) {
if(module_exists('search404')) {
search404_goto("" );
} else {
drupal_goto('' , array(), 301);
}
}
}
$language = i18n_language_interface();
$lang = $language->language;
drupal_lookup_path('alias',"node/".$node->nid);