PJ McGhee
PJ McGhee

Reputation: 1

Place an Edit Button on the view node page in Drupal 7

I don't use the Drupal Tabs because they interfere with my CSS but I need the functionality of the Edit tab to be on that screen so that a user can edit the node after reviewing it.
Any ideas on how to do this? Functions? tpl placement? Thanks!

Upvotes: 0

Views: 3675

Answers (3)

batigolix
batigolix

Reputation: 1714

You can do this in a custom module as follows.

In yourcustommodule.module you implement hook_preprocess_node(). In there you check if the user has permissions to edit the node and you set the edit link.

function yourcustommodule_preprocess_node(&$vars) {
  if (node_access("update", $vars['node']) === TRUE) {
    $vars['edit_link']['#markup'] = l(t('Edit'), 'node/' . $vars['nid'] . '/edit');
  }
}

In the node.tpl.php template in the theme you print the edit link if it is available.

<?php if (isset($edit_link)) : ?>
  <p><?php print render($edit_link); ?></p>
<?php endif; ?>

If you do not have a node.tpl.php template in your theme folder than copy the one from modules/node.

Upvotes: 2

Daggar
Daggar

Reputation: 144

If you're using the Views Format "Fields", one of the fields that you can add is "Edit Link." It's pretty flexible; it will tell you what text to display in the link. That's probably the preferred option.

If you're not using the "Fields" format, it gets trickier, especially since you're already interfering with some basic drupal styling. I'd need more information about your View and your skill set to recommend a method that doesn't cause more problems.

As a sidenote: I learned Drupal theming from the outside in, and used to use CSS that would interfere with the underlying drupal mechanics like tabs and contextual links. I've moved away from that; I find very few cases where I need to interfere with native styling-- and for those I can use custom .tpl's to get around.

EDIT: Ah. If you're not using views, a custom page .tpl is probably the best way to go. If you're not familiar, the structure for any node edit link is '/node/<NID>/edit' (for clean URL's) or '/?q=node/<NID>/edit' for old-style URL's. Depending on how your path aliases are set up, '/<url-alias>/edit' may work as well but the previous ones are more reliable.

This link on drupal.org gives a few options.

Upvotes: 1

Deepak Srinivasan
Deepak Srinivasan

Reputation: 774

I think u can write a theme file(.tpl) for u specific case and theme page in whichever way u want

Upvotes: 0

Related Questions