Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Matrix Content Table Realignment #543

Open
mericssonww opened this issue Nov 21, 2023 · 0 comments
Open

Matrix Content Table Realignment #543

mericssonww opened this issue Nov 21, 2023 · 0 comments

Comments

@mericssonww
Copy link

mericssonww commented Nov 21, 2023

Describe the bug

We noticed a pretty significant issue with our matrix content table needing realignment while working on multiple different projects with varying versions of Craft 3 and 4 and Super Table.

Say I have a Block Type that includes a Super Table field named 'CTA'. This CTA Super Table field is used in a handful of different Block Types within the same Matrix field. If I decide to remove one of my CTA Super Table fields from a Block Type that was created before any of the others that follow, the other Block Types that have a CTA Super Table field try to take over the namespace that was deleted. The original field then becomes an empty set in the database and any with a number at the tail end (i.e. matrixcontent_cta_1, matrixcontent_cta_2, etc.) attempts to be renamed 'matrixcontent_cta' because that database entry is now empty.

For example, say I have 10 different Block Types in my Matrix field. If I delete the CTA field that has the namespace 'matrixcontent_cta_5', the CTA fields that have the namespaces 'matrixcontent_cta_6', 'matrixcontent_cta_7', 'matrixcontent_cta_8', 'matrixcontent_cta_9', and 'matrixcontent_cta_10' try to take the newly available 'matrixcontent_cta_5' namespace.

When we first ran into this issue, we needed to cross-reference the database tables to make sure that we weren't losing any content. The solution was to manually revert the naming of these matrix content fields to their original contentTable within the superTableBlockTypes config so they match what is in the actual db tables. So in the example above where the 'matrixcontent_cta_5' namespace became available, we would then need to revert those that tried to change to 'matrixcontent_cta_5' to their original namespace leaving 'matrixcontent_cta_5' available in the db.

If we tried to view a page on the site that included any of these renamed 'matrixcontent_cta*' fields, Craft would throw an error. This is also a problem for content authors when trying to access the entry within Craft.

Steps to reproduce

  1. Create a Matrix field called 'Page Sections'
  2. Create a Block Type within 'Page Sections' called 'Accordion'
  3. Within 'Accordion', create a new Super Table field called 'CTA' with fields 'CTA Label' (field type: Plain Text) and 'CTA Url' (field type: Plain Text)
  4. Create a new Block Type called something like 'Card Grid'
  5. Within 'Card Grid', create a new Super Table field called 'CTA' with fields 'CTA Label' (field type: Plain Text) and 'CTA Url' (field type: Plain Text)
  6. Create a new Block Type called something like 'Media Split'
  7. Within 'Media Split', create a new Super Table field called 'CTA' with fields 'CTA Label' (field type: Plain Text) and 'CTA Url' (field type: Plain Text)

If you delete the original Accordion 'CTA' field, you should see matrixcontent config changes to the 'CTA' namespaces.

Craft CMS version

3.9.4

Plugin version

2.7.5.1

Multi-site?

Yes

Additional context

This issue also happened on another site using more recent versions of Craft and Super Table:

Craft CMS version: 4.5.5
Plugin version: 3.0.9
Multi-site: No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant