Hello there,

I'm using Quote with Advanced Forum and have been looking into making a normal webkit CSS button for it, much like seen with the class af-button-small - but I am unsure on how to add it to the code. It might be a relatively newbie question, but I feel like I've tried every angle but it either just disappears so I have to re-enable the module or it bugs out on me.

CommentFileSizeAuthor
quotebutton.PNG3.43 KBtrillex

Comments

Zen’s picture

Status: Active » Fixed

Such customisations are usually accomplished by overriding the theme_quote function if the existing mark-up is not sufficient. Searching for "overriding theme functions" should point you in the right direction ...

-K

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

sbart76’s picture

I guess you need something like:

      'attributes' => array('class' => t('af-button-small')),

in function_node_view or function_comment_view.

But it bugs me how to add the 'span' tags around...

Aalandriel’s picture

I ran into the same issue, trying to override the function from the template files. But since quote_node_view and quote_comment_view are not theme function, you can apparently not override them.

I rewrote the functions - it's working, but my drupal coding skills are almost non-existent and php skills are very rusty (same reason I'm not creating a patch as I haven't a clue how). However it work, so I'm thinking I've done it right.

function quote_node_view($node, $view_mode) {
  if (user_access('post comments') && in_array($node->type, _quote_variable_get('node_types')) && $node->comment == COMMENT_NODE_OPEN && _quote_variable_get('node_link_display')) {
    $links['quote'] = array(
      'title' => '<span>' . t('Quote') . '</span>',
      'href' => "comment/reply/$node->nid",
      'attributes' => array('title' => t('Quote this post in your reply.'),'class' => 'af-button-small'),
      'query' => array('quote' => 1),
      'fragment' => 'comment-form',
      'html' => TRUE
    );

    $node->content['links']['quote'] = array(
      '#links' => $links,
      '#attributes' => array('class' => array('links', 'inline'))
    );
  }
}

/**
 * Implements hook_comment_view().  
 */
function quote_comment_view($comment) {
  if (user_access('post comments')) {
    $node = node_load($comment->nid);
    if (in_array($node->type, _quote_variable_get('node_types')) && $node->comment == COMMENT_NODE_OPEN) {
      $links['quote'] = array(
        'title' => '<span>' . t('Quote') . '</span>',
      'href' => "comment/reply/$node->nid/$comment->cid",
      'attributes' => array('title' => t('Quote this post in your reply.'),'class' => 'af-button-small'),
      'query' => array('quote' => 1),
      'fragment' => 'comment-form',
      'html' => TRUE
      );

      $comment->content['links']['quote'] = array(
        '#links' => $links,
        '#attributes' => array('class' => array('links', 'inline'))
      );
    }
  }
}
Darren Shelley’s picture

I reached this page wanting a span for consistency with Advanced Forum

It would be great to have more power over this through module settings. I've only ever used quote in association with Advanced Forum which does wrap its node links in spans. It is a very common request to be able to place an background image in the button.

Quick and dirty preprocess solution to achieve this:

function MODULENAME_preprocess_comment(&$vars) {
  if ($vars['node']->type == 'forum' && isset($vars['content']['links']['quote']['#links']['quote'])) {
    $vars['content']['links']['quote']['#links']['quote']['html'] = TRUE;
    $vars['content']['links']['quote']['#links']['quote']['title'] = "<span>" . $vars['content']['links']['quote']['#links']['quote']['title'] . "</span>";
  }
}

function MODULENAME_preprocess_node(&$vars) {
  if ($vars['type'] == 'forum' && isset($vars['content']['links']['quote']['#links']['quote'])) {
    $vars['content']['links']['quote']['#links']['quote']['html'] = TRUE;
    $vars['content']['links']['quote']['#links']['quote']['title'] = "<span>" . $vars['content']['links']['quote']['#links']['quote']['title'] . "</span>";
  }
}

By the same method you could amend the classes_array to add the class you desire.
When adding a preprocess hook remember to flush the cache.

beefheartfan’s picture

I couldn't get the code in #5 to work in Drupal 7 using the preprocess hooks in a module. Instead I was able to use hook_node_view_alter() and hook_comment_view_alter(), like so:

function MODULENAME_styles_comment_view_alter(&$build) {
	if ($build['#node']->type == 'forum' && isset($build['links']['quote']['#links']['quote'])) {
		$build['links']['quote']['#links']['quote']['html'] = TRUE;
		$build['links']['quote']['#links']['quote']['title'] = '<span>'.$build['links']['quote']['#links']['quote']['title'].'</span>';
		$build['links']['quote']['#links']['quote']['attributes']['class'] = array('af-button-small');
	}
}

function MODULENAME_node_view_alter(&$build) {
	if ($build['#node']->type == 'forum' && isset($build['links']['quote']['#links']['quote'])) {
		$build['links']['quote']['#links']['quote']['html'] = TRUE;
		$build['links']['quote']['#links']['quote']['title'] = '<span>'.$build['links']['quote']['#links']['quote']['title'].'</span>';
		$build['links']['quote']['#links']['quote']['attributes']['class'] = array('af-button-small');
	}
}
topdillon’s picture

Works perfectly! Thanks very much.

I am not good at understanding Drupal code yet. Could you possibly show me how to add the private message link to the code? Should it be hyphenated or use underscore or space in some cases. I tried changing the code, but nothing.

topdillon’s picture

@beefheartfan: I spoke too soon. It doesn't work on the comments.

topdillon’s picture

Darren,

I got your preprocess functions to work by borrowing a line from @beefheartfan's function.

$vars['content']['links']['quote']['#links']['quote']['attributes']['class'] = array('af-button-small');

have you an idea how I can get it working for the privatemsg link as well? i.e. What do I replace 'quote' with?

beefheartfan’s picture

Whoops. The comments function didn't work because I didn't fully remove my original module name from the function name ('styles'). Corrected code below:

function MODULENAME_comment_view_alter(&$build) {
    if ($build['#node']->type == 'forum' && isset($build['links']['quote']['#links']['quote'])) {
        $build['links']['quote']['#links']['quote']['html'] = TRUE;
        $build['links']['quote']['#links']['quote']['title'] = '<span>'.$build['links']['quote']['#links']['quote']['title'].'</span>';
        $build['links']['quote']['#links']['quote']['attributes']['class'] = array('af-button-small');
    }
}
beefheartfan’s picture

I don't have private messaging set up on my forums, so I can't accurately tell you what to replace 'quote' with. But you could add this line within the if statement in the functions to display the entire links array and possibly find what you're looking for:

drupal_set_message('links: <pre>'.print_r($build['links'], TRUE).'</pre>');

topdillon’s picture

Thanks b but that showed nothing. Just the title 'Links'.