You are here

function hashtags_fields_activate in Hashtags 7

Activate hashtag field to use Hashtags for all bundles of passed entity type

Parameters

string $entity_type (node, comment, user, etc):

string $field_activate by default - body:

Return value

boolean

2 calls to hashtags_fields_activate()
hashtags_fields_content_types_submit in ./hashtags.module
hashtags_update_7002 in ./hashtags.install
1) Create a table for storing relations between hashtags, nodes and comments {hashtags_index} 2) Update Hashtags taxonomy: clean hash symbol for all saved hashtags #hash1 => hash1 3) Activate body fields for selected content types (that have…

File

./hashtags.module, line 936

Code

function hashtags_fields_activate($entity_type = 'node', $field_activate = 'body') {
  $field_name = variable_get('hashtags_terms_field', 'field_hashtags');

  // get all bundles => fields array by Entity type
  $fields = field_info_instances($entity_type);

  // go through all bundles and check 2 options:
  // * Field Hashtags exists
  // * Field to be activated exists
  foreach ($fields as $bundle => $fields) {
    if (isset($fields[$field_name]) && isset($fields[$field_activate])) {

      // activate Hashtag tracking for node body field
      $fields[$field_activate]['hashtag_settings']['hashtag_field'] = 1;
      field_update_instance($fields[$field_activate]);

      // activate Hashtag tracking for comment body field of
      // current node
      $comment_instance = field_info_instance('comment', 'comment_body', 'comment_node_' . $bundle);
      $comment_instance['hashtag_settings']['hashtag_field'] = 1;
      field_update_instance($comment_instance);
    }
  }
}