I want to add two new fields to the Commerce Discount entity --- an image and a long text. And I want these to be visible through Views.
I was going to use this code to add the fields:
http://www.monarchdigital.com/blog/2013-08-09/programmatically-creating-fields-drupal-7
But, I was thinking that there are already two fields attached to Node Bundles that do exactly what I want. All I really need to do is -copy- that field information to the Commerce Discount entity Bundles.
So I was thinking that this might do the trick, but I'm not
function() my_module_update_7000() {
// copy field info from existing entity
$field_name = 'field_page_banner';
$field = field_info_field($field_name)
field_create_field($field);
// copy field instance from existing entity $field_instance = field_info_instance('node', 'field_page_banner', 'page')
// ???? will this screw up the data in any existing bundles? $field_instance['entity_type'] = 'commerce_discount', $field_instance['bundle'] = array('order_discount', 'product_discount'),
field_create_instance($field_instance); }
Can someone look at this and let me know if I'm on the right track here? I'm not clear on how to assign the field to the new Bundle without 'un-assigning' it from the existing Bundles (if that makes sense.)
Is there anything else I need to do to make these fields available to add to existing Views?
Is there anything else I need to do to make these fields available to users when editing Commerce Discounts?
'fieldable'
key on the$entity
info "Set to TRUE if you want your entity type to accept fields being attached to it." api.drupal.org/api/drupal/modules%21system%21system.api.php/…