1

If I set the default front page to use a node with an alias, e.g. 'home', drupal_is_front_page() fails as it compares the un-aliased path ($_GET['q']) with the value of the 'site_frontpage' variable. Would it not be better to save the 'site_frontpage' variable as un-aliased path, or am I missing something?

Sorry, this is actually what happens. The variable must have been set to 'home' by something else.

  • if you set home inside module, so you can find its main path there and set it as front page – Mohammad Ali Akbari Mar 26 '12 at 12:55
3

drupal_is_front_page() compares the content of the "site_frontpage" variable with an un-aliased path because the content of that variable is set to an un-aliased path, on the page at admin/config/system/site-information.

In system_site_information_settings(), the form builder for that page, the content of the "site_frontpage" field is set using the following code:

'#default_value' => (variable_get('site_frontpage') != 'node' ? drupal_get_path_alias(variable_get('site_frontpage', 'node')) : ''), 

In system_site_information_settings_validate(), the form validation handler for that page, the value of the "site_frontpage" field is set using the following code:

  if (empty($form_state['values']['site_frontpage'])) {
    // Set to default "node".
    form_set_value($form['front_page']['site_frontpage'], 'node', $form_state);
  }
  else {
    // Get the normal path of the front page.
    form_set_value($form['front_page']['site_frontpage'], drupal_get_normal_path($form_state['values']['site_frontpage']), $form_state);
  }

What is being saved in the "site_frontpage" variable is the normal path (a.k.a. the un-aliased one). It is the correct what drupal_is_front_page() does.
If there is a module that set the value of that variable to a path alias, then the code of that module should be changed, as that module is not working with the actual Drupal code.

| improve this answer | |

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.