0

I have created a block entity using bean module.

It has three image fields. Image1, Image2 and Image3.

I want to show only one image depending upon current time. I have three time values. For this I have created 3 view modes each for one time value.

Now I'm stuck that how will change the view mode based on time value programmatically.

I have used the following code.

function glue_site_block_view_alter(&$data, $block) {
  if ($timevalue1 == $value1) {
    $data['content']['bean']['block_delta']['#view_mode'] = 'view_mode1'
}

1 Answer 1

1

You can use hook_entity_view_mode_alter()

function MYMODULE_entity_view_mode_alter(&$view_mode, $context) {  
    if ($timevalue1 == $value1) {  
      $view_mode = 'view_mode1';  
    } elseif {  
      .......  
    }  
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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