1

I'm using the following observer to add the editor handle to a System > Configuration section:

Partial config.xml:

<adminhtml>
    <!-- Events -->
    <events>
        <!-- Triggered before layout load -->
        <controller_action_layout_load_before>
            <observers>
                <digitalpianism_test_controller_action_layout_load_before>
                    <type>singleton</type>
                    <class>test/admin_observer</class>
                    <method>addEditorHandle</method>
                </digitalpianism_test_controller_action_layout_load_before>
            </observers>
        </controller_action_layout_load_before>
    </events>
</adminhtml>

Then my Admin/Observer.php file looks like this:

class DigitalPianism_Wall2time_Model_Admin_Observer
{
    /**
     * Add the editor handle to the system configuration Test section
     * @param Varien_Event_Observer $observer
     */
    public function addEditorHandle(Varien_Event_Observer $observer)
    {
        $layout = $observer->getEvent()->getLayout();
        $params = $observer->getAction()->getRequest()->getParams();
        // We add the editor handle when viewing the section where the chooser widget is displayed
        if (array_key_exists('section',$params) && $params['section'] == "test")
        {
            $layout->getUpdate()->addHandle('editor');
        }
    }
}

That works perfectly fine as a full administrator, I can use the editor handle to use widget in that specific section of my module.

However, if I use an user with a role limited to the System > Configuration > Test section only, I get the following error in the JS console:

ReferenceError: WysiwygWidget is not defined

When I check the resources loaded, I find that the mage/adminhtml/wysiwyg/widget.js is not getting loaded from the editor handle, I assume it has something to do with the resources I assigned to my user role but I can't find which ACL is related to this specific editor handle.

NB: user allowed with another configuration section allowed access won't face the problem, it only happens if the user can only access the System > Configuration > Test section.

5
  • 1
    Interesting question. I thought, layout and ACL were not coupled at all but I found that you can add a ACL restriction to <remove> elements: <remove name="BLOCKNAME" acl="RESOURCE" /> only removes the block if the user has permissions for RESOURCE. But the remove tag seems to be the only one and has nothing to do with the editor handle. Commented Mar 8, 2016 at 8:05
  • 1
    Actually it seems to be the other way around: if a block has an acl attribute it may not be removed. Weird. Commented Mar 8, 2016 at 8:11
  • But that still does not help you. The problem must be somewhere else. I'm sure, other pages with the editor handle work with restricted users. Commented Mar 8, 2016 at 8:14
  • @fschmengler you made interesting points, even if that does not help for this problem, it enlighted me on some mechanisms I wasn't aware of. I'm about to do more tests today, I'll update my question when I find more details Commented Mar 8, 2016 at 8:27
  • @fschmengler it was hard but I've found the root of my problem! Commented Mar 8, 2016 at 10:07

1 Answer 1

1

After digging deep into the code, here is what I've found:

The original problem is caused by the fact that with a user using a role only limited to a specific System > Configuration section, when you log in, you land directly on the corresponding System > Configuration section page with an URL that looks like this:

http://www.shop.com/index.php/admin/system_config/index/key/...

Because of this, the following condition in my Observer.php is not true as no parameters have been set:

if (array_key_exists('section',$params) && $params['section'] == "test")
{
    $layout->getUpdate()->addHandle('editor');
}

Now why is there no parameters set and why I still can land on the right section of my configuration page ?

Well, that was a tough one, it's definitely related to ACL as I guessed, and I assumed it was somehow triggered in a controller or via an observer.

Here is the relevant code of app/code/core/Mage/Adminhtml/controllers/System/ConfigController.php in the editAction method:

Mage::getSingleton('adminhtml/config_data')
        ->setSection($current)
        ->setWebsite($website)
        ->setStore($store);

$configFields = Mage::getSingleton('adminhtml/config');

$sections     = $configFields->getSections($current);
$section      = $sections->$current;

Even if that looks like it is what we're looking for, it's totally not. The $sections variable contains every single system configuration section, no restriction based on the admin user have been applied yet. On top of that, the $current and thus $section are empty.

Well, no luck here! So how do I land on my section??

I'll save you the time spent looking for the file that was handling all this magic: app/code/core/Mage/Adminhtml/Block/System/Config/Tabs.php!

Well what ? A block is handling the ACL ?

Yep, here is the code under the initTabs method:

foreach ($sections as $section) {
    ...
    $sectionAllowed = $this->checkSectionPermissions($code);
    if ((empty($current) && $sectionAllowed)) {

       $current = $code;
       $this->getRequest()->setParam('section', $current);
    }
    ...
}

To summarize:

  • The ConfigController.php mentioned above first checks if a section is set in the parameters (a tab has been clicked basically).
  • It then loads the layout (my Observer.php is getting triggered without luck)
  • Then it appends the adminhtml/system_config_tabs to the left block and calls the initTabs method
  • Only now the section parameter is added after looping through every single section of the configuration and keeping only the allowed ones.

Final answer: there is no way to add the editor handle via an Observer to a System Configuration section for a user role only limited to that section.

Alternative solutions:

We can change the condition under the Observer.php file so the editor handle is added for every section of the configuration:

if ($observer->getAction()->getRequest()->getControllerName() == "system_config")
{
    $layout->getUpdate()->addHandle('editor');
}

Or we change the user role so it is allowed to see an upper section of the configuration, thus, the user always land on this upper section and when he/she clicks the tab where we want to add the editor handle, the parameter is added and the handle is added.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.