Problem

The blocks sub-module is not picking up the main _content_format for rendering block content.

Steps to reproduce

Atm the code is hard-code to markup-rendering:

      foreach ($blocks as $block) {
        if ($render = $block->getPlugin()->build()) {
          $customElement = CustomElement::createFromRenderArray($render)
            ->toRenderArray();
          $output[$region][$block->id()] = $this->getrenderer()
            ->renderRoot($customElement);
        }

        if ($cacheableDependency) {
          $cacheableDependency->addCacheableDependency($block->getPlugin());
          $cacheableDependency->addCacheableDependency($block);
        }
      }

Proposed resolution

- read main request and apply desired content-format from there
- make use of \Drupal\custom_elements\CustomElementsBlockRenderHelperTrait::convertBlockRenderArray() in case no main custom element is provided in the render array.
- extend test coverage to ensure both markup and json rendering works

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

fago created an issue. See original summary.

fago’s picture

Status: Active » Needs review

accidentally merged the first PR too early (mixed it up with another issue!). Thus reverted that and opened another MR.

The second MR is now ready.

  • fago committed 6bb2d2a1 on 1.x
    fix: #3561237 Blocks API output does not obey request content format (...
fago’s picture

Status: Needs review » Fixed

Manually tested, has test coverage, all green - merged.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.