You are here

function restful_token_auth_create_field_refresh_token in RESTful 7

Same name and namespace in other branches
  1. 7.2 modules/restful_token_auth/restful_token_auth.install \restful_token_auth_create_field_refresh_token()

Helper function to create the refresh token entity reference.

2 calls to restful_token_auth_create_field_refresh_token()
restful_token_auth_install in modules/restful_token_auth/restful_token_auth.install
Implements hook_install().
restful_token_auth_update_7100 in modules/restful_token_auth/restful_token_auth.install
Adds the refresh token entity reference.

File

modules/restful_token_auth/restful_token_auth.install, line 116
Install, update, and uninstall functions for the RESTful token authentication module.

Code

function restful_token_auth_create_field_refresh_token() {

  // Add an entity reference field to the access_token bundle to link to the
  // corresponding refresh token.
  $field_name = 'refresh_token_reference';
  $field = array(
    'entity_types' => array(
      'restful_token_auth',
    ),
    'settings' => array(
      'handler' => 'base',
      'target_type' => 'restful_token_auth',
      'handler_settings' => array(
        'target_bundles' => array(
          'refresh_token' => 'refresh_token',
        ),
      ),
    ),
    'field_name' => $field_name,
    'type' => 'entityreference',
    'cardinality' => 1,
  );
  field_create_field($field);
  $instance = array(
    'field_name' => $field_name,
    'bundle' => 'access_token',
    'entity_type' => 'restful_token_auth',
    'label' => t('Refresh token'),
    'description' => t('Token used to get a new access token once it is expired.'),
    'required' => FALSE,
  );
  field_create_instance($instance);
}