All add-ons currently require PHP 7.4 or greater.

On July 4th 2024 PHP 8.2 will be the new minimum requirement for all add-ons. Expect any add-on released after that date to require 8.2 or greater. Some releases may not immediately take advantage of 8.x specific features in PHP, which means you might, be able to continue using new releases in PHP 7.4, however, if you experience an error the first thing you should do is update to PHP 8.2 then create a support ticket if the error persists.

Publisher does not support the Fluid field type. Please do not contact asking when support will be available.

If you purchased an add-on from expressionengine.com, be sure to visit boldminded.com/claim to add the license to your account here on boldminded.com.

Ticket: Adding any new bloqs to my master template throws an error

Status Resolved
Add-on / Version Bloqs 5.0.11
Severity
EE Version 7.2.11

Jaywing Developers

Sep 17, 2023

Hi,

It’s been some time since we’ve been required to add any new bloqs to our clients website. Recently I’ve noticed that adding any new bloqs seems to throw an error, regardless of the bloq setup within the CMS. We have a current setup where we have a “Master” template that handles all of the bloqs, for example:

{if bloq_a}
// Grab the template for bloq_a
{bloq_a_template}
{/if}

{if bloq_b}
// Grab the template for bloq_b
{bloq_b_template}
{/if}

This does contain many bloqs (around 40 or so) however even if I reduce the total number of bloqs (all the way to just the new one) I still get the error. The specific bit of code that can be removed to prevent the error is the template embed itself, for example:

{if bloq_a}
// Removing the template embed stops the error
{/if}

It appears that adding any new bloq triggers a simple conditionals bit of code within EE’s core LegacyParser.php file (/system/ee/ExpressionEngine/Service/Template/Variables/LegacyParser.php), specifically the following code (Found on line 267):

// simple conditionals
            if (stristr($val, '\|') && substr($val, 0, 6) != 'switch' && substr($val, 0, 11) != 'multi_field') {
                $var_single[$val] = $this->fetch_simple_conditions($val);
            }

Commenting out the above code actually fixes the error although I’m skeptical to call it a fix as it’s modifying the core EE files. Can you possibly think of any reason why this would occur? Please let me know if there’s anything additional I can provide to assist with looking into this - unfortunately I cannot provide any access to development, staging or live environments as this contains confidential client data.

Thanks,

 

#1

Jaywing Developers

I’m yet to thoroughly test but upgrading EE to 7.3.12 appears to fix the issue on the front end, just adding here for clarity.

#2

Jaywing Developers

Hi,

We are now receiving an error after editing any pages that include bloqs, I’ve updated my original screenshot to include the one with the errors - please could this be looked into as soon as possible?

Thanks,

#3

BoldMinded (Brian)

If a conditional in EE’s code is causing unexpected behavior then there isn’t anything I can do to fix that.

A bloqs field won’t render if nothing is in it, same for a bloq, so why have the extra {if} conditional around the template include? Just include the template.

#4

Jaywing Developers

Hi Brian,

the original issue was somewhat resolved as i mentioned in my last comment, however now with the latest version of bloqs and the latest version of ee I get the error in the screenshot I posted in the original ticket. Can you please comment on that issue?

thanks,

#5

BoldMinded (Brian)

What version of PHP are you using? Have you reduced the template down to just the code that causes the error? If so what types of fields in the bloq(s) is it trying to render? The error is b/c it can’t call a method on a field type file.

#6

Jaywing Developers

Hi,

The error occurs when going to edit any entry where Bloqs is present, this isn’t something that’s present on the front end, to be clear this error is from the CMS. It happens on both our development and local environments. Development is running on PHP 7.4.32 and local is running on PHP 8.2.8

Thnks,

#7

Jaywing Developers

Hi Brian

We are still unable to resolve this. I cannot find any reference to the block_display_field() method in our codebase nor can I find any mention of it within our database. This issue occurred following upgrading EE from version 7.2.11 -> 7.3.12 and also updating bloqs from 5.0.7 -> 5.0.11.

