Overview

I created a yml config that requires content_attributes from twig. I added it as part of my component.yml. As I understand that any properties will be shown in the UI so how do I hide this?

Here is the an example config I use:

$schema: https://git.drupalcode.org/project/drupal/-/raw/10.1.x/core/modules/sdc/src/metadata.schema.json
name: Card Icon
status: stable
props:
  type: object
  properties:
    content_attributes:
      type: string
      title: 'Content attributes'
      description: 'Same as attributes, except applied to the main content tag that appears in the template.'
    title:
      type: string
      title: 'Title'
      description: 'Main title'
    body:
      type: string
      title: 'Body'
      description: 'Main content text'
    more_content:
      type: string
      title: More content
      description: 'Additional content'
  required:
    - content_attributes

Proposed resolution

I would like to be able to hide some settings in the UI.

User interface changes

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

nx2611 created an issue. See original summary.

lauriii’s picture

nx2611’s picture

Issue summary: View changes
wim leers’s picture

Component: Config management » Component sources
Category: Feature request » Support request
Status: Active » Fixed

The type is wrong:

 content_attributes:
      type: string
      title: 'Content attributes'
      description: 'Same as attributes, except applied to the main content tag that appears in the template.'

should be

 content_attributes:
      type: Drupal\Core\Template\Attribute
      title: 'Content attributes'
      description: 'Same as attributes, except applied to the main content tag that appears in the template.'

If you do that, it'll be ignored automatically :) 👍

Interested in knowing why/how? → See this bit in \Drupal\experience_builder\PropShape\PropShape::getComponentPropsForMetadata():

      // TRICKY: `attributes` is a special case — it is kind of a reserved
      // prop.
      // @see \Drupal\sdc\Twig\TwigExtension::mergeAdditionalRenderContext()
      // @see https://www.drupal.org/project/drupal/issues/3352063#comment-15277820
      if ($prop_name === 'attributes') {
        assert($prop_schema['type'][0] === Attribute::class);
        continue;
      }
wim leers’s picture

Assigned: Unassigned » wim leers
Category: Support request » Feature request
Status: Fixed » Needs review

Ah, lol, I misread my own code 🙈

      if ($prop_name === 'attributes') {

→ what I wrote is not true. It should just check the type?

wim leers’s picture

Title: How to pass content_attributes to SDC without it being shown in the XB UI » Ignore all `type: Drupal\Core\Template\Attribute`s, not only the one named "attributes"
Assigned: wim leers » Unassigned
Priority: Normal » Minor
Issue tags: +Needs upstream bugfix

MR with test coverage up. 👍

But … does this even work? Doesn't \Drupal\Core\Template\ComponentsTwigExtension::mergeAdditionalRenderContext() only support a single attributes prop? 😅

So that's definitely an upstream bug in SDC.

penyaskito’s picture

Assigned: Unassigned » wim leers
Status: Needs review » Needs work
Issue tags: -Needs upstream bugfix

Assigning for the feedback you asked and removing tag. Not saying that you are the one who should fix the tests 😁

wim leers’s picture

Assigned: wim leers » penyaskito

🏓

wim leers’s picture

Category: Feature request » Task
Priority: Minor » Major
Issue tags: +beta blocker, +Contributed project blocker

Per #3513406-8: ValueError: "Drupal\Core\Template\Attribute" is not a valid backing value for enum, this affects the quite popular https://www.drupal.org/project/radix theme significantly.

Basically this just needs to be generalized:
\Drupal\experience_builder\ComponentMetadataRequirementsChecker::check()

    foreach ($metadata->schema['properties'] as $prop_name => $prop) {
      if ($prop_name === 'attributes') {
        continue;
      }

… which is the direction @penyaskito's in-progress MR already is taking 👍 Let's revive & land it!

wim leers credited kiwad.

wim leers’s picture

Marked #3513406 as a duplicate per #3513406-13: ValueError: "Drupal\Core\Template\Attribute" is not a valid backing value for enum. Crediting the contributors there that helped get clarity there, which allowed marking it as a duplicate 😊

penyaskito’s picture

Mentioned today, while we are here let's ensure we have a plan (fix here or follow-up) for Attributes prop marked as required works, even if that doesn't make any sense.

penyaskito’s picture

Version: 0.x-dev » 1.x-dev
penyaskito’s picture

Assigned: penyaskito » wim leers
Status: Needs work » Needs review
wim leers’s picture

Mentioned today, while we are here let's ensure we have a plan (fix here or follow-up) for Attributes prop marked as required works, even if that doesn't make any sense.

👆 This is not yet addressed, but the MR is ready, so tagging Needs followup.

Also linking the core issues that @penyaskito found in his research at https://git.drupalcode.org/project/experience_builder/-/merge_requests/1...

wim leers’s picture

Assigned: wim leers » penyaskito
Status: Needs review » Needs work

LGTM — only needs addressing of @larowlan's edge case, and just have 2 minor questions.

penyaskito’s picture

Assigned: penyaskito » wim leers
Status: Needs work » Needs review
Issue tags: -Needs followup
wim leers’s picture

Assigned: wim leers » Unassigned
Status: Needs review » Reviewed & tested by the community
Related issues: +#3537610: Handle required `type: Drupal\Core\Template\Attribute`s props in SDCs

Thanks!

  • wim leers committed 67a54b6f on 1.x
    Issue #3493068 by penyaskito, wim leers, nx2611, nevergone, kiwad,...
wim leers’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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