-
Notifications
You must be signed in to change notification settings - Fork 0
/
fond_membership_reepay.install
76 lines (71 loc) · 2.36 KB
/
fond_membership_reepay.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
/**
* @file
*/
/**
* Implements hook_enable().
*/
function fond_membership_reepay_enable()
{
// Adds invoice reference field on order entity.
_fond_membership_reepay_create_field('reepay_subscription_handle', 'commerce_order', 'commerce_order', 'Reepay Subscription Handle');
// Adds product reference field on product entity.
_fond_membership_reepay_create_field('reepay_plan_handle', 'commerce_product', 'membership', 'Reepay Plan Handle');
// Adds customer reference field on customer entity.
_fond_membership_reepay_create_field('reepay_contact_handle', 'commerce_customer_profile', 'billing', 'Reepay Contact Handle');
}
/**
* Utility function to create fields
*/
function _fond_membership_reepay_create_field($field_name, $entity_type, $bundle_name, $label)
{
$field = field_read_field($field_name);
if (empty($field)) {
$field = array(
'field_name' => $field_name,
'type' => 'text',
'cardinality' => 1,
'locked' => TRUE,
);
field_create_field($field);
}
$instance = field_info_instance($entity_type, $field_name, $bundle_name);
if (empty($instance)) {
// Create the instance on the bundle.
$instance = array(
'field_name' => $field_name,
'entity_type' => $entity_type,
'label' => $label,
'bundle' => $bundle_name,
'required' => FALSE,
'settings' => array(),
'widget' => array(
'type' => 'text_textfield',
),
'display' => array(
'default' => array(
'label' => 'hidden',
'type' => 'hidden',
),
),
);
field_create_instance($instance);
}
}
/**
* Implements hook_uninstall().
*/
function fond_membership_reepay_uninstall() {
variable_del('fond_membership_reepay_test');
variable_del('fond_membership_reepay_api_key');
// TODO What to do about the created fields?
}
/**
* Implements hook_update_N().
* Adds field on donation products.
*/
function fond_membership_reepay_update_7001()
{
_fond_membership_reepay_create_field('reepay_plan_handle', 'commerce_product', 'donation', 'Reepay Plan Handle');
_fond_membership_reepay_create_field('reepay_plan_handle', 'commerce_product', 'product', 'Reepay Plan Handle');
}