We are able to view/edit/save entries that do not contain any Bloqs, please let me know anything I can provide to assist with solving this.

Thanks,

#8

BoldMinded (Brian)

You’ll need to do some debugging for me. Line 294 of the FieldTypeWrapper.php file is calling method_exists on an object, so it thinks whatever $ft is that it has a valid method called block_display_field. var_dump($ft) so we know what field type is trying to call that method.

#9

BoldMinded (Brian)

Sorry line 293.

#10

Jaywing Developers

<pre><code>object(Text_ft)#5330 (16) { [“field_id”]=> int(1) [“field_name”]=> string(8) “col_id_1” [“row”]=> NULL [“var_id”]=> NULL [“EE”:protected]=> NULL [“settings”]=> array(17) { [“field_maxl”]=> string(3) “256” [“col_required”]=> string(1) “n” [“field_text_direction”]=> string(3) “ltr” [“field_fmt”]=> string(4) “none” [“field_content_type”]=> string(3) “all” [“col_search”]=> string(1) “n” [“field_label”]=> string(16) “Custom CSS Class” [“field_required”]=> string(1) “n” [“col_id”]=> int(1) [“col_name”]=> string(16) “custom_css_class” [“entry_id”]=> int(395) [“grid_field_id”]=> int(7) [“grid_row_id”]=> int(82107) [“grid_row_name”]=> NULL [“blocks_atom_id”]=> int(7) [“blocks_block_id”]=> int(82107) [“blocks_block_name”]=> NULL } [“field_fmt”]=> NULL [“id”:protected]=> int(1) [“name”:protected]=> string(8) “col_id_1” [“content_id”:protected]=> int(395) [“content_type”:protected]=> string(4) “grid” [“info”]=> array(2) { [“name”]=> string(10) “Text Input” [“version”]=> string(5) “1.0.0” } [“field_content_types”]=> NULL [“has_array_data”]=> bool(false) [“defaultEvaluationRule”]=> string(10) “isNotEmpty” [“default_field_content_type”:protected]=> string(3) “all” }<pre><code>

#11

Jaywing Developers

Hi Brian,

I also just noticed when checking the bloq that field above belonged too I can’t view/edit the it in the CMS along with all the other bloqs, stack trace below for the error:

Call to undefined method grid_display_settings()
ee/ExpressionEngine/Service/Template/Variables/ModifiableTrait.php:37

Stack Trace: Please include when reporting this error
#0 [internal function]: EE_Fieldtype->__call('grid_display_se...', Array)
#1 user/addons/bloqs/Controller/FieldTypeWrapper.php(324): call_user_func_array(Array, Array)
#2 user/addons/bloqs/Controller/FieldTypeWrapper.php(407): BoldMinded\Bloqs\Controller\FieldTypeWrapper->callGridOnly('grid_display_se...', Array)
#3 user/addons/bloqs/mcp.bloqs.php(1033): BoldMinded\Bloqs\Controller\FieldTypeWrapper->displaySettings(Array)
#4 user/addons/bloqs/mcp.bloqs.php(957): Bloqs_mcp->getAtomDefinitionSettingsForm(Object(BoldMinded\Bloqs\Model\AtomDefinition), 'text')
#5 user/addons/bloqs/mcp.bloqs.php(906): Bloqs_mcp->getAtomDefinitionView(Object(BoldMinded\Bloqs\Model\AtomDefinition), NULL, Array)
#6 user/addons/bloqs/mcp.bloqs.php(541): Bloqs_mcp->getAtomDefinitionsView(Object(BoldMinded\Bloqs\Model\BlockDefinition), Array)
#7 [internal function]: Bloqs_mcp->blockDefinition()
#8 ee/ExpressionEngine/Controller/Addons/Addons.php(1590): call_user_func_array(Array, Array)
#9 ee/ExpressionEngine/Controller/Addons/Addons.php(866): ExpressionEngine\Controller\Addons\Addons->getModuleSettings('bloqs', 'blockDefinition', Array)
#10 [internal function]: ExpressionEngine\Controller\Addons\Addons->settings('bloqs', 'block-definitio...')
#11 ee/ExpressionEngine/Core/Core.php(268): call_user_func_array(Array, Array)
#12 ee/ExpressionEngine/Core/Core.php(124): ExpressionEngine\Core\Core->runController(Array)
#13 ee/ExpressionEngine/Boot/boot.php(184): ExpressionEngine\Core\Core->run(Object(ExpressionEngine\Core\Request))
#14 admin.php(139): require_once('...')
#14 admin.php(139): require_once('...')
#12

