You are here

function uptolike_entity_view in Uptolike share buttons 7

Implements hook_entity_view().

File

./uptolike.module, line 250
Main file for Uptolike module.

Code

function uptolike_entity_view($entity, $type, $view_mode, $langcode) {
  if (isset($entity->type)) {
    $extra_fields = field_extra_fields_get_display($type, $entity->type, $view_mode);
    if (isset($extra_fields['uptolike']) && $extra_fields['uptolike']['visible'] && !empty($extra_fields['uptolike']['settings'])) {
      $preset = $extra_fields['uptolike']['settings']['preset'];
      $object = _uptolike_ctools_export_load_enabled_object(array(
        'name' => $preset,
      ));
      if (!empty($object)) {

        // Prepare data for theme function.
        $variables = array();
        $url = entity_uri($type, $entity);
        if (!empty($url['path'])) {
          $url['options']['absolute'] = TRUE;
          $variables['url'] = url($url['path'], $url['options']);
        }
        $variables['language'] = variable_get('uptolike_language', uptolike_default_language());
        $variables['data'] = filter_xss($object->code);
        $entity->content['uptolike'] = array(
          '#markup' => theme('uptolike_code', $variables),
          '#attached' => array(
            'js' => array(
              array(
                'data' => theme('uptolike_javascript'),
                'scope' => 'footer',
                'type' => 'inline',
              ),
            ),
          ),
        );
      }
    }
  }
}