@@ -215,20 +215,20 @@ protected function buildAddSectionLink(SectionStorageInterface $section_storage,
215215 // layout or an empty layout.
216216 if ($ delta === count ($ section_storage )) {
217217 if ($ delta === 0 ) {
218- $ title = $ this ->t ('Add Section ' );
218+ $ title = $ this ->t ('Add section ' );
219219 }
220220 else {
221- $ title = $ this ->t ('Add Section <span class="visually-hidden">at end of layout</span> ' );
221+ $ title = $ this ->t ('Add section <span class="visually-hidden">at end of layout</span> ' );
222222 }
223223 }
224224 // If the delta and the count are different, it is either the beginning of
225225 // the layout or in between two sections.
226226 else {
227227 if ($ delta === 0 ) {
228- $ title = $ this ->t ('Add Section <span class="visually-hidden">at start of layout</span> ' );
228+ $ title = $ this ->t ('Add section <span class="visually-hidden">at start of layout</span> ' );
229229 }
230230 else {
231- $ title = $ this ->t ('Add Section <span class="visually-hidden">between @first and @second</span> ' , ['@first ' => $ delta , '@second ' => $ delta + 1 ]);
231+ $ title = $ this ->t ('Add section <span class="visually-hidden">between @first and @second</span> ' , ['@first ' => $ delta , '@second ' => $ delta + 1 ]);
232232 }
233233 }
234234
@@ -288,35 +288,65 @@ protected function buildAdministrativeSection(SectionStorageInterface $section_s
288288 foreach ($ layout_definition ->getRegions () as $ region => $ info ) {
289289 if (!empty ($ build [$ region ])) {
290290 foreach (Element::children ($ build [$ region ]) as $ uuid ) {
291- $ build [$ region ][$ uuid ]['#attributes ' ]['class ' ][] = 'js-layout-builder-block ' ;
291+ if ($ sections_editable ) {
292+ $ build [$ region ][$ uuid ]['#attributes ' ]['class ' ][] = 'js-layout-builder-block ' ;
293+ }
292294 $ build [$ region ][$ uuid ]['#attributes ' ]['class ' ][] = 'layout-builder-block ' ;
293295 $ build [$ region ][$ uuid ]['#attributes ' ]['data-layout-block-uuid ' ] = $ uuid ;
294296 $ build [$ region ][$ uuid ]['#attributes ' ]['data-layout-builder-highlight-id ' ] = $ this ->blockUpdateHighlightId ($ uuid );
295- $ build [$ region ][$ uuid ]['#contextual_links ' ] = [
296- 'layout_builder_block ' => [
297- 'route_parameters ' => [
298- 'section_storage_type ' => $ storage_type ,
299- 'section_storage ' => $ storage_id ,
300- 'delta ' => $ delta ,
301- 'region ' => $ region ,
302- 'uuid ' => $ uuid ,
303- ],
304- // Add metadata about the current operations available in
305- // contextual links. This will invalidate the client-side cache of
306- // links that were cached before the 'move' link was added.
307- // @see layout_builder.links.contextual.yml
308- 'metadata ' => [
309- 'operations ' => 'move:update:remove ' ,
310- ],
297+ $ contextual_link_settings = [
298+ 'route_parameters ' => [
299+ 'section_storage_type ' => $ storage_type ,
300+ 'section_storage ' => $ storage_id ,
301+ 'delta ' => $ delta ,
302+ 'region ' => $ region ,
303+ 'uuid ' => $ uuid ,
311304 ],
312305 ];
306+ if ($ is_translation ) {
307+ $ component = $ section ->getComponent ($ uuid );
308+ if ($ component ->hasTranslatableConfiguration ()) {
309+ $ contextual_group = 'layout_builder_block_translation ' ;
310+ /** @var \Drupal\Core\Language\LanguageInterface $language */
311+ if ($ language = $ section_storage ->getTranslationLanguage ()) {
312+ $ contextual_link_settings ['route_parameters ' ]['langcode ' ] = $ language ->getId ();
313+ }
314+
315+ /** @var \Drupal\layout_builder\Plugin\Block\InlineBlock $plugin */
316+ $ plugin = $ component ->getPlugin ();
317+ if ($ plugin instanceof DerivativeInspectionInterface && $ plugin ->getBaseId () === 'inline_block ' ) {
318+ $ configuration = $ plugin ->getConfiguration ();
319+ /** @var \Drupal\block_content\Entity\BlockContent $block */
320+ $ block = $ this ->entityTypeManager ->getStorage ('block_content ' )->loadRevision ($ configuration ['block_revision_id ' ]);
321+ if ($ block ->isTranslatable ()) {
322+ $ contextual_group = 'layout_builder_inline_block_translation ' ;
323+ }
324+ }
325+ }
326+ }
327+ else {
328+ // Add metadata about the current operations available in
329+ // contextual links. This will invalidate the client-side cache of
330+ // links that were cached before the 'move' link was added.
331+ // @see layout_builder.links.contextual.yml
332+ $ contextual_link_settings ['metadata ' ] = [
333+ 'operations ' => 'move:update:remove ' ,
334+ ];
335+ $ contextual_group = 'layout_builder_block ' ;
336+ }
337+ if (isset ($ contextual_group )) {
338+ $ build [$ region ][$ uuid ]['#contextual_links ' ] = [
339+ $ contextual_group => $ contextual_link_settings ,
340+ ];
341+ }
313342 }
314343 }
315344
316345 $ build [$ region ]['layout_builder_add_block ' ]['link ' ] = [
317346 '#type ' => 'link ' ,
347+ '#access ' => $ sections_editable ,
318348 // Add one to the current delta since it is zero-indexed.
319- '#title ' => $ this ->t ('Add Block <span class="visually-hidden">in section @section, @region region</span> ' , ['@section ' => $ delta + 1 , '@region ' => $ region_labels [$ region ]]),
349+ '#title ' => $ this ->t ('Add block <span class="visually-hidden">in section @section, @region region</span> ' , ['@section ' => $ delta + 1 , '@region ' => $ region_labels [$ region ]]),
320350 '#url ' => Url::fromRoute ('layout_builder.choose_block ' ,
321351 [
322352 'section_storage_type ' => $ storage_type ,
@@ -407,7 +437,7 @@ protected function buildAdministrativeSection(SectionStorageInterface $section_s
407437 'data-dialog-renderer ' => 'off_canvas ' ,
408438 ],
409439 ],
410- // The section label is added to sections without a "Configure Section "
440+ // The section label is added to sections without a "Configure section "
411441 // link, and is only visible when the move block dialog is open.
412442 'section_label ' => [
413443 '#markup ' => $ this ->t ('<span class="layout-builder__section-label" aria-hidden="true">Section @section</span> ' , ['@section ' => $ delta + 1 ]),
0 commit comments