You are here

function profanity_views_data_alter in Profanity 7

Implements hook_views_data_alter().

File

./profanity.views.inc, line 11
Provide additional Views fields for entity content.

Code

function profanity_views_data_alter(&$data) {
  $entity_info = entity_get_info();
  foreach ($entity_info as $entity_type => $info) {
    if (empty($info['entity keys']['label'])) {
      continue;
    }
    $title_property = $info['entity keys']['label'];
    if (empty($data[$entity_type][$title_property])) {
      continue;
    }
    $data[$entity_type]["profanity_{$title_property}"] = $data[$entity_type][$title_property];
    $data[$entity_type]["profanity_{$title_property}"]['title'] = t('@property - Profanity filtered', array(
      '@property' => $data[$entity_type][$title_property]['title'],
    ));
    $data[$entity_type]["profanity_{$title_property}"]['help'] = t('Run the entity title through profanity filters, allows you to select which filters.');
    $data[$entity_type]["profanity_{$title_property}"]['field']['handler'] = 'profanity_views_handler_field';
    $data[$entity_type]["profanity_{$title_property}"]['field']['type'] = $entity_type;
    $data[$entity_type]["profanity_{$title_property}"]['field']['base_table'] = $info['base table'];
    $data[$entity_type]["profanity_{$title_property}"]['field']['id'] = $info['entity keys']['id'];
  }

  // If present, integrate with Search API Views.
  if (module_exists('search_api_views')) {
    try {
      $entity_types = entity_get_info();
      foreach (search_api_index_load_multiple(FALSE) as $index) {
        $key = 'search_api_index_' . $index->machine_name;
        $data[$key]['profanity_search_api_excerpt'] = array(
          'group' => 'Search',
          'title' => t('Excerpt - Profanity filtered'),
          'help' => t('The search result excerpted to show found search terms filtered by the Profanity word lists.'),
          'field' => array(
            'type' => 'text',
            'handler' => 'profanity_views_handler_search_excerpt',
          ),
        );
      }
    } catch (Exception $e) {
      watchdog_exception('search_api_views', $e);
    }
  }
}