From 30e0b0a544398f3e525e50c496c6f20b69123454 Mon Sep 17 00:00:00 2001 From: jucallme Date: Mon, 17 Mar 2014 15:17:35 -0300 Subject: [PATCH] field_collection-views-edit-delete-link --- views/field_collection.views.inc | 29 +++++++++++++ views/field_collection_handler_field_link.inc | 47 ++++++++++++++++++++++ views/field_collection_handler_field_link_add.inc | 24 +++++++++++ .../field_collection_handler_field_link_delete.inc | 24 +++++++++++ views/field_collection_handler_field_link_edit.inc | 24 +++++++++++ 5 files changed, 148 insertions(+) create mode 100644 views/field_collection_handler_field_link.inc create mode 100644 views/field_collection_handler_field_link_add.inc create mode 100644 views/field_collection_handler_field_link_delete.inc create mode 100644 views/field_collection_handler_field_link_edit.inc diff --git a/views/field_collection.views.inc b/views/field_collection.views.inc index 9bb986c..9e4f219 100644 --- a/views/field_collection.views.inc +++ b/views/field_collection.views.inc @@ -53,5 +53,34 @@ function field_collection_field_views_data($field) { ); } + $data['field_collection_item']['view_item'] = array( + 'title' => t('Link'), + 'help' => t('Provide a simple link to the field collection item.'), + 'field' => array( + 'handler' => 'field_collection_handler_field_link', + ), + ); + $data['field_collection_item']['add_item'] = array( + 'title' => t('Add link'), + 'help' => t('Provide a simple link to edit the field collection item.'), + 'field' => array( + 'handler' => 'field_collection_handler_field_link_add', + ), + ); + $data['field_collection_item']['edit_item'] = array( + 'title' => t('Edit link'), + 'help' => t('Provide a simple link to edit the field collection item.'), + 'field' => array( + 'handler' => 'field_collection_handler_field_link_edit', + ), + ); + $data['field_collection_item']['delete_item'] = array( + 'field' => array( + 'title' => t('Delete link'), + 'help' => t('Provide a simple link to delete the field collection item.'), + 'handler' => 'field_collection_handler_field_link_delete', + ), + ); + return $data; } diff --git a/views/field_collection_handler_field_link.inc b/views/field_collection_handler_field_link.inc new file mode 100644 index 0000000..e6a1704 --- /dev/null +++ b/views/field_collection_handler_field_link.inc @@ -0,0 +1,47 @@ +additional_fields['item_id'] = 'item_id'; + } + + function option_definition() { + $options = parent::option_definition(); + $options['text'] = array('default' => 'view', '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(); + $this->add_additional_fields(); + } + + function render($values) { + $text = !empty($this->options['text']) ? $this->options['text'] : t('view'); + $item = field_collection_item_load($this->get_value($values, 'item_id')); + $path = field_collection_field_get_path((array) $item); + return $this->render_link($text, $path, $item); + } + + function render_link($text, $path, $item) { + if (field_collection_item_access('view', $item)) { + return l($text, $path . '/' . $item->item_id); + } + return NULL; + } +} diff --git a/views/field_collection_handler_field_link_add.inc b/views/field_collection_handler_field_link_add.inc new file mode 100644 index 0000000..b1807aa --- /dev/null +++ b/views/field_collection_handler_field_link_add.inc @@ -0,0 +1,24 @@ + 'add', 'translatable' => TRUE); + return $options; + } + + /** + * Renders the link. + */ + function render_link($text, $path, $item) { + if (field_collection_item_access('update', $item)) { + return l($text, $path . '/add/' . $item->hostEntityType() . '/' . $item->hostEntityId()); + } + return NULL; + } +} diff --git a/views/field_collection_handler_field_link_delete.inc b/views/field_collection_handler_field_link_delete.inc new file mode 100644 index 0000000..3f64c77 --- /dev/null +++ b/views/field_collection_handler_field_link_delete.inc @@ -0,0 +1,24 @@ + 'delete', 'translatable' => TRUE); + return $options; + } + + /** + * Renders the link. + */ + function render_link($text, $path, $item) { + if (field_collection_item_access('delete', $item)) { + return l($text, $path . '/' . $item->item_id . '/delete'); + } + return NULL; + } +} diff --git a/views/field_collection_handler_field_link_edit.inc b/views/field_collection_handler_field_link_edit.inc new file mode 100644 index 0000000..ca1df4e --- /dev/null +++ b/views/field_collection_handler_field_link_edit.inc @@ -0,0 +1,24 @@ + 'edit', 'translatable' => TRUE); + return $options; + } + + /** + * Renders the link. + */ + function render_link($text, $path, $item) { + if (field_collection_item_access('update', $item)) { + return l($text, $path . '/' . $item->item_id . '/edit'); + } + return NULL; + } +} -- 1.8.5.2 (Apple Git-48)