Components with no properties break config form

Created on 23 February 2024, 4 months ago
Updated 9 March 2024, 3 months ago

Problem/Motivation

I have a component with only slots:

$schema: https://git.drupalcode.org/project/sdc/-/raw/1.x/src/metadata.schema.json
name: Info Card
slots:
  card_title:
    title: Card title
  card_year:
    title: Card year
  content:
    title: Content

It's throwing this error:

TypeError: Adaptor SchemaForms\Drupal\FormGeneratorDrupal received invalid input data: []. in Shaper\Transformation\TransformationBase->Shaper\Transformation\{closure}() (line 23 of /app/vendor/e0ipso/shaper/src/Transformation/TransformationTransformerTrait.php).

Shaper\Transformation\TransformationBase->transform(NULL, Object) (Line: 66)
Drupal\cl_editorial\Form\ComponentInputToForm->buildForm('custom_theme:card-info', Array, Array, Object) (Line: 196)
Drupal\sdc_display\Form\BaseMappingsSettings->staticMappingsForm(Array, Object, 'custom_theme:card-info', Array) (Line: 74)
Drupal\sdc_display\Form\ViewModeMappingsSettings->alter(Array, Object, 'artwork_info', Array, '1AkLcy') (Line: 250)
sdc_display_form_entity_view_display_edit_form_alter(Array, Object, 'entity_view_display_edit_form') (Line: 545)
Drupal\Core\Extension\ModuleHandler->alter('form', Array, Object, 'entity_view_display_edit_form') (Line: 841)
Drupal\Core\Form\FormBuilder->prepareForm('entity_view_display_edit_form', Array, Object) (Line: 284)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object) (Line: 39)
Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

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

Comments & Activities

  • Issue created by @mortona2k
  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    The error is actually in cl_editorial, ComponentInputToForm::buildForm(), line 62.

    With no props in component.yml, $schema is null on this line. It's fixable by checking if(!empty($schema)), but I'm not sure that's the best way to go.

    With empty props defined in component.yml, the check has to be if(!empty($shema) && !empty($schema->properties)).

  • Status changed to Fixed 4 months ago
  • e0ipso Can Picafort

    Hi again @mortona2k! It seems like yesterday we were chatting in Pittsburgh.

    Component schema is mandatory for integration with SDC Display. The way to declare empty props is not by leaving them out but by actually saying they are empty. Perhaps a schema like this would work:

    $schema: https://git.drupalcode.org/project/sdc/-/raw/1.x/src/metadata.schema.json
    name: Info Card
    props:
      type: object
      properties: {}
    slots:
      card_title:
        title: Card title
      card_year:
        title: Card year
      content:
        title: Content
    

    Thanks to this report, I have created an F.A.Q. entry in our documentation. I hope this fixes your issue. https://www.drupal.org/docs/develop/theming-drupal/using-single-director... β†’

    I think this is an error message we should work on in core, so it doesn't blow up in contrib. Do you know if you had validation turned on in your local environment? If so, did it show any validation error based on the empty props declaration? I think we should have an issue for Drupal core to provide a good error message for this, to avoid tripping more people. Can you create this issue and shoot me the link in Slack?

    Additionally, I think we also need an issue for https://github.com/e0ipso/schema-forms-php to provide a useful error message when validation is turned off for SDC in Drupal. Would you also create that one please? πŸ™Œ

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024