나는 새로운 모듈을 올바르게 빌드하기 위해 Drupal 7의 엔티티 및 필드 API를 사용하려고합니다. 문서에서 이해할 수 없었던 것은 새로운 API를 사용하여 Body와 같은 많은 수의 설정 필드가있는 '콘텐츠 유형'(노드 유형 아님)을 만드는 올바른 방법입니다.Drupal 7 엔티티 및 필드 API를 사용하는 올바른 방법
hook_entity_info를 사용하여 엔티티를 설정하려고하는데 field_create_instance를 사용하여 본문 필드를 추가해야한다고 생각합니다. 그러나 작동시키지 못합니다. mycontenttype.module에서
는 :
/**
* Implements hook_entity_info().
*/
function mycontenttype_entity_info() {
$return = array(
'mycontenttype' => array(
'label' => t('My Content Type'),
'controller class' => 'MyContentTypeEntityController',
'base table' => 'content_type',
'uri callback' => 'content_type_uri',
'entity keys' => array(
'id' => 'cid',
'label' => 'title',
),
'bundles' => array(
'mycontenttype' => array(
'label' => 'My Content Type',
'admin' => array(
'path' => 'admin/contenttype',
'access arguments' => array('administer contenttype'),
),
),
),
'fieldable' => true,
),
);
return $return;
}
/**
* Implements hook_field_extra_fields().
*/
function mycontenttype_field_extra_fields() {
$return['mycontenttype']['mycontenttype'] = array(
'form' => array(
'body' => array(
'label' => 'Body',
'description' => t('Body content'),
'weight' => 0,
),
),
);
return $return;
}
다음이는 .install 파일에 갈 않습니다
?function mycontenttype_install() {
$field = array(
'field_name' => 'body',
'type' => 'text_with_summary',
'entity_types' => array('survey'),
'translatable' => TRUE,
);
field_create_field($field);
$instance = array(
'entity_type' => 'mycontenttype',
'field_name' => 'body',
'bundle' => 'mycontenttype',
'label' => 'Body',
'widget_type' => 'text_textarea_with_summary',
'settings' => array('display_summary' => TRUE),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'text_default',
),
'teaser' => array(
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
),
),
);
field_create_instance($instance);
}
이 블로그 게시물을 할 수있다 유용하다. http://www.istos.it/blog/drupal-entities/drupal-entities-part-3-programming-hello-drupal-entity – bkildow