"starting level follow active menu item" broken by max_depth variable
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #2283897. -->
Reported by: [dblue](https://www.drupal.org/user/1186882)
>>>
<h3>Problem</h3>
<p>The introduction of the <code>$max_depth variable</code> in <code>menu_tree_block_data()</code> has broken a menu where the menu's starting level is set to the 3rd level and it's set to have the starting level follow the active menu item. When active menu item is a page on the 4th level, the menu still renders the 3rd level instead of following.</p>
<p>Example menu structure:</p>
<ul>
<li>item 1
<ul>
<li>item 1.1</li>
<li>item 1.2</li>
<ul>
<li>item 1.2.1
<ul>
<li>item 1.2.1.1</li>
<li>item 1.2.1.2</li>
</ul>
</li>
<li>item 1.2.2
<ul>
<li>item 1.2.2.1</li>
<li>item 1.2.2.2</li>
</ul>
</li>
</ul>
</ul>
</li>
</ul>
<p>Expected behavior:<br>
When browsing to, e.g. "item 1.2.1.2," the resulting menu block's title is "Item 1.2.1" and the menu's links are "item 1.2.1.1" and "item 1.2.1.2"</p>
<p>Actual behavior:<br>
When browsing to, e.g. "item 1.2.1.2," the resulting menu block's title is "Item 1.2" and the menu's links are "item 1.2.1" and "item 1.2.2"</p>
<p>Potentially relevant settings for the menu block in question:</p>
<ul>
<li>Starting level: 3rd level (tertiary)</li>
<li>Make the starting level follow the active menu item: checked</li>
<li>Starting level will be: Active menu item</li>
<li>Maximum depth: 1</li>
</ul>
<p>By giving the $max_depth parameter to <code>menu_tree_page_data()</code> it's returning a menu with no links below item 1.2.1 so the menu block has nothing to follow.</p>
<h3>Possible solution</h3>
<p>I'm not too familiar with the module's code, but for my use case, the issue is solved by eliminating the <code>-1</code> subtraction from <code>$config['level'] + $config['depth'] -1</code> when calculating max depth in <code>menu_tree_block_data()</code>. I'm not currently set up to see if this works for other settings of maximum depth, or other starting levels.</p>
<p>This looks like it might be the same cause as issue <a href="https://www.drupal.org/node/2270769">#2270769</a>, so I've added that as a related issue.</p>
<p><img src="https://www.drupal.org/files/issues/2283897-states-issue.gif" alt=""></p>
<p><img src="https://www.drupal.org/files/issues/2283897-states-issue.gif" alt=""></p>
<p><img src="https://www.drupal.org/files/issues/2283897-states-issue.gif" alt=""></p>
<p><img src="https://www.drupal.org/files/issues/2283897-states-issue.gif" alt=""></p>
> Related issue: [Issue #2270769](https://www.drupal.org/node/2270769)
> Related issue: [Issue #1572408](https://www.drupal.org/node/1572408)
> Related issue: [Issue #2394547](https://www.drupal.org/node/2394547)
issue