Create HTTP Endpoint for View modes/content templates
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3541015. -->
Reported by: [tedbow](https://www.drupal.org/user/240860)
Related to !34 !35 !33 !10 !1507 !1482
>>>
<h3 id="overview">Overview</h3>
<p>The UI will need to show the view modes of all entity types are the opt-ed into XB templating</p>
<h3 id="proposed-resolution">Proposed resolution</h3>
<p>Provide an HTTP API endpoint that will return list of all XB template enabled bundles and their view mode<br>
Until will make the UI to opt-in bundles lets have this hardcode to assume all node types are enabled.<br>
For each mode we should have metadata<br>
Proposed format</p>
<div class="codeblock">
<pre><span style="color: #000000"><span style="color: #0000BB"><?php<br>$view_modes </span><span style="color: #007700">= [<br> </span><span style="color: #DD0000">'node' </span><span style="color: #007700">=> [<br> </span><span style="color: #DD0000">'label' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Content'</span><span style="color: #007700">,<br> </span><span style="color: #DD0000">'bundles' </span><span style="color: #007700">=> [<br> </span><span style="color: #DD0000">'page' </span><span style="color: #007700">=> [<br> </span><span style="color: #DD0000">'label' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'Page'</span><span style="color: #007700">,<br> </span><span style="color: #DD0000">'view_modes' </span><span style="color: #007700">=> [<br> </span><span style="color: #DD0000">'full' </span><span style="color: #007700">=> [<br> </span><span style="color: #FF8000">// Whether template has auto-save changes. This can be tru even if<br> // existing_template is false since we auto-save templates before<br> // first publishing without creating a new saved template.<br> </span><span style="color: #DD0000">'auto-save-changes' </span><span style="color: #007700">=> </span><span style="color: #0000BB">TRUE</span><span style="color: #007700">,<br> </span><span style="color: #FF8000">// Where the there is an existing template saved.<br> </span><span style="color: #DD0000">'existing_template' </span><span style="color: #007700">=> </span><span style="color: #0000BB">TRUE</span><span style="color: #007700">,<br> </span><span style="color: #FF8000">// The ID does require an exisitng template because it is based on<br> // entity props that can't be changed.<br> </span><span style="color: #DD0000">'template_id' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'node.page.full'</span><span style="color: #007700">,<br> </span><span style="color: #FF8000">// do we need this or can the client just make it?<br> </span><span style="color: #DD0000">'layout_url' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'/xb/api/v0/layout-template/node/page/full/{entity_id'</span><span style="color: #007700">,<br> ]<br> ]<br> ]<br> ]<br> ]<br> ];<br></span><span style="color: #0000BB">?></span></span></pre></div>
<p>We could also flatten it more</p>
<div class="codeblock">
<pre><span style="color: #000000"><span style="color: #0000BB"><?php<br>$view_modes </span><span style="color: #007700">= [<br> </span><span style="color: #DD0000">'node.page.full' </span><span style="color: #007700">=> [<br> </span><span style="color: #DD0000">'entity_type' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'node'</span><span style="color: #007700">,<br> </span><span style="color: #DD0000">'bundle' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'page'</span><span style="color: #007700">,<br> </span><span style="color: #DD0000">'view_mode' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'full'</span><span style="color: #007700">,<br> </span><span style="color: #FF8000">// Whether template has auto-save changes. This can be tru even if<br> // existing_template is false since we auto-save templates before<br> // first publishing without creating a new saved template.<br> </span><span style="color: #DD0000">'auto-save-changes' </span><span style="color: #007700">=> </span><span style="color: #0000BB">TRUE</span><span style="color: #007700">,<br> </span><span style="color: #FF8000">// Where the there is an existing template saved.<br> </span><span style="color: #DD0000">'existing_template' </span><span style="color: #007700">=> </span><span style="color: #0000BB">TRUE</span><span style="color: #007700">,<br> </span><span style="color: #FF8000">// The ID does require an exisitng template because it is based on<br> // entity props that can't be changed.<br> </span><span style="color: #DD0000">'template_id' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'node.page.full'</span><span style="color: #007700">,<br> </span><span style="color: #FF8000">// do we need this or can the client just make it?<br> </span><span style="color: #DD0000">'layout_url' </span><span style="color: #007700">=> </span><span style="color: #DD0000">'/xb/api/v0/layout-template/node/page/full/{entity_id'</span><span style="color: #007700">,<br> ]<br> ];<br></span><span style="color: #0000BB">?></span></span></pre></div>
<p>Probably just depends on what is prefered by the UI</p>
<h3 id="ui-changes">User interface changes</h3>
> Related issue: [Issue #3518272](https://www.drupal.org/node/3518272)
> Related issue: [Issue #3541000](https://www.drupal.org/node/3541000)
issue