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

Specify matrix block type #484

Open
Tam opened this Issue Mar 7, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@Tam
Copy link

Tam commented Mar 7, 2019

Description

We're rebuilding a craft site and need to import matrix blocks from the old site to the new, while maintaining their order. As far as I can see there's no way of specifying the block type to use when importing. Our data is structured like this (via element api):

{
  "data": [
    {
      "layers": [
        {
          "type": "blockType",
          "all": "fields",
          "for": "all",
          "block": "types",
        }
      ]
    }
  ]
}

Each layer item has all the possible fields for each block type. Fields that don't appear on that block type are null.

Steps to reproduce

  1. Create a Craft 2 site that has some matrix block in it.
  2. Re-build the entire site from scratch in Craft 3.
  3. Try to import the matrix blocks, while maintaining their order.
  4. Fail.
  5. Try not to cry.
  6. Cry a lot.

Additional info

  • Plugin version: 3.0.4
  • Craft version: 3.1.16
@engram-design

This comment has been minimized.

Copy link
Member

engram-design commented Mar 8, 2019

Its correct that you can't select the block type when mapping, because the fields change depend on what block type you want - therefore, a potentially different set of mapping. It'd be like trying to set the entry type or section of an entry when trying to import it - Feed Me wouldn't know what to do!

You should be able to import your content in the correct order via:

{
  "entries": [
  {
    "title": "Title 1-1",
    "MatrixField": {
      "MatrixBlock": [
        {
          "HeadingSize": "h1",
          "HeadingText": "This is an H1 tag"
        },
        { 
          "Copy": "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>"
        },
        {
          "HeadingSize": "h2",
          "HeadingText": "This is an H2 tag"
        },
        {
          "Images": [
            "img_fjords.jpg"
          ]
        }
      ]
    }
  }
}

Where the above shows importing an entry, with a Matrix field, with 3 block types, Heading, Image and Copy, and these should import in the order specified, and for the type setup per mapping. Note the nodes names are just for illustrative purposes, but if you're going from C2 > C3, it might be worth keeping them the same as their counterparts.

@Tam

This comment has been minimized.

Copy link
Author

Tam commented Mar 8, 2019

That would work, except two of the blocks we've got share the same fields (same field names) but are displayed differently. I guess the only workaround is to change the name of at least one of the fields.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.