BoldMinded (Brian)

Based on the generally broad error message, and the fact that I can’t replicate this locally, and no one else is reporting a similar issue, it leads me to believe there is something unique happening in your environment that is out of my purview. Have you tried setting up a clean EE install with only Bloqs installed to replicate the issue? Do you a field that is the same name as a bloq? Or a Grid column the same name as a bloq?

#13

Jaywing Developers

Hi Brian,

I’ve tried a fresh copy of expression engine, bloqs and then copied across all of our remaining addons (Structure, Publisher Lite, Wyvern) along with our project setup and templates and also a backed up version of the database prior to the issue and unfortunately the issue still persists. This is probably about as close as I can get with a fresh install. The problem is that we have a site with over 400 entries and around 50 bloqs, if data migration in expression engine was easy then I’d be happy to go with a fresh install but as you can imagine recreating a site like that manually would take a very long time (time isn’t something we have unfortunately).

It feels like somewhere along the way the database might have become corrupted in some form - if that’s the case could you possibly advise on anything for us to try?

In relation to your final questions, no we don’t have any fields named the same as bloqs and we don’t use any grid columns on the site at all.

Thanks,

#14

Jaywing Developers

Hi Brian,

Is there a paid support option we could pursue for this? If so, is there a more personal means to contact you in order to speed up the process - we’ve almost exhausted things on our end and a site rebuild would be a massive undertaking.

Thanks,

#15

BoldMinded (Brian)

I’m not asking you to create a fresh install of the site and copy over all content and add-ons, that defeats the purpose. A fresh install of just EE and Bloqs with the bare minimum channels, custom fields, and templates necessary to recreate the issue. If the issue can be re-created in that environment, then it is easier to determine what the issue is. If it can’t be replicated in that environment then it may indicate there is a conflict with another add-on, or something was configured differently, or there is some other factor I’m unaware of in your original environment.

No I don’t have paid support plans. I work a full-time job and support the add-ons when I can find the time.

#16

BoldMinded (Brian)

The error is coming from the ModifiableTrait class, which means you likely have a variable modifier in your template. Have you tried stripping down your template to the bare minimum, e.g. removing any modifiers, and then adding them back to determine what part of the template is causing the problem?

#17

Jaywing Developers

Hi Brian,

We reverted back to what’s on our live installation currently to try and work forwards from there which is running EE version 7.2.11 and Bloqs 5.0.7. For reference our master template contains Template partials, not embeds - which I should have mentioned before. When I strip it down to it’s absolute barebones of what’s required, this consists of a “row_block” with a nested test block “bloq_test_new”, in order to replicate how our layout typically operates. Our master template looks like this:

{exp:channel:entries channel="default_layout" {gv_disable} {gv_cache}}

{default_group}
{row_block}
<div class="row">
    {bloqs:children}
    {bloq_test_new_template}
</div>
{/row_block}
{/default_group}

{/exp:channel:entries}

The partial that’s referenced “bloq_test_new_template” looks like this:

{bloq_test_new}
<div data-block-name="bloq_test_new">
    {title}
</div>
{/bloq_test_new}

The output of the page in this situation is:

<div class="row">
    
<!--Attempting to render a block from entry #429, but the template tag pair is missing. Add {bloq_test_new}{/bloq_test_new} to your layouts/_html-wrapper template to correct this error.-->

    test
<div data-block-name="bloq_test_new">
    Testing Title
</div>
{/bloq_test_new}
</div>

