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

Potential issue with neo blocks within globals #982

Open
ryssbowh opened this issue Jan 16, 2025 · 4 comments
Open

Potential issue with neo blocks within globals #982

ryssbowh opened this issue Jan 16, 2025 · 4 comments
Labels

Comments

@ryssbowh
Copy link

ryssbowh commented Jan 16, 2025

What question would you like to ask?

Hi,

I'm the maintainer of the plugin activity which integrates with Neo to calculate field changes when an element is saved.

I'm chasing a bug where the activity plugin would somehow disrupt Neo blocks saving when the Neo field is inside a global. The activity plugin calculates the field value before a global is saved and after, and calculate changes from that.

The blocks for a field are fetched with $this->field->normalizeValue($this->rawValue)->anyStatus()->all() where $this->rawValue is a Neo block query and $this->field the Neo field.

Say I have a global with a Neo field that has one block, and I remove it.

  • Before saving the global, the call to the normalizeValue above returns 1 (as expected)
  • After saving the block, the call also returns 1

If I do the same on an entry, the call to the normalizeValue above after saving returns 0 (as expected), so this is specific to globals it seems.

And another issue : the blocks aren't saved at all. when the page is reloaded the block I deleted is still there.
If I remove the call to the normalizeValue above, the block is deleted as expected.

This is on Craft 4.13.7 with Neo version 4.2.23.

It may be an issue on my side, but the fact that it works for entries (with the exact same code) makes me think that there may be a different behavior in Neo regarding globals ? maybe someething related to memoized queries ?
Do you see any issues in the way I fetch the blocks in the query above ?

Any other pointers appreciated

Thanks for your time

@ttempleton
Copy link
Contributor

I was able to get the Neo block to delete by changing the line to:

$this->field->normalizeValue(clone $this->rawValue)->anyStatus()->all()

I'm not sure if there would be a better place in your code to do it, so I'm not going to open a pull request to make the above change, but basically the original Neo block query needs to be cloned before using it.

@ryssbowh
Copy link
Author

Ha, cloning the query... why didn't I think about it.

That fixes the issue of blocks not saved properly, thanks !

The query after save still returns 1 in the scenario above though, and only for globals.

@ttempleton
Copy link
Contributor

Just to make sure I'm understanding correctly - after the one block on the global set is deleted, the query above is still returning that block?

@ttempleton ttempleton reopened this Jan 19, 2025
@ryssbowh
Copy link
Author

@ttempleton Yes that's correct

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

No branches or pull requests

2 participants