0

I would like to add a class based on the field value I used in commerce order view. I have tried a solution from here I have installed "devel" module and already enabled it. However, I cannot find the dpm() result from my admin order page. I don't know if it is because of my code or dpm() function.

Here is my code and put them in my theme's template.php file::

function MYTHEME_preprocess_views_view_list(&$vars) {
    if ($vars['view']->name == 'commerce_backoffice_orders' && $vars['view']->current_display == "Admin Page") {
        dpm($vars); //uncomment to see variables
        foreach($vars['view']->result as $key => $value){
             $timestamp = $value->node_created;
             if ($timestamp) { // add whatever conditional logic you need here
             $vars['classes_array'][$key] .= ' hello'; // note the space in front of class
             }
         }
     }
}

Here is a screenshot: enter image description here enter image description here

Does anyone have any idea about my issue? Thank you for anyone's help~~~~

4
  • If you are not using the site administrator account check the permissions page and see if the "Access developer information" permission is grated to your role. Just to make sure that your hook is being called add a die() call and see if your page is still being loaded or not. Also, can you add a screenshot of the whole view configuration?
    – OPTASY
    Commented Nov 22, 2016 at 15:48
  • @OPTASYCanada Thank you for your reply. I checked my permission page and have all the permissions. I edited my question and add the configuration screenshot above.
    – jmu
    Commented Nov 22, 2016 at 18:06
  • In the code you posted, have you actually replaced MYTHEME with the name of your theme ? Otherwise, the hook won't get called.
    – OPTASY
    Commented Nov 23, 2016 at 6:29
  • @OPTASYCanada Yes. I replaced it.
    – jmu
    Commented Nov 23, 2016 at 14:07

2 Answers 2

0

Try this hook instead: MYTHEME_preprocess_views_view_table. Your view uses the Megarow table format. The hook you used is called for the list format.

1
  • This is my code looks like right now: function themev2_preprocess_views_view_table(&$vars) { dpm($vars) or die("Cannot open"); //uncomment to see variables }. I deleted "if" but I still cannot see $vars value on any view page.
    – jmu
    Commented Nov 23, 2016 at 14:18
0

I found the solution by using JS injector Module. If someone wants to get any idea from my question, you can check it from here.

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.