Skip to content

Conversation

@giuscris
Copy link
Member

This pull request introduces improvements to the Layout and Section classes within the layout fields system. The main focus is on optimizing how sections are handled, specifically by enabling dynamic sorting and enhancing data interoperability.

Enhancements to section handling and layout construction:

  • The Layout class now lazily initializes its sections property and ensures sections are always sorted by their order value, improving both performance and consistency when accessing sections. [1] [2]
  • The Section class now implements the Arrayable interface and uses the DataArrayable trait, making it easier to convert section data to arrays for serialization or further processing.
  • A new order() method was added to the Section class, which retrieves the section's order for sorting, defaulting to PHP_INT_MAX if not set. This supports the new sorting logic in Layout.

@giuscris giuscris added this to the 2.2.0 milestone Nov 16, 2025
@giuscris giuscris self-assigned this Nov 16, 2025
@giuscris giuscris added the enhancement New feature or request label Nov 16, 2025
@giuscris giuscris requested a review from Copilot November 16, 2025 14:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request enhances the Layout and Section classes to support custom ordering of sections in layout fields.

Key changes:

  • Section class now implements the Arrayable interface for better data serialization
  • Added an order() method to Section class to retrieve section order values
  • Layout class now lazily initializes and automatically sorts sections by their order value

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
formwork/src/Fields/Layout/Section.php Implements Arrayable interface, adds DataArrayable trait, and introduces order() method for section ordering
formwork/src/Fields/Layout/Layout.php Refactors constructor to use promoted properties and implements lazy initialization of sections with automatic sorting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@giuscris giuscris marked this pull request as ready for review November 16, 2025 14:39
@giuscris giuscris merged commit 98fcdcd into 2.x Nov 16, 2025
1 check passed
@giuscris giuscris deleted the feature/layout-section-order branch November 16, 2025 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants