Rework module to work without a separate computed field

Created on 13 July 2023, over 1 year ago
Updated 14 June 2024, 5 months ago

Problem/Motivation

The current implementation requires a separate computed field with a list of relationships for all blocks.

Proposed resolution

I have implemented more simplified logic that works well without a separate field and works well with reusable blocks too.
Also, it provides support for including fields from the "default_include" list, provided by jsonapi_extras module (jsonapi_defaults submodule).

Remaining tasks

User interface changes

API changes

Data model changes

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @murz
  • @murz opened merge request.
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    Composer require-dev failure
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    Build Successful
  • Status changed to Needs review over 1 year ago
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia

    For my cases it works well, so let's move to "Needs review" to check how it works for others.

  • Issue was unassigned.
  • πŸ‡¦πŸ‡²Armenia murz Yerevan, Armenia
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    Build Successful
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    Build Successful
  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    Will this recursively load info for blocks that have entity reference fields (Media, taxonomy, etc)?

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 7 months ago
    Composer require failure
  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    Here is a quick add on for this patch that does the following:

    1. Checks if $item['layout_builder__layout'] is empty.
    2. If so, load the entity type and its bundles entity view display information.
    3. If the entity view display is layout builder enabled, load the third party settings and get that information.
    4. Populate $item['layout_builder__layout'] with that information and proceed as normal - adding the entity view display entity as a cacheable dependency.

    This was important in getting layout builder information for decoupled sites for nodes that are NOT overridden, or may not be able to be overridden in layout builder. Otherwise, the array is empty - but you DO have layout builder information at the display level. It should pass it.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 7 months ago
    Composer require failure
  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    Attaching a second patch. This one will sort the blocks in their proper order so it is easier to work with on the client side.

      /**
       * Sort blocks within sections by their weights so the order is correct in JSON:API.
       *
       * @param array $section_data
       *   A set of layouts and components within a section.
       *
       * @return array
       *   The sorted components.
       */
      protected function sortSectionComponents(array &$section_data): array {
        foreach ($section_data as &$section_components) {
          usort($section_components['components'], fn($a, $b) => $a['weight'] <=> $b['weight']);
        }
    
        return $section_data;
      }
    
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 7 months ago
    Composer require failure
  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    I noticed that core does not store the order of items correctly, region or weight. This updated patch attempts to set that order while building the response so the frontend does not have to bear that burden.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 7 months ago
    Composer require failure
  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    Updating patch. Reworked some of the logic and addressed issues when viewing entities that are not Layout Builder enabled.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.2.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update 5 months ago
    Composer require failure
  • πŸ‡ΊπŸ‡¦Ukraine quadrexdev Lutsk

    We used the patch from #9 in our project and it worked fine except for supporting the includes tree.

    Our case:

    Node with layout builder, inside layout builder layout added some blocks with paragraphs (just a basic block type with a paragraph field) -> paragraphs were not included even after configuring default includes.

    What helped:

    Adding "include" parameter before

        $this->rootParser->parse($response);
    

    Attaching patch file

  • πŸ‡ΊπŸ‡ΈUnited States kevinquillen

    That could have been overlooked, sure - I don't use Layout Paragraphs or Paragraphs.

Production build 0.71.5 2024