From bc60830608525a96b63fac072190e67a13318279 Mon Sep 17 00:00:00 2001 From: Tom Kirkpatrick Date: Wed, 2 May 2012 19:08:47 +0200 Subject: [PATCH] Ad views handlers for edit and delete links --- field_collection.info | 2 + views/field_collection.views.inc | 16 +++++++++++ .../field_collection_handler_field_delete_link.inc | 29 ++++++++++++++++++++ views/field_collection_handler_field_edit_link.inc | 29 ++++++++++++++++++++ 4 files changed, 76 insertions(+), 0 deletions(-) create mode 100644 views/field_collection_handler_field_delete_link.inc create mode 100644 views/field_collection_handler_field_edit_link.inc diff --git a/field_collection.info b/field_collection.info index 494eb27..5d8d173 100644 --- a/field_collection.info +++ b/field_collection.info @@ -5,5 +5,7 @@ dependencies[] = entity files[] = field_collection.test files[] = field_collection.info.inc files[] = views/field_collection_handler_relationship.inc +files[] = views/field_collection_handler_field_edit_link.inc +files[] = views/field_collection_handler_field_delete_link.inc configure = admin/structure/field-collections package = Fields diff --git a/views/field_collection.views.inc b/views/field_collection.views.inc index a4e8a0d..6799a0d 100644 --- a/views/field_collection.views.inc +++ b/views/field_collection.views.inc @@ -49,5 +49,21 @@ function field_collection_field_views_data($field) { ); } + $data['field_collection_item']['edit_link'] = array( + 'field' => array( + 'title' => t('Edit link'), + 'help' => t('Provides a simple link to edit a field collection item.'), + 'handler' => 'field_collection_handler_field_edit_link', + ), + ); + + $data['field_collection_item']['delete_link'] = array( + 'field' => array( + 'title' => t('Delete link'), + 'help' => t('Provides a simple link to delete a field collection item.'), + 'handler' => 'field_collection_handler_field_delete_link', + ), + ); + return $data; } diff --git a/views/field_collection_handler_field_delete_link.inc b/views/field_collection_handler_field_delete_link.inc new file mode 100644 index 0000000..bfd9e75 --- /dev/null +++ b/views/field_collection_handler_field_delete_link.inc @@ -0,0 +1,29 @@ +item_id; + $field_collection_item = field_collection_item_load($item_id); + + if (!field_collection_item_access('delete', $field_collection_item)) { + return; + } + + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = $field_collection_item->path() . '/delete'; + $this->options['alter']['query'] = drupal_get_destination(); + + $text = !empty($this->options['text']) ? $this->options['text'] : t('Delete'); + return $text; + } + +} diff --git a/views/field_collection_handler_field_edit_link.inc b/views/field_collection_handler_field_edit_link.inc new file mode 100644 index 0000000..4f7dafe --- /dev/null +++ b/views/field_collection_handler_field_edit_link.inc @@ -0,0 +1,29 @@ +item_id; + $field_collection_item = field_collection_item_load($item_id); + + if (!field_collection_item_access('edit', $field_collection_item)) { + return; + } + + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = $field_collection_item->path() . '/edit'; + $this->options['alter']['query'] = drupal_get_destination(); + + $text = !empty($this->options['text']) ? $this->options['text'] : t('Edit'); + return $text; + } + +} -- 1.7.4.4