3
  1. Can someone explain me, which page is shown as default when entering the system configuration in the backend? What is the logic behind it?

  2. Is there a cookie based "remember the last system config page you visited and show it when you come back" function or did it exist in the past? I thought there was but I am not sure anymore.

The reason I am asking is, when I enter the System Configuration, I see a blank content page and I am not sure but I think there was content there before. It seems I messed up something :) But every page in the system config that I click works as expected.

Thanks in advance! :-)

enter image description here

8

If no section request parameter is present, the currently active section is simply the first one in the ordered list of system.xml sections.

This happens in Mage_Adminhtml_Block_System_Config_Tabs::initTabs().
(I have removed parts of the method for the sake of clarity!)

public function initTabs()
{
    $current = $this->getRequest()->getParam('section');
    $configFields = Mage::getSingleton('adminhtml/config');
    $sections = $configFields->getSections($current);
    $sections = (array)$sections;
    usort($sections, array($this, '_sort'));
    foreach ($sections as $section) {
    if ((empty($current) && $sectionAllowed)) {
        $current = $code;
        $this->getRequest()->setParam('section', $current);
    }
    // ... leave out the rest of the method ...

The _sort() callback method simply sorts the sections by <sort_order> value.
So which section is sorted first?

As it happens, thats the <paypal> section, which is configured in Mage/PaypalUk/etc/system.xml!
This section has no <sort_order> node, so it is sorted to the top.

But, you may ask yourself, why isn't the section shown?

Well, the section configuration is not only missing the <sort_order> declaration, it is also missing the <show_in_default>, <show_in_website> and <show_in_store> settings.
And the default, if these are not set explicitly to be visible, is to hide the part of the user interface (code found in Mage_Adminhtml_Block_System_Config_Form::_canShowField()).

If we where to add <show_in_default>1</show_in_default> to the <paypal> section, the default page would no longer be empty, it would show the Website Payments Pro (Payflow Edition) group.

If you want a different section to show up as the default, just give it a <sort_order> that sorts before an empty string ;)

In previous versions of Magento the <paypal> section had a sort order set, and - if no custom module messed it up - the default section would be the General section from the Mage/Core/etc/system.xml file.
I believe (but don't know) that the current behavior with the blank page is a bug.

  • Excellent answer! As always :) Thank you very much! – Celldweller Oct 19 '13 at 17:35
  • 2
    This also helped me in 2015! ;) – mniess May 19 '15 at 16:37
  • Upgrade from 1.6.2.0 to 1.9.2.2, Magento lost the default opening System Config => General page. Everything displays, including the Save Config button and gray horizontal rule, except any configuration main panel (typically General Configurations). Found app/code/core/Mage/PaypalUk/etc/system.xml left over from 1.3.1.1 that had been modified to have all the <show_in_*> settings so it would show, but caused issues due to its presence in 1.9.2.2. Great help as your answer pointed me to the issue!!! – Fiasco Labs Dec 2 '15 at 5:35
5

EDIT: This is the right answer for a different question, namely
Which page is shown by default after logging into the admin interface?
I'll leave the answer because of the time spent writing it, and someone else might find it useful.
The proper answer is here: https://magento.stackexchange.com/a/9704/766

TL;DR

To summarize, if any page is requested without a valid user session, the client is redirected to the login page.
After a successful login, the page which was requested before the login was shown will be requested again.
If the adminhtml index action was requested, that will be the configured default page.

Below is an overview of the whole process.

How is a "not logged in" request redirected to the login page?

To begin with, lets assume we are requesting the /admin route for the first time as a not logged in user. Lets have a look at the admin interface entry point:

the Mage_Adminhtml_IndexController::indexAction() method.

public function indexAction()
{
    $session = Mage::getSingleton('admin/session');
    $url = $session->getUser()->getStartupPageUrl();
    if ($session->isFirstPageAfterLogin()) {
        // retain the "first page after login" value in session (before redirect)
        $session->setIsFirstPageAfterLogin(true);
    }
    $this->_redirect($url);
}