Notable takeaways from the above:

  • I’m not sure where the “test” text is coming from.
  • I’m also not sure why the closing bloq tag “{/bloq_test_new}” is returning.
  • Despite it rendering it appears there was an issue as the comment suggests.

Thanks again for your help.

#18

Jaywing Developers

Hi,

Changing the test bloq name to “testing_blocks” and then altering the template layout to the following appears to have resolved the issue:

{exp:channel:entries channel="default_layout" {gv_disable} {gv_cache}}

{default_group}
{row_block}
<div class="row">
    {bloqs:children}
</div>
{/row_block}
{bloq_test_new_template}
{/default_group}

{/exp:channel:entries}
#19

BoldMinded (Brian)

It resolves the issue b/c of what I think is a long standing issue with EE’s template parser. You had a template prefixed with bloq_test_new_, and a bloq also named bloq_test_new, and it gets confused and botches the parsing. I don’t know if there is much I can do about this in Bloqs itself, but this seems to come up once or twice a year, so maybe I’ll have to see if it’s fixable from the Bloqs side of things. I think it stems back to this issue https://github.com/ExpressionEngine/ExpressionEngine/issues/55

#20

Jaywing Developers

Hi Brian,

Apologies for coming back so late in this, the original issue unfortunately was not fixed. I run into issues when attempting to create new blocks in the CMS. The first bit of code when I first raised the issue about commenting out a line in the “LegacyParser.php” file seems to resolve the issue for a while but as mentioned it’s not a great way to proceed with this.

From doing some digging all I can figure out is that the root cause seems to occur with prepending functions with “block_” or “grid_” in the bloqs/controller/FieldTypeWrapper.php file. These occur with the functions “validate_settings” and “display_settings”. Can I ask where are the functions “grid_display_settings”, “block_display_settings”, “grid_validate_settings” and “block_validate_settings” located within Bloqs? I can’t seem to find any reference of these methods unless they are being imported from elsewhere?

Thanks,

#21

Jaywing Developers

Sorry I forgot to add as well, that removing any reference of “block_” and “grid_” from these methods being called in the FieldTypeWrapper.php file fixes my issues in the CMS, this is why I’m asking the above in my last reply.

#22

BoldMinded (Brian)

That’s happening in FieldTypeWrapper.php, line 259 in the call() function.

#23

Jaywing Developers

Hi Brian,

Apologies I think you’ve misunderstood the above. I understand the origins of where they are being called from, my question is where do these methods exist at? Specifically these 4:

“block_display_settings” “block_validate_settings” “grid_display_settings” “grid_validate_settings”

Thanks,

#24

BoldMinded (Brian)

They exist in ft files, either in native ones or 3rd party ones. They’re optional. If a “block_display_settings” method exists it’ll get called, otherwise it’ll call “display_settings”. It gives add-on devs options to change the behavior if their field type is in a block, otherwise it’ll use the default methods.

#25

Jaywing Developers

Hi Brian,

So this appears to be where my issue lies, as creating a new bloq appears to require the use of those 4 methods listed above. This only occurred when I upgraded EE to the latest version from 7.2.11. If I am to modify FieldTypeWrapper.php to remove the prepending of “block_” and “grid_” when these methods are called and we just use the default versions of “display_settings” and “validate_settings” then the error goes away. So for example:

