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

Fix incompatibility with Field Manager #462

Closed
engram-design opened this issue Jun 5, 2021 · 3 comments
Closed

Fix incompatibility with Field Manager #462

engram-design opened this issue Jun 5, 2021 · 3 comments

Comments

@engram-design
Copy link
Contributor

engram-design commented Jun 5, 2021

Refer to issue verbb/field-manager#78

I believe this is because Neo assumes the field layout for a block type will come from POST params (using assembleLayoutFromPost)

craft-neo/src/Field.php

Lines 603 to 608 in 2af37c2

// Set each block type's field layout based on the data from Craft 3.5's field layout designer
foreach ($this->getBlockTypes() as $blockType) {
$fieldLayout = $fieldsService->assembleLayoutFromPost("types.{$class}.blockTypes.{$blockType->id}");
$fieldLayout->type = $class;
$blockType->setFieldLayout($fieldLayout);
}

However, in Field Manager, when we clone a field, we take the block types from the origin field, and create new block types based on those, for the new field. As such, the field is all prepped and ready to go, however this code overrides our prepped block types. Because assembleLayoutFromPost in this case will equate to null, it resets the field layout.

What I might propose is a check if the field layout is already set for the block type?

// Set each block type's field layout based on the data from Craft 3.5's field layout designer
foreach ($this->getBlockTypes() as $blockType) {
    // Check if the block type already has a field layout set - no need to set it again
    if (!$blockType->fieldLayout) {
        $fieldLayout = $fieldsService->assembleLayoutFromPost("types.{$class}.blockTypes.{$blockType->id}");
        $fieldLayout->type = $class;
        $blockType->setFieldLayout($fieldLayout);
    }
}

Notably, this wasn't an issue on previous versions - I can't tell you what version exactly, but I was on 2.8.14 before updating to the latest (2.9.11) and this was working

@ttempleton
Copy link
Contributor

Yep, your proposed fix looks great. Would you like to open a pull request, or are you happy for us to make that change?

@engram-design
Copy link
Contributor Author

Happy to do a PR - #464

@ttempleton
Copy link
Contributor

Thanks again -- just released Neo 2.9.12 with that fix.

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

No branches or pull requests

2 participants