by joachim: Fixed loading of all entityform types; fixes bug with block not showing...
[sandbox/joachim/2045865.git] / entityform_block.module
1 <?php
2
3 /**
4 * @file entityform_block.module
5 * Provides blocks for entity form types.
6 */
7
8 /**
9 * Implements hook_block_info().
10 */
11 function entityform_block_block_info() {
12 $blocks = array();
13 foreach (entityform_get_types() as $entityform_type) {
14 if (!empty($entityform_type->data['block_enable'])) {
15 $blocks[$entityform_type->type] = array(
16 'info' => t('Entityform: ' . $entityform_type->label()),
17 // DRUPAL_CACHE_PER_ROLE will be assumed.
18 );
19 }
20 }
21
22 return $blocks;
23 }
24
25 /**
26 * Implements hook_block_view().
27 */
28 function entityform_block_block_view($delta = '') {
29 module_load_include('inc', 'entityform', 'entityform.admin');
30
31 $block = array();
32 $entityform_type = entityform_get_types($delta);
33 if (!empty($entityform_type)) {
34 $block['subject'] = $entityform_type->label();
35 $block['content'] = entityform_form_wrapper(entityform_empty_load($entityform_type->type), 'submit', 'embedded');
36 }
37
38 return $block;
39 }
40
41 /**
42 * Implements hook_form_FORM_ID_alter(): entityform_type_form.
43 */
44 function entityform_block_form_entityform_type_form_alter(&$form, &$form_state, $form_id) {
45 $entityform_type = $form['#entityform_type'];
46
47 $form['data']['block_set'] = array(
48 '#type' => 'fieldset',
49 '#title' => t('Block settings'),
50 '#collapsible' => TRUE,
51 '#group' => 'additional_settings',
52 '#weight' => 150,
53 );
54 $form['data']['block_set']['block_enable'] = array(
55 '#type' => 'checkbox',
56 '#title' => t('Provide block'),
57 '#default_value' => !empty($entityform_type->data['block_enable']),
58 '#description' => t('Provide a block showing this entity form.'),
59 '#parents' => array('data', 'block_enable'),
60 );
61 }