Problem/Motivation

A slots data type error throws a message like this (note the missing component):

[warning] Drupal\Core\Render\Component\Exception\InvalidComponentException: [slots.contacts] Array value found, but an object is required in Drupal\Core\Theme\Component\ComponentValidator->validateDefinition() (line 145 of /var/www/html/web/core/lib/Drupal/Core/Theme/Component/ComponentValidator.php).

Steps to reproduce

Obvious.

Proposed resolution

Add the component id to the error.

In ComponentValidator, find

    $message_parts = [
      ...$message_parts,
      ...$missing_class_errors,
    ];

Replace with:

    $message_parts = [
      sprintf('In component %s:', $definition['id']),
      ...$message_parts,
      ...$missing_class_errors,
    ];

Remaining tasks

- Roll a MR
- Review
- Commit

User interface changes

None.

Introduced terminology

None.

API changes

None.

Data model changes

None.

Release notes snippet

---

Issue fork drupal-3549909

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

geek-merlin created an issue. See original summary.

geek-merlin’s picture

Issue summary: View changes

solimanharkas made their first commit to this issue’s fork.

solimanharkas’s picture

Status: Active » Needs review

I've added the component ID to validation errors.

Before:
[warning] Drupal\Core\Render\Component\Exception\InvalidComponentException: [slots.contacts] Array value found, but an object is required in Drupal\Core\Theme\Component\ComponentValidator->validateDefinition()...

After:
[warning] Drupal\Core\Render\Component\Exception\InvalidComponentException: In component test_component:
[slots.contacts] Array value found, but an object is required...

ankitv18’s picture

Status: Needs review » Reviewed & tested by the community

MR changes looks good, hence moving into RTBC.

  • longwave committed 4b4e574e on 11.3.x
    fix: #3549909 Component slot error does not reveal the offending...

  • longwave committed 6c68fad3 on 11.x
    fix: #3549909 Component slot error does not reveal the offending...
longwave’s picture

Version: 11.x-dev » 11.3.x-dev
Status: Reviewed & tested by the community » Fixed

Committed and pushed 6c68fad3969 to 11.x and 4b4e574e417 to 11.3.x. Thanks!

Decided not to backport in case something like a test is relying on the old format (Canvas has some tests around this for sure) and 11.3.0 is out next month anyway.

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.