You are here

function token_custom_save in Custom Tokens 7.2

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

Saves a token to the database.

Parameters

object|array $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 True on success.

2 calls to token_custom_save()
token_custom_edit_form_submit in ./token_custom.admin.inc
Submit handler for the custom token admin form.
token_custom_type_delete in ./token_custom.module
Delete token type.

File

./token_custom.module, line 331
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;
}