Create Custom Block for entityform

Entityform

Entityform one the best module which is used to create entity-form. Why we call it entity-form while there is already a contributed module available, called "Webform" which is used to create forms. Entity form is better than webform because you can reuse fields in entityfom and it can be used with any entity API like

  • Views
  • Rules
  • Entity Reference
  • Organic Groups many more...


How to call an entity form in a custom block?
Sometimes we have a situation when we want to call an entity form in block and we can call this custom block in any region in our Drupal website/instance e.g we want to create a custom block name "test_form" (and we will follow these steps to create a module for custom block) in which we will call entity form.

So our first thing is to do is create an entity form called test contact form under

  admin->structure->Entiyform Type-> Add Entityform Type

Now goto to your root folder and create a directory called test_form under root folder->sites->all->module->test_form and create info and module files in it. Now open test_form.info and put this code in it.


name = Test Entityform Blocks 
description = Custom blocks for Entityform. 
core = 7.x 
version = 7.x-1.0 
 

Now open test_form.module file and paste this code in it.

/** * Implements hook_block_info(). */ 
function test_form_block_info() { 
  $blocks = array(); 
  $blocks['test_contact_forms'] = array( 
    'info' => t('Entity Contact Form'), 
  ); 
  return $blocks; 
} 

/** * Implements hook_block_view(). */ 
function test_form_block_view($delta = '') { 
  $block = array(); 
  switch($delta) { 
    case 'test_contact_forms': 
      $block['subject'] = ''; 
      $block['content'] = _test_blocks_contact_forms(); 
      break; 
   } 
  return $block; 
} 

/** * Function to return form in a custom block. */ 
function _test_blocks_contact_forms() { 
  module_load_include('inc', 'entityform', 'entityform.admin'); 
  $entity_form_name = 'test_contact_form'; 
  $render_estimate_form = entityform_form_wrapper(entityform_empty_load($entity_form_name), 'submit', 'embedded'); 
  return drupal_render($render_estimate_form); 
} 

After all this above thing just goto admin->Structure->Blocks and you will see your custom block in blocks listing.
Now you can call it in any region or in panels.