I alter the following lines in FieldTypeWrapper.php at Line 292:

} else if (is_callable(array($ft, 'block_' . $methodName))) {
            $result = call_user_func_array(array($ft, 'block_' . $methodName), $args);
        } else if (is_callable(array($ft, 'grid_' . $methodName))) {
            $result = call_user_func_array(array($ft, 'grid_' . $methodName), $args);

And replace it with:

} else if (is_callable(array($ft, 'block_' . $methodName))) {
            $result = call_user_func_array(array($ft, '' . $methodName), $args);
        } else if (is_callable(array($ft, 'grid_' . $methodName))) {
            $result = call_user_func_array(array($ft, '' . $methodName), $args);

And then also modify FieldTypeWrapper.php line 400 for displaySettings():

public function displaySettings($data)
    {
        $method_to_call = is_callable(array($this->_fieldtype, 'grid_display_settings'))
            ? 'grid_display_settings'
            : 'display_settings';

        return $this->callGridOnly($method_to_call, array($data));
    }

And change this too (removing $method_to_call and hardcoding “validate_settings” instead):

public function displaySettings($data)
    {
        $method_to_call = is_callable(array($this->_fieldtype, 'grid_display_settings'))
            ? 'grid_display_settings'
            : 'display_settings';

        return $this->callGridOnly('display_settings', array($data));
    }

And then finally amending FieldTypeWrapper.php Line 413 for validateSettings():

public function validateSettings($data)
    {
        return $this->callGridOnly('grid_validate_settings', array($data));
    }

And changing this to remove grid_ in the call too:

public function validateSettings($data)
    {
        return $this->callGridOnly('validate_settings', array($data));
    }

All these changes above to this file appear to fix my issue. Would it be possible to get an understanding how these will impact the bloqs addon moving forward and if this helps on your end in debugging this?

Thanks,

#26

BoldMinded (Brian)

Those changes would likely have a huge impact on other customers, so I’m most likely not going to change those on a whim without a full understanding of what the issue is.

The question I have is why this is happening. It sounds like a 3rd party add-on is likely the issue here. In cases like this where a very specific issue is happening for someone that I’m not able to replicate, and no one else is also reporting the same issue, it almost always comes down to something unique in that environment that I’m not privy to. Either an add-on conflict, or something custom they’ve done.

I can’t use “is_callable” - that’s what it used to be actually, but the ModifiableTrait class was changed in EE.

What specific fields (the field types) are in the block you’re trying to add to the page? Have you tried replicating this with just Bloqs and EE with basic text fieldtypes?

#27

BoldMinded (Brian)

Can you share a video or screenshots of your Bloqs field, it’s settings (what fields are in the bloqs etc)

#28

BoldMinded (Brian)

Does the same behavior happen if you don’t prefix the bloq names with “bloq_” or “block_”? What about the snippet names?

#29

Jaywing Developers

Hi Brian,

Apologies I will come back to you on all of the above - I’m just rather busy right now and want to collate everything for you properly so we can work this out, I should be able to fire something back on all your above points in the next few hours.

Thanks,

#30

Jaywing Developers

Comment has been marked private.

#31

BoldMinded (Brian)

You can edit the exp_bloqs_ tables to change the block names directly instead of going through the CP.

#32

Jaywing Developers

Hi Brian,

Thanks for the tip, that’s definitely a better approach than what I was doing. I got to the point where I erased every single Bloq, every bloq field, every channel and every entry in expression engine. This seems to resolve the initial error to add a new bloq however when saving the bloq the grid_validate_settings() method error comes up once again. At this point I’m not overly sure what to debug next to figure out the issue further - is there anything that you would suggest?

My problem is that the site we are working on is vast in content and to create a fresh site would take days if not weeks to fully populate the content again otherwise I’d definitely be starting from a fresh database.

Thanks,

#33

BoldMinded (Brian)

Can you create a video of the entire process and in the video walk me through what you’re doing so I can see step by step exactly what is happening, what your bloq definitions look like etc. Then maybe I can try to re-create it locally.

Earlier you said this:

I’ve tried a fresh copy of expression engine, bloqs and then copied across all of our remaining addons (Structure, Publisher Lite, Wyvern) along with our project setup and templates and also a backed up version of the database prior to the issue and unfortunately the issue still persists. This is probably about as close as I can get with a fresh install.

Have you tried it with just Bloqs? I’m not asking for a site re-build, what I asking for is for you to setup Bloqs, and just the bare minimum bloq definitions and template (if necessary) to re-create the issue. Name the bloqs and atoms the same as your main site. I need to see this error happen when Bloqs is the only add-on present to rule out other add-ons, custom configurations, or possible user error (doesn’t sound likely in this case but this is the process). If it can be re-created with only Bloqs installed then I can isolate my testing as well. If it suddenly starts happening when another add-on is installed… well… then that points this in a different direction.

Login to reply