If formatter does not contain underscore than the $parts array will be empty since it is popped at the second line, so the implode function will try to implode an empty array

$parts =  explode('_', $formatter);
$style = array_pop($parts);
$presetname = implode('_', $parts);

Solution

  // Check if there is an underscore in the formatter name
  if (strpos($formatter, '_')) {
    preg_match('/^(.*)_(linked|imagelink|path|url)?$/', $formatter, $matches);
    // Shift the first element of regex match since it contains the whole string (formatter)
    array_shift($matches);
    list($presetname, $style) = $matches;
  }
  else {
    $presetname = $formatter;
  }

Comments

energie’s picture

StatusFileSize
new701 bytes

Sorry, i've found a bug in my patch
Here comes the correct one...

condition changed

if (strpos($formatter, '_') && preg_match('/^(.*)_(linked|imagelink|path|url)?$/', $formatter, $matches)) {
  array_shift($matches);
  list($presetname, $style) = $matches;
}
else {
  $presetname = $formatter;
}
soxofaan’s picture

StatusFileSize
new1017 bytes

Isn't just easier to make sure all formatters names have the same structure?

soxofaan’s picture

Status: Needs review » Closed (duplicate)

this issue is duplicate of http://drupal.org/node/249363
marking this one as the duplicate because the other is older (and longer)