0

I'm using Drupal 7 and Flag.

I try to modify the output of my flags according to the view mode with preprocess_flag :

function mytheme_preprocess_flag(&$variables) {
  $variables['full'] = $variables['view_mode'] == 'full';
  if ($variables['full']) {
...
  }
}

But i have an error : Notice : Undefined index: view_mode dans publiu_preprocess_flag().

Do you know how to use the view_mode in hook_preprocess_flag ?

1 Answer 1

2

view_mode key is not in variables object, which you get as argument. You can check for the same, by printing variables object.

print '<pre>';
print_r($variables);
print '</pre>';

However if u still want to get view mode, you can use somewhat like below.

function bartik_preprocess_flag(&$variables) {
  $arg_1 = arg(1);
  if( isset($arg_1) && !empty($arg_1) ) {
    $menu_obj = menu_get_object();
    $menu_obj_content = $menu_obj['content'];
    foreach($menu_obj_content as $menu_key=>$menu_val) {
      $node_view_mode = $menu_val['#view_mode'];
      break;
    }
    print $node_view_mode;
  }
}

Here node_view_mode will return "View Mode" of current node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.