1

I have overwritten my login page with a file named page--user--login.tpl.php. Now I have this:

<div class="main-container container">
  <div class="row-fluid">
    <section<?php print $content_column_class; ?>>
      <a id="main-content"></a>
        <h1>Xmed.be Stocksolutions</h1>
        <p>"We help you Xchange your stock"</p>
      <?php print render($title_suffix); ?>
      <?php print $messages; ?>
      <?php if (!empty($page['help'])): ?>
        <?php print render($page['help']); ?>
      <?php endif; ?>
      <?php if (!empty($action_links)): ?>
        <ul class="action-links"><?php print render($action_links); ?></ul>
      <?php endif; ?>
      <?php print render($page['content']); ?>
      <a href="user/register">NO ACCOUNT? REGISTER</a>
      <a href="user/password">FORGOT PASSWORD?</a>
    </section>
  </div>
</div>

As you can see I added two links at the end (register and password). But I would like them to be inside $page['content'], so that they are in the section. How can I edit the $content variable, loop through it or something?

UPDATE:

Now I've added in my template.php:

function hook_form_user_login_alter(&$form, &$form_state, $form_id) {
    var_dump('test');
}

But I'm not getting test around my form (also looked in html).

I've also already tried:

function hook_form_alter(&$form, &$form_state, $form_id) {
    dpm($form);
}

But no result or something ...

2
  • You mean $page['content'], not $content...
    – Felix Eve
    Apr 17 '14 at 8:50
  • yes, sorry. Changed it.
    – nielsv
    Apr 17 '14 at 8:55
2

You can use hook_page_alter to add them into the content array:

function YOUR_MODULE_page_alter(&$page) {

  // Check if this is the correct page.
  if(!isset($page['content']['system_main']['#form_id']) || $page['content']['system_main']['#form_id'] != 'user_login') return;

  // Add links.
  $page['content']['system_main']['register'] = array(
    '#markup' => '<p><a href="user/register">NO ACCOUNT? REGISTER</a></p>',
    '#weight' => 20
  );
  $page['content']['system_main']['password'] = array(
    '#markup' => '<p><a href="user/password">FORGOT PASSWORD?</a></p>',
    '#weight' => 21
  );

}

Another option here would be to use hook_form_alter instead. Although hook_form_FORM_ID_alter may well be the most efficient option as it will only run for this specific form removing any overhead from other pages.

5

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.