findPolicy forced to mgr context in core code of modmediasource.class.php

In doing some custom work on a site, I found a line the core code that doesn’t make sense in core/model/modx/sources/modmediasource.class.php. The line is “$context = ‘mgr’;”, as shown in context below:

    public function findPolicy($context = '') {
        $policy = array();
        $enabled = true;
        $context = 'mgr';
        if ($context === $this->xpdo->context->get('key')) {
            $enabled = (boolean) $this->xpdo->getOption('access_media_source_enabled', null, true);

The line renders the $context parameter useless and forces the value to be ‘mgr’ instead.

On the site I am working on, it generates a lot of messages about the ‘mgr’ context when I am trying to access pages of the ‘web’ context.

I have removed the line from our code and don’t see anything negatively impacted. Does anyone know why this parameter is being forced to the ‘mgr’ context in all cases or see anything wrong with removing this line?

The $context variable here has “function parameter” scope (so it’s local to the function). It can’t affect anything outside the function, but you’re right that the code looks wrong.

My guess is that the $context = 'mgr'; line should be replaced with this:

$context = empty($context) ? 'mgr' : $context;

I think that will solve your problem in a way that’s less likely to cause trouble, since there may be code that calls the function with no argument.