We use Contentblocks for layout on our sites. We have blocks for different uses, including one that brings dynamic content based on a dynamic URL.
To do this, we list the resources with this block using the cbHasField function intercepted on the OnDocFormSave event.
This works well when the field is integrated into a layout element. However, as soon as it is nested within another element, it does not work. For example, we have an accordion-type element (field) in a 2/3 - 1/3 Bootstrap block, and it no longer works. Has anyone found a solution for a recursive call to cbHasField? Thank you in advance for your help.
ContentBlocks saves the structured data for a resource in the database column properties under different keys (content, linear, fieldcounts, _isContentBlocks).
The snippet “cbHasField” then looks at the fieldcounts array to check if a certain field exists.
It looks like the code also counts the fields in nested layouts to create the fieldcounts array. Not sure why the function doesn’t work in your case.
As the same event is also used by ContentBlocks (to set the properties column), make sure that your plugin runs after the ContentBlocks plugin.
If the snippet “cbHasField” doesn’t work for your use case, try using the structured data from the content key (in the namespace contentblocks of the properties column) directly, to extract the desired information.
It could also be advantageous to use the event ContentBlocks_RenderContent (instead of OnDocFormSave) to run your custom code, as you get direct access to the ContentBlocks content (parameter cbContent).