1

I am trying to change the URL of the node edit link for a specific view. This is what I have done and it (almost) works:

  1. created a file mymodule/views/mymodule.views.inc with the following code:
/**
 * Implements hook_views_data_alter().
 */
function kd_ari_views_data_alter(&$data) {
  module_load_include('inc', 'mymodule', 'views/views_handler_field_article_link_edit');
  $data['views_entity_node']['edit_node']['field']['handler'] = 'views_handler_field_article_link_edit';
}
  1. created a second file mymodule/views/views_handler_field_article_link_edit.inc with the following code:
class views_handler_field_article_link_edit extends views_handler_field_node_link {

 function render_link($node, $values) {
   if (!node_access('update', $node)) {
     return;
   }
   $this->options['alter']['make_link'] = TRUE;
   $this->options['alter']['path'] = 'admin/mymodule/' . $node->nid;
   $text = !empty($this->options['text']) ? $this->options['text'] : t('edit');
   return $text;
 }
}

The problem is that the view displays the edit link only one time after I clear all caches... afterwards the display link is gone. Any tips would be highly appreciated.

  • can you tell me exactly what do you want to do ? just want to have a column with edit label and link to admin/mymodule/[nid] path? – Yusef Mohamadi Mar 27 '17 at 12:47
  • @zhilevan yes that is exactly what I want to achieve – dasj19 Mar 27 '17 at 12:50
  • Ok, but you choose hard solution, views is powerful, try easier methods. – Yusef Mohamadi Mar 27 '17 at 12:54
1

Add Nid as field, Set Label to Operation (or anything you want ), in Rewrite results section

  • check Override the output of this field with custom text and enter Edit text.

  • check Output this field as a custom link and in the input box enter admin/mymodule/[nid] .

save the field and enjoy the power of views rewriting.

enter image description here

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.