The getStartupPageUrl() default page can be configured under

System > Config > Admin > Startup Page

So basically the request now changes to a different controller action within the adminhtml interface. And we still aren't logged in.

To understand how we end up on the login page, we need to examine the preDispatch() method of the class Mage_Adminhtml_Controller_Action, from which all adminhtml page controllers are extended.

The code section we need to look at is

if ($this->getRequest()->isDispatched()
    && $this->getRequest()->getActionName() !== 'denied'
    && !$this->_isAllowed()) {
        $this->_forward('denied');
        $this->setFlag('', self::FLAG_NO_DISPATCH, true);
        return $this;
}

The important line is && !$this->_isAllowed()).
The method _isAllowed() should be implemented by every Adminhtml action controller to the ACL, if the current user is permitted to view the requested page. Here an example for the product grid:

protected function _isAllowed()
{
    return Mage::getSingleton('admin/session')->isAllowed('catalog/products');
}

Regarding your question, the admin/session does this:

public function isAllowed($resource, $privilege = null)
{
    $user = $this->getUser();
    $acl = $this->getAcl();

    if ($user && $acl) {
        // .. code check the ACL omitted for clarity
    }
    return false;
}

Since we are not logged in, $this->getUser(); returns false, so moving back to the preDispatch() method, we are now forwarded to the deniedAction().

$this->_forward('denied');

And here is where we are finally sent to the login page as a logged out user.

public function deniedAction()
{
    $this->getResponse()->setHeader('HTTP/1.1','403 Forbidden');
    if (!Mage::getSingleton('admin/session')->isLoggedIn()) {
        $this->_redirect('*/index/login');
        return;
    }
    $this->loadLayout(array('default', 'adminhtml_denied'));
    $this->renderLayout();
}

So this is how we end up on the login page. Any request to an adminhtml page not being logged in will end up being the login page.
To summarize, if any page is requested without a valid user session, the client is redirected to the login page.
But your question was, "How does Magento decide which page to display after login?".

The Admin Login Process

In contrast to the frontend, there is no loginPostAction().
Instead there is an observer configured in Mage/Adminhtml/etc/config.xml for the controller_action_predispatch event in the <adminhtml> area.
It involves the method Mage_Admin_Model_Observer::actionPreDispatchAdmin().

If the requested action is included in the list hardcoded of hardcoded open actions, no further action is taken.

$openActions = array(
    'forgotpassword',
    'resetpassword',
    'resetpasswordpost',
    'logout',
    'refresh' // captcha refresh
);

Otherwise, if no user is present for the session (that is, the user is currently logged out), the following code is processed.

if ($request->getPost('login')) {
    $postLogin  = $request->getPost('login');
    $username   = isset($postLogin['username']) ? $postLogin['username'] : '';
    $password   = isset($postLogin['password']) ? $postLogin['password'] : '';
    $session->login($username, $password, $request);
    $request->setPost('login', null);
}

Basically, this allows a login post to any adminhtml page to be processed.

The code which is responsible for determining which page to display after the login can be found in the admin/session model.

It starts with the method login($username, $password, $request = null).
If the authentication is successful, $this->setIsFirstPageAfterLogin(true); is called.
This is not a magic setter, it will simply set the $_isFirstPageAfterLogin property, which will keep that value only for the duration of that single request during which the login was posted.
The the session checks the request object.

$requestUri = $this->_getRequestUri($request);
if ($requestUri) {
    Mage::dispatchEvent('admin_session_user_login_success', array('user' => $user));
    header('Location: ' . $requestUri);
    exit;
}

Not nice, but it works. So where does this $requestUri come from?

Mage::getSingleton('adminhtml/url')->getUrl('*/*/*', array('_current' => true));

Its the currently request URL!

So whatever page was requested before the login will be shown again. If the index action was requested, that will be the configured default page.

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.