0

I've added a custom field of type global using views_handler_field. This custom field type is basically a button that needs to call a javascript function. This javascript function takes an adjacent field's value as a parameter. When I edit the view on my webpage, under rewrite rules->replacement values, I can see the token for the value I need in my handler's functionality. In the code example, it's [fieldID]

However, I don't see any way to access this value in my views_handler_field include file.

function render($values) {

    $actions = array();
    $variable = variable_get('fieldID'); // HERE is what I'd like to do to get the adjacent [fieldID] icon

    $alt = t('Download File');
    $actions[] = array(
      'name' => t('Download'),
      'html' => 'javascript:initiateDownload('.$variable.')',     
      'id' => t('download-button-' . $variable),
      'icon' => theme('image', array('path' => drupal_get_path('module', 'download_process') . '/images/edit.png', 'alt' => $alt))
    );

    $output = '';

    $counter = 0;
    foreach ($actions as $action) {
      $output .= l($action['icon'], $action['html'], array('attributes' => array('id' => $action['id'] . $counter), 'html' => TRUE, 'external' => TRUE));
      $counter++;
    }
    return $output;
  }
  function query() {

  }

I've tried working with get_render_tokens, but I don't think that that's what I'm looking for. Any help here would be appreciated! For reference, I'm using Drupal 7.

0

The answer ended up being very simple. All I needed to do was cast $values to an array, then access the id. Like this:

$array = json_decode(json_encode($values), true);
$value = $array['fieldid'];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.