You are here

function invite_by_email_add_fields in Invite 7.4

Add fields.

2 calls to invite_by_email_add_fields()
invite_by_email_install in modules/invite_by_email/invite_by_email.install
Implements hook_install().
invite_by_email_update_7001 in modules/invite_by_email/invite_by_email.install
Implements hook_update_N().

File

modules/invite_by_email/invite_by_email.install, line 97
Install, update and uninstall functions for the Invite by e-mail.

Code

function invite_by_email_add_fields() {
  $fields = array(
    'field_invitation_email_address' => array(
      'definition' => array(
        'field_name' => 'field_invitation_email_address',
        'type' => 'text',
        'cardinality' => 1,
      ),
      'instance' => array(
        'field_name' => 'field_invitation_email_address',
        'entity_type' => 'invite',
        'label' => t('E-mail'),
        'bundle' => 'invite_by_email',
        'description' => t('Type the e-mail address of the person you wish to invite.'),
        'widget' => array(
          'type' => 'text_textfield',
          'weight' => 10,
        ),
        'display' => array(
          'default' => array(
            'type' => 'text_textfield',
            'weight' => 10,
          ),
        ),
      ),
    ),
    'field_invitation_email_subject' => array(
      'definition' => array(
        'field_name' => 'field_invitation_email_subject',
        'type' => 'text',
        'cardinality' => 1,
      ),
      'instance' => array(
        'field_name' => 'field_invitation_email_subject',
        'entity_type' => 'invite',
        'label' => t('Subject'),
        'bundle' => 'invite_by_email',
        'description' => t('Enter e-mail subject.'),
        'default_value' => array(
          array(
            'value' => variable_get('invite_default_mail_subject', ''),
          ),
        ),
        'widget' => array(
          'type' => 'text_textfield',
          'weight' => 20,
        ),
        'settings' => array(
          'text_processing' => 0,
        ),
        'format' => 'plain_text',
        'display' => array(
          'default' => array(
            'type' => 'text_textfield',
            'weight' => 20,
          ),
        ),
      ),
    ),
    'field_invitation_email_body' => array(
      'definition' => array(
        'field_name' => 'field_invitation_email_body',
        'type' => 'text_long',
        'cardinality' => 1,
      ),
      'instance' => array(
        'field_name' => 'field_invitation_email_body',
        'entity_type' => 'invite',
        'label' => t('Body'),
        'bundle' => 'invite_by_email',
        'description' => t('Enter e-mail body.'),
        'default_value' => array(
          array(
            'value' => variable_get('invite_default_mail_body', ''),
          ),
        ),
        'widget' => array(
          'type' => 'text_textarea',
          'weight' => 30,
        ),
        'settings' => array(
          'text_processing' => 0,
        ),
        'format' => 'plain_text',
        'display' => array(
          'default' => array(
            'type' => 'text_textarea',
            'weight' => 30,
          ),
        ),
      ),
    ),
  );
  foreach ($fields as $field) {
    $info = field_read_field(array(
      'field_name' => $field['definition']['field_name'],
    ));
    if (empty($info)) {
      field_create_field($field['definition']);
    }

    // Ensure that field wasn't added previously.
    $prior_instance = field_read_instance($field['instance']['entity_type'], $field['instance']['field_name'], $field['instance']['bundle']);
    if (!$prior_instance) {
      field_create_instance($field['instance']);
    }
  }
}