You are here

function hansel_action_add_link_to_nodetype_get_crumbs in Hansel breadcrumbs 7

Same name and namespace in other branches
  1. 8 hansel.actions.inc \hansel_action_add_link_to_nodetype_get_crumbs()

Callback for the "add link to nodetype" breadcrumb action to generate the crumbs.

Parameters

array $arguments:

Return value

array

1 string reference to 'hansel_action_add_link_to_nodetype_get_crumbs'
hansel_hansel_action_types in ./hansel.module
Implements hook_hansel_action_types().

File

./hansel.actions.inc, line 124
Hansel breadcrumb actions

Code

function hansel_action_add_link_to_nodetype_get_crumbs($arguments) {
  if (drupal_strtolower(hansel_arg(0)) == 'node' && is_numeric(hansel_arg(1))) {
    if ($node = node_load(hansel_arg(1))) {
      $type = $node->type;
    }
  }
  elseif (drupal_strtolower(hansel_arg(0)) == 'node' && drupal_strtolower(hansel_arg(1)) == 'add') {

    // Nodetypes may not contain hyphens. So it's same to assume that all hyphens are underscores.
    $type = str_replace('-', '_', hansel_arg(2));
  }
  if (!empty($type)) {
    $path = isset($arguments['path']) ? $arguments['path'] : 'node/add/[type]';
    $path = str_replace('[type]', str_replace('_', '-', $type), $path);
    $path = str_replace('[type-raw]', $type, $path);
    $node = new stdClass();
    $node->type = $type;
    if ($title = node_type_get_name($node)) {
      return array(
        array(
          'title' => t($title),
          'href' => $path,
        ),
      );
    }
  }
  return array();
}