2013-01-24 2 views
0

저는 Drupal 7 및 Entity API를 사용하여 모듈을 개발합니다. 클라이언트 정보를 기록 할 엔티티가 있습니다. 클라이언트가 로고를 업로드 할 수 있도록 image_field를 사용하고 싶습니다. 내가 사용하는 엔티티 생성/편집 양식에서drupal의 엔티티에 image_field를 첨부하십시오.

function silver_client_enable() 
{ 
    field_cache_clear(); 
    field_associate_fields("silver_client"); 

    if(field_info_field('logo')) 
    return; 

    $field = array(
    'field_name' => 'logo', 
    'cadinality' => 1, 
    'type' => 'image', 
    ); 

    field_create_field($field); 

    $instance = array(
    'field_name' => 'logo', 
    'entity_type' => 'silver_client', 
    'bundle' => 'silver_client', 
    'label' => 'Logo', 
    'description' => 'Logo', 
    'display' => array(
     'default' => array('label' => 'hidden') 
    ), 
    'settings' => array(
     'file_directory' => '/logo', 
    ), 
    'widget' => array(
     'type' => 'image_image', 
    ), 
); 

    field_create_instance($instance); 
} 

:

field_attach_form('silver_client', $client, $form, $form_state); 

필드 attch하는 그래서 나는이 기능을 가지고있다.

이 양식을 불러 오면 이미지 업로드 필드가 수정되었습니다. 내가 uplod 파일을 제공하는 데 사용할 수 있습니다. 기능을 제출 양식에

, 나는 같은 엔티티 저장 : 내가 저장 버튼을 누른 후, 그러나

entity_save('silver_client', $client); 

을, 엔티티 테이블이 제대로 저장됩니다. 필드 테이블이 아닙니다. field_data_logo 및 field_revision_logo는 모두 비어 있습니다.

I believer Entity API는 첨부 된 필드의 검색 및 저장을 관리합니다. 누군가 내 코드에 어떤 문제가 있다고 말할 수 있습니까? 고맙습니다.

답변

0

당신은 다시 개체에 값을 작성해야합니다 :

field_attach_submit('silver_client', $client, $form, $form_state); 
entity_save('silver_client', $client); 

http://api.drupal.org/api/drupal/modules!field!field.attach.inc/function/field_attach_submit/7

그리고 당신은 필드 값의 유효성을 검사해야합니다 또한

field_attach_validate('silver_client', $client, $form, $form_state); 

http://api.drupal.org/api/drupal/modules!field!field.attach.inc/function/field_attach_validate/7

당신의 경우를 엔티티와 f를 선언하고 싶지 않다. 너 자신에 의해 EntityConstructionKit : Views과 같이 Features 인 엔티티 구조를 내보낼 수있는 http://drupal.org/project/eck을 체크 아웃 할 수 있습니다.

+0

저는 이것을 직접 해결하고 싶습니다. 제출 기능에서 함수 : entity_form_submit_build_entity ('silver_client', $ client, $ form, $ form_state); 을 호출해야합니다. 그것이 없으면 값은 form_state에서 온 것입니다. –

+0

감사합니다. Ghommey. 필자의 원래 코드에서는 field_attach_submit을 사용했지만 entity_save 뒤에 입력했습니다. 나는이 기능의 의도를 정말로 이해하지 못했다. 이제 보았을 때 실제로 form_state의 필드 값을 엔티티 객체에 넣었습니다. 그래서이 값들은 나중에 저장 될 수 있습니다. –

+0

내가 도와 줘서 다행이다 :) – jantimon

관련 문제