Incorrect schema for table component

Created on 15 January 2024, 10 months ago
Updated 1 February 2024, 10 months ago

Problem/Motivation

Rendering a basic table with the properties defined, fail with an InvalidComponentException:

Drupal\sdc\Exception\InvalidComponentException: [header] Array value found, but a string or an object is required/n[footer] NULL value found, but a string or an object is required. This may be because the property is empty instead of having data present. If possible fix the source data, use the |default() twig filter, or update the schema to allow multiple types. in Drupal\sdc\Component\ComponentValidator->validateProps() (line 201 of core/modules/sdc/src/Component/ComponentValidator.php).

Steps to reproduce

Add a simple table render-array to a page controller:


namespace Drupal\example\Controller;

use \Drupal\Core\Controller\ControllerBase;

/**
 * An example controller.
 */
class ExampleController extends ControllerBase {

  /**
   * Returns a renderable array for a test page.
   *
   * return []
   */
  public function content() {
    $rows = [
      ['1', '1'],
      ['2', '2'],
    ];

    $build['table'] = [
      '#type' => 'table',
      '#caption' => $this->t('PoC'),
      '#header' => [
        'Col 1',
        'Col 2',
      ],
      '#rows' => $rows,
      '#empty' => 'No rows found.',
    ];

    return $build;
  }

}

Proposed resolution

I don't know SDC, but changing the header `type: string` to `type: array` and removing the `footer:` "property" from `table.component.yml` let us render the table without issues.

(Could also add `#footer = [];` to the render-array but that do not align with the properties in https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21... )

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

6.0

Component

Code

Created by

πŸ‡³πŸ‡΄Norway jfauske

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

Comments & Activities

Production build 0.71.5 2024