0

Возникла ошибка в друпал 7, выдал модуль Table Field

Warning: Invalid argument supplied for foreach() в функции tablefield_field_formatter_view() (строка 455 в файле X:\home\tt.du\www\sites\all\modules\tablefield\tablefield.module).

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

  foreach ($items as $delta => $table) {
    // Check for table caption.
    $raw = unserialize($table['value']);
    $caption = isset($raw['caption'])? check_plain($raw['caption']): '';

    // Rationalize the stored data.
    if (!empty($table['tabledata'])) {
      $tabledata = $table['tabledata'];
    }
    elseif (!empty($table['value'])) {
      $tabledata = tablefield_rationalize_table(unserialize($table['value']));
    }

    // Run the table through input filters.
    if (isset($tabledata)) {
      if (!empty($tabledata)) {

        if (!empty($settings['trim_trailing_rows'])) {
          $tabledata = tablefield_rtrim_rows($tabledata);
        }

        if (!empty($settings['trim_trailing_cols'])) {
          $tabledata = tablefield_rtrim_cols($tabledata);
        }

        foreach ($tabledata as $row_key => $row) {
          foreach ($row as $col_key => $cell) {
            if (!empty($table['format'])) {
              $tabledata[$row_key][$col_key] = array(
                'data' => check_markup($cell, $table['format']),
                'class' => array('row_' . $row_key, 'col_' . $col_key),
              );
            }
            else {
              $tabledata[$row_key][$col_key] = array(
                'data' => check_plain($cell),
                'class' => array('row_' . $row_key, 'col_' . $col_key),
              );
            }
          }
        }
      }

      // Check for an empty header, if so we don't want to theme it.
      $noheader = TRUE;
      if (empty($field['settings']['hide_headers'])) {
        $header_data = array_shift($tabledata);
        foreach ($header_data as $cell) {
          if (strlen($cell['data']) > 0) {
            $noheader = FALSE;
            break;
          }
        }
      }

      $header = $noheader ? NULL : $header_data;

      $entity_info = entity_get_info($entity_type);
      $entity_id = !empty($entity_info['entity keys']['id']) ? $entity->{$entity_info['entity keys']['id']} : NULL;

      // Theme the table for display.
      $element[$delta] = array(
        '#theme' => 'tablefield_view',
        '#attributes' => array(
          'id' => 'tablefield-' . $delta,
          'class' => array('tablefield'),
        ),
        '#caption' => $caption,
        '#header' => $header,
        '#rows' => $tabledata,
        '#delta' => $delta,
        '#export' => isset($field['settings']['export']) ? $field['settings']['export'] : NULL,
        '#entity_type' => $entity_type,
        '#entity_id' => $entity_id,
        '#field_name' => $field['field_name'],
        '#langcode' => $langcode,
        '#formatter' => $formatter,
      );
    }

  }
  return $element;
}

Ошибка возникает на

foreach ($header_data as $cell) {

Кто подскажет куда копать

модуль друпала 7 Table Field

1 ответ 1

3

Замените этот код:

if (empty($field['settings']['hide_headers'])) {
  $header_data = array_shift($tabledata);
  foreach ($header_data as $cell) {
    if (strlen($cell['data']) > 0) {
      $noheader = FALSE;
      break;
    }
  }
}

На такой:

if (empty($field['settings']['hide_headers'])) {
  $header_data = array_shift($tabledata);
  if (is_array($header_data)) {
    foreach ($header_data as $cell) {
      if (strlen($cell['data']) > 0) {
        $noheader = FALSE;
        break;
      }
    }
  }
}

Ошибка говорит о том, что в цикл для обработки передано что-то, что невозможно итерировать.

1

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.