You are here

function _feeds_excel_token_values__excel_sheet in Feeds Excel 7

Helper function for rendering token values for excel sheet tokens.

Parameters

object $object: the exce sheet object to build the token value for.

string $token_name: the specific token name, like passed to hook_tokens() as $tokens key.

string $original_token: the original complete token, containing type and name, like passed to hook_tokens() as $tokens value.

Return value

string rendered token value for the given token

1 string reference to '_feeds_excel_token_values__excel_sheet'
feeds_excel_tokens in ./feeds_excel.module
Implements hook_tokens().

File

./feeds_excel.module, line 318

Code

function _feeds_excel_token_values__excel_sheet($object, $token_name, $original_token, $sanitize) {

  // Subpattern for preg_match
  $subpattern = array();
  if ($token_name == 'id') {
    return $sanitize ? check_plain($object->id) : $object->id;
  }
  elseif ($token_name == 'name') {
    return $sanitize ? check_plain($object->name) : $object->name;
  }
  elseif (is_array($object->fixed_cells) && preg_match('&^cell-([0-9]+)-([0-9]+)(-formatted)?$&is', $token_name, $subpattern)) {
    $row = $subpattern[1];
    $column = $subpattern[2];
    $formatted = !empty($subpattern[3]);
    foreach ($object->fixed_cells as $id => $cell) {

      // We found the correct cell.
      if ($cell['row'] == $row && $cell['column'] == $column) {
        $key = $formatted ? 'value' : 'raw';
        return $sanitize ? check_plain($cell[$key]) : $cell[$key];
      }
    }

    // @TODO: check if fixed cells are only valid, if they appear in fixed_cells
    // array. If so we have to return nothing here.
    return '';
  }

  // No other valid token names.
}