Skip to content

Drupal Integrating Mathjax with Field Collections

Davide P. Cervone edited this page May 26, 2013 · 4 revisions

From https://groups.google.com/d/msg/mathjax-users/fE2NQew_uLo/TOjihEPMAbYJ


Thank you both, Peter and Davide, for all your help. I was able to locate the error in the apache log files and I am investigating what happened. It appears that the error is occurring within the PHP code for the field collection module. If I learn anything useful about using Drupal, MathJax and Field Collections or if I have any further questions regarding MathJax in this issue I will be sure to post them here.


In case anyone is curious, the function that breaks with Mathjax enabled is shown below. The error occurs on the line indicated as "Call to undefined function (line 869 of /sites/all/modules/field_collection/field_collection.module)" which works fine when MathJax is uninstalled or disabled.

/**
 * Implements hook_field_formatter_view().
 */
function field_collection_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
  $element = array();
  $settings = $display['settings'];

  switch ($display['type']) {
    case 'field_collection_list':

      foreach ($items as $delta => $item) {
        if ($field_collection = field_collection_field_get_entity($item)) {
          $output = l($field_collection->label(), $field_collection->path());
          $links = array();
          foreach (array('edit', 'delete') as $op) {
            if ($settings[$op] && field_collection_item_access($op == 'edit' ? 'update' : $op, $field_collection)) {
              $title = entity_i18n_string("field:{$field['field_name']}:{$instance['bundle']}:setting_$op", $settings[$op]);
              $links[] = l($title, $field_collection->path() . '/' . $op, array('query' => drupal_get_destination()));
            }
          }
          if ($links) {
            $output .= ' (' . implode('|', $links) . ')';
          }
          $element[$delta] = array('#markup' => $output);
        }
      }
      field_collection_field_formatter_links($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display);
      break;

    case 'field_collection_view':

      $element['#attached']['css'][] = drupal_get_path('module', 'field_collection') . '/field_collection.theme.css';
      $view_mode = !empty($display['settings']['view_mode']) ? $display['settings']['view_mode'] : 'full';
      foreach ($items as $delta => $item) {
        if ($field_collection = field_collection_field_get_entity($item)) {
          $element[$delta]['entity'] = $field_collection->view($view_mode);
          $element[$delta]['#theme_wrappers'] = array('field_collection_view');
          $element[$delta]['#attributes']['class'][] = 'field-collection-view';
          $element[$delta]['#attributes']['class'][] = 'clearfix';
          $element[$delta]['#attributes']['class'][] = drupal_clean_css_identifier('view-mode-' . $view_mode);

          $links = array(
            '#theme' => 'links__field_collection_view',
          );
          $links['#attributes']['class'][] = 'field-collection-view-links';
          foreach (array('edit', 'delete') as $op) {
            if ($settings[$op] && field_collection_item_access($op == 'edit' ? 'update' : $op, $field_collection)) {
              $links['#links'][$op] = array(

/* 
<------------------------ CALL TO UNDEFINED FUNCTION 'entity_i18n_string' OCCURS ERROR OCCURS on line of code below  ----------------------->
*/

                'title' => entity_i18n_string("field:{$field['field_name']}:{$instance['bundle']}:setting_$op", $settings[$op]), 
                'href' => $field_collection->path() . '/' . $op,
                'query' => drupal_get_destination(),
              );
            }
          }
          $element[$delta]['links'] = $links;
        }
      }
      field_collection_field_formatter_links($element, $entity_type, $entity, $field, $instance, $langcode, $items, $display);
      break;

    case 'field_collection_fields':

      $view_mode = !empty($display['settings']['view_mode']) ? $display['settings']['view_mode'] : 'full';
      foreach ($items as $delta => $item) {
        if ($field_collection = field_collection_field_get_entity($item)) {
          $element[$delta]['entity'] = $field_collection->view($view_mode);
        }
      }
      break;
  }

  return $element;
}

Here is some information on this:

It looks like there is a patch that you can apply to fix the problem. It doesn't seem to be related to MathJax in any way, but perhaps installing the MathJax extension updated part of your system and caused the error.

Davide


You are a hero and a saint. I came home from my other job last night prepared to get my hands dirty but was pleasantly surprised to see that it appears I will not have to do so. I have to go back to work again today, but I will roll this solution out tonight or tomorrow. I will be sure to post my results. Many thanks Davide! Cheers.


Implementing the changes from the drupal groups worked like Magic. Thanks!

Clone this wiki locally