Skip to content

Commit

Permalink
TL : mise a jour tl_hacks pour gerer icons univers sur views
Browse files Browse the repository at this point in the history
  • Loading branch information
DuaelFr committed Mar 3, 2012
1 parent 57c3c75 commit 7aaaf70
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 1 deletion.
@@ -0,0 +1,42 @@
<?php
/**
* Filter handler for group audience:gid
*/
class og_handler_filter_group_audience_gid_tl extends views_handler_filter_many_to_one {

function get_value_options() {

// @TODO add extra settings to allow filtering by OG_STATE in og_get_all_group()
$groups = og_load_multiple(og_get_all_group());

foreach($groups as $group) {
if ($group->access()) {
$entity = reset(entity_load('node', array($group->etid)));
if ($this->value_form_type == 'checkboxes') {
$flang = field_language('node', $entity, 'field_icon');
$imageData = array(
'style_name' => 'universe_icon',
'path' => !empty($entity->field_icon) ? $entity->field_icon[$flang][0]['filename'] : _tl_hacks_get_default_icon_uri(),
'alt' => check_plain($entity->title),
'title' => check_plain($entity->title),
);
$this->value_options[$group->gid] = theme('image_style', $imageData);
} else {
$this->value_options[$group->gid] = $entity->title;
}
}
}
}

function value_form(&$form, &$form_state) {
if (empty($form_state['form_id']) || $form_state['form_id'] != 'views_ui_config_item_form') {
$this->value_form_type = 'checkboxes';
}

parent::value_form($form, $form_state);

if (empty($form_state['form_id']) || $form_state['form_id'] != 'views_ui_config_item_form') {
$form['value']['#theme'] = 'select_as_checkboxes';
}
}
}
1 change: 1 addition & 0 deletions sites/terraludis.org/modules/tl_hacks/tl_hacks.info
Expand Up @@ -4,3 +4,4 @@ package = Terraludis
core = 7.x

files[] = tl_hacks.module
files[] = og_handler_filter_group_audience_gid_tl.inc
42 changes: 41 additions & 1 deletion sites/terraludis.org/modules/tl_hacks/tl_hacks.module
@@ -1,5 +1,9 @@
<?php

////////////////////////////////////////////////////////////////////////////////
// LOGIN FORM
////////////////////////////////////////////////////////////////////////////////

/**
* Modification de l'ordre des éléments du formulaire de login
* @param array $form
Expand All @@ -11,6 +15,10 @@ function tl_hacks_form_user_login_block_alter(&$form) {
$form['links']['#weight'] = 4;
}

////////////////////////////////////////////////////////////////////////////////
// ACTUALITES
////////////////////////////////////////////////////////////////////////////////

/**
* Implements hook_field_formatter_info().
*/
Expand All @@ -36,12 +44,24 @@ function tl_hacks_field_formatter_view($entity_type, $entity, $field, $instance,
$label = og_label($group->gid);
$entity = entity_load($group->entity_type, array($group->etid));
$entity = current($entity);

$flang = field_language('node', $entity, 'field_group_type');
if ($entity->field_group_type[$flang][0]['value'] != 'univers') continue;

// Get the entity type of the group entity.
$uri = entity_uri($group->entity_type, $entity);
$flang = field_language('node', $entity, 'field_icon');
$imageData = array(
'style_name' => 'universe_icon',
'path' => !empty($entity->field_icon) ? $entity->field_icon[$flang][0]['filename'] : _tl_hacks_get_default_icon_uri(),
'alt' => check_plain($entity->title),
'title' => check_plain($entity->title),
);
$element[$delta] = array(
'#type' => 'link',
'#title' => var_export($entity->field_icon, true),
'#title' => theme('image_style', $imageData),
'#href' => $uri['path'],
'#options' => array('html' => TRUE,),
);
}
else {
Expand All @@ -61,4 +81,24 @@ function tl_hacks_field_formatter_view($entity_type, $entity, $field, $instance,
}

return $element;
}

/**
* Get default icon uri
*/
function _tl_hacks_get_default_icon_uri() {
$uri = &drupal_static(__FUNCTION__);
if (empty($uri)) {
$field = field_info_field('field_icon');
$file = file_load($field['settings']['default_image']);
$uri = $file->uri;
}
return $uri;
}

/**
* Implements hook_views_data_alter().
*/
function tl_hacks_views_data_alter(&$data) {
$data['og_membership']['group']['filter']['handler'] = 'og_handler_filter_group_audience_gid_tl';
}

0 comments on commit 7aaaf70

Please sign in to comment.