Project

General

Profile

Paste
Download (3.43 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / addthis / includes / addthis.block.inc @ 2c8c2b87

1
<?php
2

    
3
/**
4
 * @file
5
 * Block related hook implementations for the AddThis-module.
6
 */
7

    
8
/**
9
 * Implements hook_block_info().
10
 */
11
function addthis_block_info() {
12
  $block_info = array();
13
  $block_info[AddThis::BLOCK_NAME] = array(
14
    'info' => t('AddThis'),
15
    'cache' => DRUPAL_NO_CACHE,
16
  );
17
  return $block_info;
18
}
19

    
20
/**
21
 * Implements hook_block_view().
22
 *
23
 * #block key allows alter hooks to react on this information. Someone might
24
 * want to change this specific display.
25
 */
26
function addthis_block_view($block_name = '') {
27

    
28
  if ($block_name == AddThis::BLOCK_NAME) {
29

    
30
    $widget_type = AddThis::getInstance()->getBlockDisplayType();
31
    $widget_settings = AddThis::getInstance()->getBlockDisplaySettings();
32

    
33
    $block_options = array(
34
      '#block' => AddThis::BLOCK_NAME,
35
      '#display' => array(
36
        'settings' => $widget_settings,
37
      )
38
    );
39

    
40
    $markup = AddThis::getInstance()->getDisplayMarkup($widget_type, $block_options);
41
    return array(
42
      'subject' => '',
43
      'content' => $markup,
44
    );
45
  }
46
}
47

    
48
/**
49
 * Implements hook_block_configure().
50
 */
51
function addthis_block_configure($delta = '') {
52
  return array();
53
}
54

    
55
/**
56
 * Implements hook_block_save().
57
 *
58
 * @todo Refactor settings save validation to appropriate class/method.
59
 *   There should come classes for each render type that also handle the saving
60
 *   of the settings data.
61
 */
62
function addthis_block_save($delta = '', $edit = array()) {
63
  variable_set(AddThis::BLOCK_WIDGET_TYPE_KEY, $edit['addthis_settings']['type']);
64
  if ($edit['addthis_settings']['type'] != 'addthis_disabled') {
65
    variable_set(AddThis::BLOCK_WIDGET_SETTINGS_KEY, $edit['addthis_settings']['settings']);
66
  }
67
}
68

    
69
/**
70
 * Callback submit.
71
 */
72
function _addthis_settings_form_block_submit($form, &$form_state) {
73
  $form_state['rebuild'] = TRUE;
74
}
75

    
76
/**
77
 * Callback to return ajax replace part.
78
 */
79
function _addthis_settings_form_block_submit_callback($form, &$form_state) {
80
  return $form['settings']['addthis_settings']['form'];
81
}
82

    
83
/**
84
 * Implements hook_form_FORM_ID_alter().
85
 */
86
function addthis_form_block_admin_configure_alter(&$form, &$form_state) {
87

    
88
  if ($form['module']['#value'] == 'addthis' && $form['delta']['#value'] == 'addthis_block') {
89
    form_load_include($form_state, 'inc', 'addthis', 'addthis.block');
90
    $form['#cache'] = TRUE;
91

    
92
    $form['settings']['addthis_settings'] = array(
93
      '#type' => 'fieldset',
94
      '#title' => 'Display settings',
95
    );
96

    
97
    // Retrieve settings.
98
    $addthis_settings['type'] = AddThis::getInstance()->getBlockDisplayType();
99
    $addthis_settings['settings'] = AddThis::getInstance()->getBlockDisplaySettings();
100

    
101
    // Create a addthis settings form based on the available configuration.
102
    $element = _addthis_settings_form(
103
      isset($form['addthis_settings']['form']) ? $form['addthis_settings']['form'] : array(),
104
      $form_state,
105
      isset($addthis_settings['type']) ? $addthis_settings['type'] : NULL,
106
      isset($addthis_settings['settings']) ? $addthis_settings['settings'] : NULL
107
    );
108

    
109
    // Change the submit and callback because our handling is different and the
110
    // form structure is different form the default implementation.
111
    $element['type']['#submit'] = array('_addthis_settings_form_block_submit');
112
    $element['type']['#ajax']['callback'] = '_addthis_settings_form_block_submit_callback';
113
    $form['settings']['addthis_settings']['form'] = $element;
114

    
115
    array_unshift($form['#submit'], '_addthis_settings_form_block_submit');
116
  }
117

    
118
  return $form;
119
}