小编use*_*765的帖子

Drupal 7 hook_menu用于特定内容类型

我尝试将新选项卡添加到特定内容类型'abc',这是代码,但它不起作用,选项卡显示在所有节点上.任何人都可以帮忙吗?谢谢!

function addtabexample_menu() {
  $items=array();

  $items['node/%node/test'] = array(
  'title' => 'Test',
  'page callback' => 'handle_test',
  'page arguments' => array('node', 1),
  'access arguments' => array('access content'), 
  'type' => MENU_LOCAL_TASK,
  'weight' => 100,
  );
return $items;
}

function handle_test($node){

  $result='hi';
  if ($node->type == 'abc') {
    $result='I am working';
}
Run Code Online (Sandbox Code Playgroud)

drupal drupal-7 drupal-routes

11
推荐指数
1
解决办法
6293
查看次数

如何以编程方式将表单添加到Drupal 7中的节点?

我需要在Drupal 7中向节点添加一个程序化表单.如何将表单附加到节点?

function addtabexample_form($node, &$form_state) {
  $type = node_type_get_type($node);

  $form['title'] = array(
    '#type' => 'textfield', 
    '#title' => check_plain($type->title_label), 
    '#default_value' => !empty($node->title) ? $node->title : '', 
    '#required' => TRUE, 
    '#weight' => -5,
  );

  $form['field1'] = array(
    '#type' => 'textfield', 
    '#title' => t('Custom field'), 
    '#default_value' => $node->field1, 
    '#maxlength' => 127,
 );


  return $form;
}
Run Code Online (Sandbox Code Playgroud)

php drupal drupal-7 drupal-fapi drupal-forms

3
推荐指数
1
解决办法
6591
查看次数