Hello everyone,
i want to create a flag inside a module 'get_involved'. Unfortunately, despite pretty much copying what drupal.org says (https://www.drupal.org/node/1748148#default-flags), I cannot seem to get flag_default_flags() to work. Any ideas?

Context: I am trying to create a flag within a module, which shall display it in a block.

function get_involved_flag_default_flags() {
  $flags = array();
  $flags[] = array(
    'content_type' => 'node',
    'name' => 'get_involved_interested',
    'title' => 'Interested',
    'global' => FALSE,
    'types' => array('ad'),
    'flag_short' => 'Join',
    'flag_long' => 'I want to join',
    'flag_message' => 'Your interest was registered',
    'unflag_short' => 'Cancel',
    'unflag_long' => 'Cancel my interest',
    'unflag_message' => 'Your interest was deleted',
    'show_on_page' => TRUE,
    'show_on_teaser' => FALSE,
    'show_on_form' => TRUE,
    'status' => TRUE,
    'locked' => array('name', 'types', 'global'),
  );
  return $flags;
}

Comments

phaeton005’s picture

I found out that the documentation on this page (https://www.drupal.org/node/1748148) is not the latest.
Instead, I used the following:

function mymodule_flag_default_flags() {
  $flags = array();
  // Exported flag: "Interested".
  $flags['mymodule_interested'] = array(
    'entity_type' => 'node',
    'title' => 'Interested',
    'global' => false,
    'types' => array(
      0 => 'content_type_invitation',
    ),
    'flag_short' => 'I am interested',
    'flag_long' => 'I am interested in this activity',
    'flag_message' => 'Your interest was registered',
    'unflag_short' => 'Not interested',
    'unflag_long' => 'Not interested in this activity anymore',
    'unflag_message' => 'Your interest was deleted',
    'unflag_denied_text' => '',
    'link_type' => 'toggle',
    'weight' => 0,
    'show_on_teaser' => false,
    'show_on_form' => true,
    'status' => false,
    'locked' => array(
      'name' => 'name',
      'types' => 'types',
      'global' => 'global',
    ),
    'module' => 'get_involved',
    'api_version' => 3,
    'import_roles' => array(
      'flag' => array(),
      'unflag' => array(),
    ),
    'show_in_links' => array(
      'full' => true,
    ),
  );

  return $flags;
}