Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] BlockRenderer does not render nested blocks in order of position #1955

Closed
mikerockett opened this issue Nov 27, 2022 · 1 comment
Closed

Comments

@mikerockett
Copy link
Contributor

mikerockett commented Nov 27, 2022

Description

When fetching root blocks, the default behaviour is to order by position. However, the same cannot be said for nested blocks, as the query simply fetches by parent_id without any ordering.

Steps to reproduce

  1. Create a block that uses a block editor that references any block type.
  2. Add an instance of that block to a module, such as a page.
  3. Create a template for both blocks, and use renderChildren(name) in the root block template.
  4. Add some child blocks and re-order them. The order will not be as intended.

Expected result

Nested blocks at all levels should rendered be in the order defined.

Actual result

Nested blocks are ordered as per the database’s default ordering.

Steps to correct

In BlockRenderer, exchange the $childBlocks assignment in getNestedBlocksForBlock to:

$childBlocks = A17Block::whereParentId($block->id)->orderBy(
    config('twill.blocks_table', 'twill_blocks') . '.position',
    'asc'
)->get();

(May I open a PR against 3.x?)

Versions

Twill version: 3.0.0-beta2
Laravel version: 9.x
PHP version: 8.1
Database engine: Postgres 14

@mikerockett
Copy link
Contributor Author

Have gone ahead and opened a PR targetting 3.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants