function commerce_message_message_field_refresh in Commerce Message 7
Refresh the fields attached to the message types we support.
1 call to commerce_message_message_field_refresh()
- commerce_message_flush_caches in ./
commerce_message.module - Implements hook_flush_caches().
File
- includes/
commerce_message.message.inc, line 260
Code
function commerce_message_message_field_refresh() {
$fields['message_commerce_order']['field'] = array(
'type' => 'entityreference',
'module' => 'entityreference',
'cardinality' => '1',
'translatable' => FALSE,
'settings' => array(
'target_type' => 'commerce_order',
'handler' => 'base',
'handler_settings' => array(
'target_bundles' => array(),
'sort' => array(
'type' => 'property',
'property' => 'order_id',
'direction' => 'ASC',
),
),
),
'locked' => TRUE,
);
$bundles = array(
'commerce_order_created',
'commerce_order_state',
'commerce_order_payment_entered',
'commerce_order_payment_full',
'commerce_order_cart_add',
'commerce_order_cart_remove',
'commerce_order_user_comment',
'commerce_order_admin_comment',
'commerce_order_order_confirmation',
'commerce_order_admin_order_confirmation',
);
$fields['message_commerce_order']['instances'][] = array(
'entity_type' => 'message',
'bundles' => $bundles,
'label' => 'Order',
'required' => TRUE,
'widget' => array(
'type' => 'entityreference_autocomplete',
'module' => 'entityreference',
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => '60',
'path' => '',
),
),
'settings' => array(),
'display' => array(
'default' => array(
'label' => 'above',
'type' => 'entityreference_label',
'settings' => array(
'link' => FALSE,
),
'module' => 'entityreference',
'weight' => 0,
),
),
);
$fields['message_commerce_line_item']['field'] = array(
'type' => 'entityreference',
'module' => 'entityreference',
'cardinality' => '1',
'translatable' => FALSE,
'settings' => array(
'target_type' => 'commerce_line_item',
'handler' => 'base',
'handler_settings' => array(
'target_bundles' => array(),
'sort' => array(
'type' => 'property',
'property' => 'line_item_id',
'direction' => 'ASC',
),
),
),
'locked' => TRUE,
);
$fields['message_commerce_line_item']['instances'][] = array(
'entity_type' => 'message',
'bundles' => array(
'commerce_order_cart_add',
'commerce_order_cart_remove',
),
'label' => 'Line item',
'required' => TRUE,
'widget' => array(
'type' => 'entityreference_autocomplete',
'module' => 'entityreference',
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => '60',
'path' => '',
),
),
'settings' => array(),
'display' => array(
'default' => array(
'label' => 'above',
'type' => 'entityreference_label',
'settings' => array(
'link' => FALSE,
),
'module' => 'entityreference',
'weight' => 0,
),
),
);
$fields['message_commerce_payment']['field'] = array(
'type' => 'entityreference',
'module' => 'entityreference',
'cardinality' => '1',
'translatable' => FALSE,
'settings' => array(
'target_type' => 'commerce_payment_transaction',
'handler' => 'base',
'handler_settings' => array(
'target_bundles' => array(),
'sort' => array(
'type' => 'property',
'property' => 'transaction_id',
'direction' => 'ASC',
),
),
),
'locked' => TRUE,
);
$fields['message_commerce_payment']['instances'][] = array(
'entity_type' => 'message',
'bundles' => array(
'commerce_order_payment_entered',
),
'label' => 'Line item',
'required' => TRUE,
'widget' => array(
'type' => 'entityreference_autocomplete',
'module' => 'entityreference',
'settings' => array(
'match_operator' => 'CONTAINS',
'size' => '60',
'path' => '',
),
),
'settings' => array(),
'display' => array(
'default' => array(
'label' => 'above',
'type' => 'entityreference_label',
'settings' => array(
'link' => FALSE,
),
'module' => 'entityreference',
'weight' => 0,
),
),
);
$fields['message_commerce_body']['field'] = array(
'type' => 'text_long',
'module' => 'text',
'cardinality' => '1',
'translatable' => FALSE,
'settings' => array(),
'locked' => TRUE,
);
$bundles = array(
'commerce_order_user_comment',
'commerce_order_admin_comment',
);
$fields['message_commerce_body']['instances'][] = array(
'entity_type' => 'message',
'bundles' => $bundles,
'label' => 'Message',
'required' => TRUE,
'widget' => array(
'type' => 'text_textarea',
'module' => 'text',
'settings' => array(
'rows' => '3',
),
),
'settings' => array(
'text_processing' => TRUE,
),
'display' => array(
'default' => array(
'label' => 'above',
'type' => 'text_default',
'settings' => array(),
'module' => 'text',
'weight' => 1,
),
),
);
drupal_alter('commerce_message_message_fields', $fields);
// Create the missing fields.
foreach ($fields as $field_name => $info) {
$field = $info['field'];
$field += array(
'field_name' => $field_name,
);
if (!field_info_field($field_name)) {
field_create_field($field);
}
foreach ($info['instances'] as $instance) {
foreach ($instance['bundles'] as $bundle) {
$instance['bundle'] = $bundle;
unset($instance['bundles']);
$instance['field_name'] = $field_name;
if (!field_info_instance($instance['entity_type'], $instance['field_name'], $instance['bundle'])) {
field_create_instance($instance);
}
}
}
}
}