You are here

function gutenberg_render_block_core_navigation in Gutenberg 8.2

Renders the `core/navigation` block on server.

Parameters

array $content The saved content.:

array $block The parsed block.:

Return value

string Returns the post content with the legacy widget added.

1 string reference to 'gutenberg_render_block_core_navigation'
navigation.php in vendor/gutenberg/block-library/blocks/navigation.php

File

vendor/gutenberg/block-library/blocks/navigation.php, line 130

Code

function gutenberg_render_block_core_navigation($content, $block) {
  if ('core/navigation' !== $block['blockName']) {
    return $content;
  }
  $block['innerBlocks'] = gutenberg_block_core_navigation_empty_navigation_links_recursive($block['innerBlocks']);
  $attributes = $block['attrs'];

  /**
   * Deprecated:
   * The rgbTextColor and rgbBackgroundColor attributes
   * have been deprecated in favor of
   * customTextColor and customBackgroundColor ones.
   * Move the values from old attrs to the new ones.
   */
  if (isset($attributes['rgbTextColor']) && empty($attributes['textColor'])) {
    $attributes['customTextColor'] = $attributes['rgbTextColor'];
  }
  if (isset($attributes['rgbBackgroundColor']) && empty($attributes['backgroundColor'])) {
    $attributes['customBackgroundColor'] = $attributes['rgbBackgroundColor'];
  }
  unset($attributes['rgbTextColor'], $attributes['rgbBackgroundColor']);
  if (empty($block['innerBlocks'])) {
    return '';
  }
  $colors = gutenberg_block_core_navigation_build_css_colors($attributes);
  $font_sizes = gutenberg_block_core_navigation_build_css_font_sizes($attributes);
  $classes = array_merge($colors['css_classes'], $font_sizes['css_classes'], array(
    'wp-block-navigation',
  ), isset($attributes['className']) ? array(
    $attributes['className'],
  ) : array(), isset($attributes['orientation']) && 'vertical' === $attributes['orientation'] ? array(
    'is-vertical',
  ) : array(), isset($attributes['itemsJustification']) ? array(
    'items-justified-' . $attributes['itemsJustification'],
  ) : array(), isset($attributes['align']) ? array(
    'align' . $attributes['align'],
  ) : array());
  $class_attribute = sprintf(' class="%s"', esc_attr(implode(' ', $classes)));
  $style_attribute = $colors['inline_styles'] || $font_sizes['inline_styles'] ? sprintf(' style="%s"', esc_attr($colors['inline_styles']) . esc_attr($font_sizes['inline_styles'])) : '';
  return sprintf('<nav %1$s %2$s>%3$s</nav>', $class_attribute, $style_attribute, gutenberg_block_core_navigation_build_html($attributes, $block, $colors, $font_sizes, true));
}