создать поле программно друпал 7

смотрим сюда = http://drupal.stackexchange.com/questions/8284/programmatically-create-fields-in-drupal-7
API для работы с полями в друпал - читаем здесь = http://api.drupal.org/api/drupal/modules!field!field.module/group/field/7

вот кусок кода - пример из comment.module - данная фукция создаёт поле комментария =

/**
 * Creates a comment_body field instance for a given node type.
 */
function _comment_body_field_create($info) {
  // Create the field if needed.
  if (!field_read_field('comment_body', array('include_inactive' => TRUE))) {
    $field = array(
      'field_name' => 'comment_body',
      'type' => 'text_long',
      'entity_types' => array('comment'),
    );
    field_create_field($field);
  }
  // Create the instance if needed.
  if (!field_read_instance('comment', 'comment_body', 'comment_node_' . $info->type, array('include_inactive' => TRUE))) {
    field_attach_create_bundle('comment', 'comment_node_' . $info->type);
    // Attaches the body field by default.
    $instance = array(
      'field_name' => 'comment_body',
      'label' => 'Comment',
      'entity_type' => 'comment',
      'bundle' => 'comment_node_' . $info->type,
      'settings' => array('text_processing' => 1),
      'required' => TRUE,
      'display' => array(
        'default' => array(
          'label' => 'hidden',
          'type' => 'text_default',
          'weight' => 0,
        ),
      ),
    );
    field_create_instance($instance);
  }
}

единственный "внешний " параметр здесь - это $info , который передаётся в функцию из comment_node_type_insert() - расположенную в том же файле с кодом, при этом последняя в данном файле ни разу не вызывается - дело в том , что это реализация такого вот хука

фактически - реализация данного хука позволяет добавить поле комментариев к новым типам контента в момент их создания.

также смотрим эти ссылки =

  • тема на форуме = http://drupal.org/node/1751298
  • работа с полями в друпал 7 = http://ado.io/blog/drupal-7/working-programmatically-with-fields-in-drupal-7
  • ещё пример программного добавления оля в друпал 7 = http://drupal.stackexchange.com/questions/25981/how-to-add-field-programmatically-in-drupal-7-with-dynamic-content-value
    • И ВООБЩЕ - ВСЕ ЭТИ = http://www.google.ru/#hl=ru&newwindow=1&sclient=psy-ab&q=drupal%207%20add%20field%20programmatically&oq=&gs_l=&pbx=1&bav=on.2,or.r_gc.r_pw.r_qf.&fp=d27b0c800978b39e&biw=1330&bih=633&pf=p&pdl=300

Ещё полезные ссылки =

Comments

http://drupal.stackexchange.com/questions/25981/how-to-add-field-programmatically-in-drupal-7-with-dynamic-content-value

вот ещё полезный пример = http://numiko.com/labs/2011/programmatically-adding-a-node-reference-field-to-a-type-in-drupal-7/