Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9182543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:35:03+00:00 2026-06-17T18:35:03+00:00

I use drupal 7, and Entity API to develope a module. I have an

  • 0

I use drupal 7, and Entity API to develope a module. I have an entity to record client information. I wish to use image_field to let client upload their logo. So I have this function:

    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);
}

In the entity creation/edit form, I use :

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

to attch the field.

When I called up this form, the image upload field was corrected displayed. An i can use it to uplod file to serve.

In the form submit function, I save the entity as:

entity_save('silver_client', $client);

However, after I press the save button, the entity table is correctly saved. Field table is not. Both field_data_logo and field_revision_logo are empty.

I believer Entity API looks after the retrieving and saving of attached fields. Can someone tell me what is wrong with my code? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:35:04+00:00Added an answer on June 17, 2026 at 6:35 pm

    You have to write the values back into your entity:

    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

    And you should validate the field values:

    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

    Furthermore if you don’t want to declare your entity and fields by yourself you might checkout the EntityConstructionKit : http://drupal.org/project/eck which allows to export entity structures with Features just like Views.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I quite often use Drupal's Views Module to build SQL that I paste into
I'm try to use drupal open id module. When i used to login using
How would I be able to use the Drupal Fivestar voting module for voting
Situation: In Drupal, when you use Views module, it restricts to display Search Form
I need to use Drupal 6's hook_user to update a 3rd party API whenever
We are putting together a website for a client and their IT Team have
I asked this question about reasons to use Drupal 7's Forms API as opposed
I have a master copy of a Drupal site and for each client I
I use Drupal 5 with Ubercart 1 (latest) and uc_subscribe module. I see in
I have an application with a Java back-end. I wanted to use Drupal CMS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.