home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (webform_handler_field_submission_link.inc)

This example Drupal source code file (webform_handler_field_submission_link.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

access, array, break, directory, file, function, link, nid, node, php, return, submission, text, values

The webform_handler_field_submission_link.inc Drupal example source code

<?php

/**
* @file
* Views handler to display links to a submission.
*/

/**
 * Field handler to present a link to the user.
 */
class webform_handler_field_submission_link extends views_handler_field {
  var $link_type;

  function construct() {
    // We need to set this property before calling the construct() chain
    // as we use it in the option_definintion() call.
    $this->link_type = $this->definition['link_type'];

    parent::construct();
    $this->additional_fields['sid'] = 'sid';
    $this->additional_fields['nid'] = 'nid';
    $this->additional_fields['uid'] = 'uid';

    $this->additional_fields['node_uid'] = array(
      'table' => 'node', 
      'field' => 'uid',
    );
  }

  function allow_advanced_render() {
    return FALSE;
  }

  function option_definition() {
    $options = parent::option_definition();
    $options['label'] = array('default' => '', 'translatable' => TRUE);
    $options['text'] = array('default' => $this->link_type, 'translatable' => TRUE);
    return $options;
  }

  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);
    $form['text'] = array(
      '#type' => 'textfield',
      '#title' => t('Text to display'),
      '#default_value' => $this->options['text'],
    );
  }

  function query() {
    $this->ensure_my_table();

    // Join to the node table to retrieve the node UID.
    $join = new views_join();
    $join->construct('node', $this->table_alias, 'nid', 'nid');
    $this->query->ensure_table('node', $this->relationship, $join);

    $this->add_additional_fields();
  }

  function render($values) {
    $submission = new stdClass();
    $submission->sid = $values->{$this->aliases['sid']};
    $submission->nid = $values->{$this->aliases['nid']};
    $submission->uid = $values->{$this->aliases['uid']};
    $node = (object) array(
      'nid' => $submission->nid,
      'uid' => $values->{$this->aliases['node_uid']},
    );

    switch ($this->link_type) {
      case 'view':
        $text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
        $link = l($text, "node/$submission->nid/submission/$submission->sid");
        $access = webform_submission_access($node, $submission, 'view');
        break;
      case 'edit':
        $text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
        $link = l($text, "node/$submission->nid/submission/$submission->sid/edit");
        $access = webform_submission_access($node, $submission, 'edit');
        break;
      case 'delete':
        $text = !empty($this->options['text']) ? $this->options['text'] : t('view');
        $path = drupal_get_path_alias($_GET['q']);
        $link = l($text, "node/$submission->nid/submission/$submission->sid/delete", array('query' => array('destination' => $path)));
        $access = webform_submission_access($node, $submission, 'delete');
        break;
      default:
        $text = '';
        $link = NULL;
        $access = FALSE;
    }

    if (!$access) {
      return;
    }

    return $link;
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal webform_handler_field_submission_link.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.