2

I would like to change formatter of Field Collection Table, so that class added to a table row corresponds to a value of field of field collection item. As a first step, I would like to inspect theme function of that module. However, if I modify it to:

function theme_field_collection_table_multiple_value_field($variables) {
  $element = $variables['element'];
  $header = array();
  $cells = array();

  // Order field widgets by their widget weight.
  $instances = field_info_instances($element['#entity_type'], $element['#bundle']);
  uasort($instances, '_field_collection_table_sort_items_widget_helper');
  foreach ($instances as $field_name => $instance) {
    if (empty($element[$field_name])) {
      continue;
    }

    $header[] = _field_collection_table_get_title($element[$field_name]);
    $cells[] = array('data' => $element[$field_name]);

    // Remove the original field to prevent duplicate printing.
    unset($element[$field_name]);
  }

  $element['field_collection_table'] = array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => array($cells),
    '#weight' => 0,
  );

  $element['#sorted'] = FALSE;
  dpm($element);
  return drupal_render_children($element);
} 

no krumo element is displayed. I cleared both opcache and drupal cache several times, but the problem persists. Also, I did deliberate error to make sure, that theme function applies. Do you know, what am I doing wrong?

1

If dpm($element) isn't returning output at that stage, you can log the data instead (temporarily) to the watchdog log.

e.g:

watchdog('dev', '<pre>' . var_export($element, 1) .'</pre>');

You can then view it at Admin > Reports > Recent log entries

  • Thanks, I tried it. But again, there is no output. Perhaps I have a completely wrong approach, or expectations: I'm using Field Collection Table formatter for a field, entity is displayed using specific view mode by Views and the view content pane is displayed using Panels. Maybe I should try with fewer levels of abstraction? – Miloš Kroulík Sep 18 '15 at 6:14
  • If there's no output it's pretty likely the theme function isn't running @MilošKroulík. You can test definitively by adding die(); in there. If you still see the site, you know what's wrong – Clive Sep 18 '15 at 8:00
  • Thanks @Clive, I already made a deliberate error so I'm sure the theme function applies. I will update the answer. – Miloš Kroulík Sep 18 '15 at 8:05
-1

I think you should initialize the $element variable as a array element before this part of code..

   **$element = array();**
     $element['field_collection_table'] = array(
        '#theme' => 'table',
        '#header' => $header,
        '#rows' => array($cells),
        '#weight' => 0,

);

  • Sorry, I don't understand. You're suggesting I should change the module code (the code above is copied directly from the module, except my dpm call) to make this work? That shouldn't be necessary, I think. – Miloš Kroulík Sep 18 '15 at 7:35
  • For good or bad, PHP doesn't require that you initialise arrays before accessing them as such, so this wouldn't make any difference, even if we ignore the fact that $variables['element'] is already an array – Clive Sep 18 '15 at 8:01
  • but you are unset the a $element that's why i thought and just for more specific coding standard I told you. – Aradhya Sep 18 '15 at 8:15

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.