You are here

function mailhandler_default_type in Mailhandler 7

Same name and namespace in other branches
  1. 6 mailhandler.module \mailhandler_default_type()

Return a default content type if the user has not chosen a specific type on the settings page In order of priority, return blog, story, page This assumes that one of these basic types is in use on a site (page and story are active by default) A user can choose other content types via the settings page as this exposes all available types

2 calls to mailhandler_default_type()
mailhandler_admin_settings in ./mailhandler.admin.inc
Return the settings page for mailhandler
mailhandler_node_prepare_message in ./mailhandler.module
Append default commands. Separate commands from body. Strip signature. Return a node object.

File

./mailhandler.module, line 191

Code

function mailhandler_default_type() {

  // Get the current default setting, if defined
  $default_type = variable_get('mailhandler_default_type', NULL);

  // Find out what types are available
  $available_types = node_get_types('names');

  // Check the default type is still available (it could have been deleted)
  if ($default_type && array_key_exists($default_type, $available_types)) {
    return $default_type;
  }

  // If we get here then either no default is set, or the default type is no longer available
  // Search for the array key (the machine readable name) for blog, story and page basic types
  if (array_key_exists('blog', $available_types)) {
    $default_type = 'blog';
  }
  else {
    if (array_key_exists('story', $available_types)) {
      $default_type = 'story';
    }
    else {
      if (array_key_exists('page', $available_types)) {
        $default_type = 'page';
      }
      else {

        // If basic types not found then return the first item from the array as an alternative default
        $default_type = key($available_types);
      }
    }
  }
  return $default_type;
}