Setting "Use as title" to respect the initial visibility level
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3321699. -->
Reported by: [agileware](https://www.drupal.org/user/89106)
Related to !34 !13
>>>
<h3 id="summary-problem-motivation">Problem/Motivation</h3>
<p>Currently there is no way to set the block's title to the parent of the initial visibility level when this is set higher than level 2.<br>
This is to me the expected behaviour when using "Active trail's root title", since the parent of the configured visibility level is the Active trail's <i>effective</i> root, however when is actually used is the 1st level item of the Active trail</p>
<h4 id="summary-steps-reproduce">Steps to reproduce</h4>
<ol>
<li>Create a menu with the structure:
<ul>
<li>Food
<ul>
<li>Vegetables</li>
<li>Grains
<ul>
<li>Wheat</li>
<li>Barley</li>
</ul>
</li>
</ul>
</li>
<li>Drink</li>
<li>Equipment</li>
</ul>
</li>
<li>Add a menu block that will appear on the <i>Wheat</i> and <i>Barley</i> pages with <b>Initial visibility level</b> configured as 3 and <b>Use as title</b> configured as "Active trail's root title"</li>
<li>Navigate to the <i>Wheat</i> or <i>Barley</i> page</li>
<li>Observe that the menu block contains <i>Wheat</i> and <i>Barley</i>, but that the title is <i>Food</i> rather than <i>Grains</i>
</li></ol>
<p>I don't imagine this is super useful to most people.</p>
<h3 id="summary-proposed-resolution">Proposed resolution</h3>
<p>Update "Active trail's root title" to use the immediate parent of the visibility level rather than the 1st level item of the current trail. Have a patch ready for this.</p>
<p>An alternative approach would be to add a new option such as "Visible trail root" to avoid the situation where someone is intentionally using the current behaviour with a gap the trail (IMO this is unlikely, but people do their own thing).</p>
<h3 id="summary-remaining-tasks">Remaining tasks</h3>
<p>Updated code has not yet been tested with "Make the initial visibility level follow the active menu item" option checked.</p>
<h3 id="summary-ui-changes">User interface changes</h3>
<p>Menu Blocks with "Active trail's root title" set will display the parent of the visible portion of the active menu trail as the block title instead of the 1st level item in the trail as is used now.</p>
<h3 id="summary-api-changes">API changes</h3>
<p>None</p>
<h3 id="summary-data-model-changes">Data model changes</h3>
<p>In-memory only: Add a protected <code>$menuRoot</code> property to the <code>Drupal\menu_block\Plugin\Block</code> to propagate the <code>$menu_root</code> id from the <code>build()</code> method to the <code>getActiveTrailRootTitle()</code> method.</p>
> Related issue: [Issue #3445576](https://www.drupal.org/node/3445576)
issue