Module works flawlessly.

I would like to keep the UX consistent and have this same modal come up for all default Login and Register links like those for comments.

Is this possible with minimum effort?

Comments

joshuautley created an issue. See original summary.

2pha’s picture

Should be pretty easy. If the links provided by this module are already on the page then you don't need to worry about the modals.
Just theme your register and login links the same way this module does.
You could do it by implementing theme_link().
For the login, you just need to make it like this:
<a href="#" data-toggle="modal" data-target="#login-modal">' . t('Login') . '</a>
and the register like this:
<a href="#" data-toggle="modal" data-target="#register-modal">' . t('Register') . '</a>

2pha’s picture

Status: Active » Closed (works as designed)
joshuautley’s picture

Excellent thank you.

joshuautley’s picture

Worked like a charm!

joshuautley’s picture

This may help someone who finds this thread....

I wanted to trigger the modal from the node links, specifically for the comment module. Here is the function I put in my template.php file....

/**
 * Returns HTML for a "you can't post comments" notice.
 *
 * @param $variables
 *   An associative array containing:
 *   - node: The comment node.
 *
 * @ingroup themeable
 */
function YOURTHEME_comment_post_forbidden($variables) {
  $node = $variables['node'];
  global $user;

  // Since this is expensive to compute, we cache it so that a page with many
  // comments only has to query the database once for all the links.
  $authenticated_post_comments = &drupal_static(__FUNCTION__, NULL);

  if (!$user->uid) {
    if (!isset($authenticated_post_comments)) {
      // We only output a link if we are certain that users will get permission
      // to post comments by logging in.
      $comment_roles = user_roles(TRUE, 'post comments');
      $authenticated_post_comments = isset($comment_roles[DRUPAL_AUTHENTICATED_RID]);
    }

    if ($authenticated_post_comments) {
      // We cannot use drupal_get_destination() because these links
      // sometimes appear on /node and taxonomy listing pages.
      if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_SEPARATE_PAGE) {
        $destination = array('destination' => "comment/reply/$node->nid#comment-form");
      }
      else {
        $destination = array('destination' => "node/$node->nid#comment-form");
      }

      if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
        // Users can register themselves.
        return t('<a data-target="#login-modal" data-toggle="modal" href="#">Sign In</a> or <a data-target="#register-modal" data-toggle="modal" href="#">Join Now!</a> to post comments');
      }
      else {
        // Only admins can add new users, no public registration.
        return t('<a data-target="#login-modal" data-toggle="modal" href="#">Sign In</a> to post comments');
      }
    }
  }
}

All I changed was...

<a data-target="#login-modal" data-toggle="modal" href="#">Sign In</a> or <a data-target="#register-modal" data-toggle="modal" href="#">Join Now!</a>

And...

<a data-target="#login-modal" data-toggle="modal" href="#">Sign In</a>

Here is the original function from the comment.module.... (lines 2364 - 2400)

function theme_comment_post_forbidden($variables) {
  $node = $variables['node'];
  global $user;

  // Since this is expensive to compute, we cache it so that a page with many
  // comments only has to query the database once for all the links.
  $authenticated_post_comments = &drupal_static(__FUNCTION__, NULL);

  if (!$user->uid) {
    if (!isset($authenticated_post_comments)) {
      // We only output a link if we are certain that users will get permission
      // to post comments by logging in.
      $comment_roles = user_roles(TRUE, 'post comments');
      $authenticated_post_comments = isset($comment_roles[DRUPAL_AUTHENTICATED_RID]);
    }

    if ($authenticated_post_comments) {
      // We cannot use drupal_get_destination() because these links
      // sometimes appear on /node and taxonomy listing pages.
      if (variable_get('comment_form_location_' . $node->type, COMMENT_FORM_BELOW) == COMMENT_FORM_SEPARATE_PAGE) {
        $destination = array('destination' => "comment/reply/$node->nid#comment-form");
      }
      else {
        $destination = array('destination' => "node/$node->nid#comment-form");
      }

      if (variable_get('user_register', USER_REGISTER_VISITORS_ADMINISTRATIVE_APPROVAL)) {
        // Users can register themselves.
        return t('<a href="@login">Log in</a> or <a href="@register">register</a> to post comments', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));
      }
      else {
        // Only admins can add new users, no public registration.
        return t('<a href="@login">Log in</a> to post comments', array('@login' => url('user/login', array('query' => $destination))));
      }
    }
  }
}
slaurent’s picture

Hi,

That's almost exactly what I need, except I need to apply it to a "you must login or register to view this form" message that appears when a non-authorized user wants to fill a webform . I'm looking for the good hook, though i'm not experienced with using hooks and I can't find it... Will it be in webform or in core form?

Thanks in advance from a Drupal newbie!

2pha’s picture

It seems the webform module outputs the message wit a call to drupal_set_message().
You could do as outlined at THIS stackoverflow question.
Alternatively, you could probably write some javascript to search for links to the login or register pages, and change them as needed.
Why the webform module still does not easily allow you to set these messages I don't know. Maybe it's worth putting a feature request in the webform module issue queue.