You are here

function command_buttons_create_node_button in Command Buttons 7

Create a node add button based on the node type and label.

Parameters

$type: The machine name of the content type you are creating a button for.

$label: The label of the content type you are creating a button for.

3 calls to command_buttons_create_node_button()
command_buttons_modules_enabled in ./command_buttons.module
Implements hook_modules_enabled().
command_buttons_node_type_insert in ./command_buttons.module
Implements hook_node_type_insert().
command_buttons_update_7108 in ./command_buttons.install
Create buttons for all node types.

File

./command_buttons.module, line 176

Code

function command_buttons_create_node_button($type, $label) {
  $new_buttons = array();

  // Create node/add buttons for the new node type.
  if (!command_buttons_machine_name_exists($type)) {
    $type_url_str = str_replace('_', '-', $type);
    $values = array(
      'bundle' => 'node_add',
      'name' => $type,
      'title' => t('Create !title', array(
        '!title' => $label,
      )),
      'language' => LANGUAGE_NONE,
      'field_command_link' => array(
        LANGUAGE_NONE => array(
          array(
            'url' => 'node/add/' . $type_url_str,
            'title' => 'Create ' . $label,
          ),
        ),
      ),
    );
    $new_buttons[$type] = command_buttons_create($values);
  }
  if (count($new_buttons)) {
    drupal_alter('command_buttons_node_buttons', $new_buttons);

    // All buttons may have been removed, so check once again.
    if (count($new_buttons)) {
      foreach ($new_buttons as $new_button) {
        command_buttons_save($new_button);
      }
    }
  }
}