Project

General

Profile

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

root / drupal7 / sites / all / modules / flag / flag_bookmark / flag_bookmark.install @ 4cfd8be6

1
<?php
2

    
3
/**
4
 * @file
5
 * The Flag Bookmark module install hooks.
6
 */
7

    
8
/**
9
 * Implements hook_enable().
10
 *
11
 * We create the demonstration flag on enable, so hook implementations in flag
12
 * module will fire correctly, as the APIs are not available on install.
13
 */
14
function flag_bookmark_enable() {
15
  // Load the flag API in case we want to use it when enabling.
16
  include_once drupal_get_path('module', 'flag') . '/flag.module';
17

    
18
  if (!flag_get_flags()) {
19
    // Install a demonstration flag only if no flag exists. This is to prevent
20
    // a case where a disables and enables the module, and the demonstration
21
    // flag is overwritten or re-created.
22
    $flag = flag_flag::factory_by_entity_type('node');
23
    $configuration = array(
24
      'name' => 'bookmarks',
25
      'global' => 0,
26
      'show_in_links' => array(
27
        'full' => 1,
28
        'teaser' => 1,
29
      ),
30
      'show_on_form' => 1,
31
      // The following UI labels aren't wrapped in t() because they are written
32
      // to the DB in English. They are passed to t() later, thus allowing for
33
      // multilingual sites.
34
      'title' => 'Bookmarks',
35
      'flag_short' => 'Bookmark this',
36
      'flag_long' => 'Add this post to your bookmarks',
37
      'flag_message' => 'This post has been added to your bookmarks',
38
      'unflag_short' => 'Unbookmark this',
39
      'unflag_long' => 'Remove this post from your bookmarks',
40
      'unflag_message' => 'This post has been removed from your bookmarks',
41
      'types' => _flag_bookmark_install_get_suggested_node_types(),
42
    );
43
    $flag->form_input($configuration);
44
    $flag->save();
45

    
46
    // Clear the flag cache so the new permission is seen by core.
47
    drupal_static_reset('flag_get_flags');
48

    
49
    // Grant permissions.
50
    $permissions = array('flag bookmarks', 'unflag bookmarks');
51
    user_role_grant_permissions(DRUPAL_AUTHENTICATED_RID, $permissions);
52
  }
53
}
54

    
55
/**
56
 * Returns some node types to which the demonstration 'bookmarks' flag will
57
 * apply.
58
 */
59
function _flag_bookmark_install_get_suggested_node_types() {
60
  $preferred = array('article', 'story', 'forum', 'blog');
61
  $existing = array_intersect($preferred, array_keys(node_type_get_types()));
62
  if (!$existing) {
63
    // As a last resort, take the first preference.
64
    return array($preferred[0]);
65
  }
66
  return $existing;
67
}