You are here

function token_custom_save in Custom Tokens 7

Same name and namespace in other branches
  1. 7.2 token_custom.module \token_custom_save()

Saves a token to the database.

Parameters

$token: An object or an array containing the values to save. The key 'is_new' determines if the token is being inserted or updated

Return value

bool

1 call to token_custom_save()
token_custom_edit_form_submit in ./token_custom.admin.inc
Submit handler for the custom token admin form.

File

./token_custom.module, line 158
It gives the user the ability to create custom tokens using PHP code for specific replacements that can improve other modules relying on the token Drupal 7 core API.

Code

function token_custom_save($token) {
  $is_new = is_object($token) ? (bool) $token->is_new : !empty($token['is_new']);
  $return = (bool) drupal_write_record('token_custom', $token, $is_new ? array() : 'machine_name');

  //Clear the Token module's token cache table.
  if (module_exists('token')) {
    token_clear_cache();
  }
  return $return;
}