You are here

function node_limit_message in Node Limit 7

Display message for user and redirect based on node limit settings.

Parameters

string $nodetype: Load current node type object.

2 calls to node_limit_message()
node_limit_init in ./node_limit.module
Implements hook_init().
node_limit_node_prepare in ./node_limit.module
Implements hook_node_prepare().

File

./node_limit.module, line 798

Code

function node_limit_message($nodetype) {

  // Check if enabled custom message option.
  $custom_msg = variable_get('node_limit_custom_msg', NULL);
  if ($custom_msg) {

    // Get settings of node type.
    $settings = variable_get('node_limit_settings_' . $nodetype->type);

    // Get redirect path.
    $redirect_path = $settings['redirect_' . $nodetype->type];

    // Format text.
    $text = t($settings['message_' . $nodetype->type], array(
      '[node_limit:type_title]' => check_plain($nodetype->name),
      '[node_limit:type_name]' => $nodetype->type,
    ));
  }
  else {

    // Get global text message and redirect.
    $text = variable_get('node_limit_global_msg', t("You can't create more content of type [node_limit:type_title]"));
    $redirect_path = variable_get('node_limit_global_redirect', NULL);

    // Format text.
    $text = t($text, array(
      '[node_limit:type_title]' => check_plain($nodetype->name),
      '[node_limit:type_name]' => $nodetype->type,
    ));
  }

  // Display message for user.
  drupal_set_message($text, 'error');

  // Redirect user if it exist.
  if ($redirect_path != NULL) {
    drupal_goto($redirect_path);
  }
}