You are here

eck_views_handler_field_link_delete.inc in Entity Construction Kit (ECK) 7.3

Same filename and directory in other branches
  1. 7.2 views/handlers/eck_views_handler_field_link_delete.inc

Field handler to present a link to delete the entity content.

File

views/handlers/eck_views_handler_field_link_delete.inc
View source
<?php

/**
 * @file
 * Field handler to present a link to delete the entity content.
 */

// @codingStandardsIgnoreStart
class eck_views_handler_field_link_delete extends eck_views_handler_field_link {
  function render_link($entity, $values) {
    $entity_type = $entity
      ->entityType();
    $bundle = $entity
      ->bundle();
    $action = 'delete';
    if (eck_access($action, 'entity', $entity)) {
      $crud_info = get_bundle_crud_info($entity_type, $bundle);
      $this->options['alter']['make_link'] = TRUE;
      $this->options['alter']['path'] = str_replace('%eckentity', $entity->id, $crud_info['delete']['path']);
      $this->options['alter']['query'] = drupal_get_destination();
      if (count($this->view->result) == 1 && $this->view->query->offset >= $this->view->query->limit) {
        $destination = drupal_get_destination();
        $url_query = parse_url($destination['destination']);
        parse_str($url_query['query'], $url_data);
        $url_data['page'] = $url_data['page'] - 1;
        $destination['destination'] = $url_query['path'] . '?' . http_build_query($url_data);
        $this->options['alter']['query'] = $destination;
      }
      $text = !empty($this->options['text']) ? $this->options['text'] : t('delete');
      return $text;
    }
  }

}

// @codingStandardsIgnoreEnd