You are here

function formblock_get_block in Form Block 7

Same name and namespace in other branches
  1. 5 formblock.module \formblock_get_block()
  2. 6 formblock.module \formblock_get_block()

Generate a block containing a node entry form.

1 call to formblock_get_block()
formblock_block_view in ./formblock.module
Implements hook_block_view().

File

./formblock.module, line 122

Code

function formblock_get_block($type) {
  if (node_access('create', $type) && variable_get('formblock_expose_' . $type, 0)) {
    $block = array();

    // Include page handler for node_add()
    module_load_include('inc', 'node', 'node.pages');

    // Note title before rendering of form.
    $title = drupal_get_title();
    $form = node_add($type);

    // Restore title, which will have been overridden.
    drupal_set_title($title, PASS_THROUGH);

    // Get the help
    $node_type = node_type_load($type);
    if (variable_get('formblock_show_help_' . $type, 0)) {
      $block['content']['help'] = array(
        '#markup' => !empty($node_type->help) ? '<p>' . filter_xss_admin($node_type->help) . '</p>' : '',
      );
    }

    // Add our CSS
    $block['content']['#attached']['css'][] = drupal_get_path('module', 'formblock') . '/formblock.css';
    $block['subject'] = t('@type form', array(
      '@type' => $node_type->name,
    ));
    $block['content']['form'] = $form;
    return $block;
  }
}