in inline.module:

function _inline_fileobj(&$node, $field_name, $image_name)

does not return the images included with the node.
Some debuging reveals that this has something to do with the language settings.
My site is in dutch ('nl'), but I did not define a node language ('und').

So
$node->{$field_name} gives array ( 'und' => array.....
But
$node->language gives 'nl'

so I think the foreach also has to search the 'und' language (the altered function works for me):

function _inline_fileobj(&$node, $field_name, $image_name) {
// Named file reference.
foreach ($node->{$field_name}[$node->language] as $file) {
// var_export($file);
// var_export($image_name);
$file = (object) $file;
if ($file->filename == $image_name) {
return $file;
}
}
foreach ($node->{$field_name}['und'] as $file) {
// var_export($file);
// var_export($image_name);
$file = (object) $file;
if ($file->filename == $image_name) {
return $file;
}
}
return NULL;
}

Comments

fasdalf@fasdalf.ru’s picture

Same for russian.

    Notice: Undefined index: ru в функции _inline_fileobj() (строка 276 в файле /var/www/sites/all/modules/inline/inline.module).
    Warning: Invalid argument supplied for foreach() в функции _inline_fileobj() (строка 276 в файле /var/www/sites/all/modules/inline/inline.module).
    Notice: Trying to get property of non-object в функции inline_prepare_file_object() (строка 250 в файле /var/www/sites/all/modules/inline/inline.module).
    Notice: Trying to get property of non-object в функции _inline_substitute_tags() (строка 341 в файле /var/www/sites/all/modules/inline/inline.module).

I'll try your fix and report back.

fasdalf@fasdalf.ru’s picture

Shows (un)localized files without warnings, plase review:

function _inline_local_files(&$node, $field_name) {
  $files = array();
  if (isset($node->{$field_name}[$node->language])) {
    $files += $node->{$field_name}[$node->language];
  };
  if (isset($node->{$field_name}['und'])) {
    $files += $node->{$field_name}['und'];
  };
  return $files;
}


function _inline_fileobj(&$node, $field_name, $image_name) {
  // Get (un)translated files
  $files = _inline_local_files($node,$field_name);
  // Find named file reference.
  foreach ($files as $file) {
    $file = (object) $file;
    if ($file->filename == $image_name) {
      return $file;
    }
  };
  // If nothing found
  return NULL;
}

/**
 * Automatically add all images to configured node views.
 *
 * This feature can be configured per content-type.
 */
function _inline_auto_add(&$build, $field_name) {
  $node = $build['#node'];
  switch (variable_get('upload_inline_'. $node->type, 0)) {
    case 1:
      // Display only in teaser.
      if ($build['body']['#view_mode'] == 'teaser') {
        foreach (_inline_local_files($node,$field_name) as $file) {
          $file = inline_prepare_file_object($file);
          if (_inline_decide_img_tag($file)) {
            $build['body'][0]['#markup'] .= theme('inline_img', array('node' => $node, 'file' => $file, 'viewmode' => 'summary'));
          }
        }
      }
      break;

    case 2:
      // Display only in body.
      if ($build['body']['#view_mode'] == 'full') {
        foreach (_inline_local_files($node,$field_name) as $file) {
          $file = inline_prepare_file_object($file);
          if (_inline_decide_img_tag($file)) {
            $build['body'][0]['#markup'] .= theme('inline_img', array('node' => $node, 'file' => $file, 'viewmode' => 'full'));
          }
        }
      }
      break;

    case 3:
      // Display in teaser and body.
      foreach (_inline_local_files($node,$field_name) as $file) {
        $file = inline_prepare_file_object($file);
        if (_inline_decide_img_tag($file)) {
          $build['body'][0]['#markup'] .= theme('inline_img', array('node' => $node, 'file' => $file, 'viewmode' => 'full'));
        }
      }
      break;
  }
}

2 functions changed, 1 function added.

fasdalf@fasdalf.ru’s picture

Status: Active » Needs review

missposted

foxfabi’s picture

using another language as default (disabling 'en') still results in ['und'] as key index ...
currently we are using:

function _inline_fileobj(&$node, $field_name, $image_name) {
  // Named file reference.
  foreach ($node->{$field_name}['und'] as $file) {
    $file = (object) $file;
    if ($file && $file->filename == $image_name) {
     return $file;
    }
  }
  foreach ($node->{$field_name}[$node->language] as $file) {
    $file = (object) $file;
    if ($file && $file->filename == $image_name) {
      return $file;
    }
  }
  return NULL;
}