0

Had a Drupal site that used the php filter module. After realizing the security risk I started the process of fixing things up.

Currently the last piece of code is a php snippet I embedded into a view to display the input fields of a content type (called post).

<?php 
  module_load_include('inc', 'node', 'node.pages');
  $node_form = node_add('post');
  print drupal_render($node_form);
  $form['buttons']['submit']['#value'] = t('Save and add new');
?>

This is a view block embedded within a panel. Not 100% sure how to take this and make it a custom module that I suppose cloud be a block for me to embed on the panel page.

Update: Attempted to make the module using hook_block_configure() but when enabled it is not showing up as a block option for me to embed.

<?php

/**
 * Implements hook_block_configure().
 */

function hook_block_configure($delta = '') {

  module_load_include('inc', 'node', 'node.pages');
  $node_form = node_add('post');
  print drupal_render($node_form);
  $form['buttons']['submit']['#value'] = t('Save and add new');

}

Is the correct command being used?

0

I don't really think embedding a node form in a node view is good in terms of performance because the entire node form needs to be rebuilt, and it can interferer caching mechanisms as well. Probably a ctools madal form with Ajax will do the job better.

You can define blocks in your site using a custom module. Panels will pick them up without any further integration.

function MYMODULE_block_info() {
  $blocks['MYMODULE_post_node_form'] = array(
    'info' => t('Add new'),
    'cache' => DRUPAL_NO_CACHE,
  );

  return $blocks;
}


function MYMODULE_block_view($delta = '') {
  $block = array();

  switch ($delta) {
    case 'MYMODULE_post_node_form':
      module_load_include('inc', 'node', 'node.pages');
      $node_form = node_add('post');
      $node_form['buttons']['submit']['#value'] = t('Save and add new'); 
      $block['content'] = $node_form; // No need to render() here. Will happen automatically.
      break;
  }

  return $block;
}

I'm assuming you know how to create a basic module with an .info file, change "MYMODULE" to the module name of your choice and how to install them. If everything went OK, you will see the "Add new" block in admin/structure/blocks page and in "Add content" form in panels.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy