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

Null Variable Supertable inside Matrix Supertable v2.6.5 #399

Closed
williamhibberd opened this issue Dec 21, 2020 · 12 comments
Closed

Null Variable Supertable inside Matrix Supertable v2.6.5 #399

williamhibberd opened this issue Dec 21, 2020 · 12 comments

Comments

@williamhibberd
Copy link

Description

Everything working fine in 2.6.4 but when I update to 2.6.5 I am getting:
Impossible to access an attribute ("value") on a null variable.
With a supertable inside a matrix field.

Matrix setup:
Screenshot 2020-12-21 at 10 39 11

Matrix block templating

{% set promotion = block.promotion %}
	<div class="{{ promotion ? promotion.promotionPosition : 'grid' }}">
		{% if promotion|length %}
			{% set items = block.recipesTutorialsOrNews.with(['category','entryImage']).limit(2).all() %}
			{% set bgColour = promotion.backgroundColour.value %}
			{% set heading = promotion.promotionHeading %}
			{% set body = promotion.promotionBody %}
			{% set link = promotion.promotionLink %}
			<div class="col-6_sm-12">
				<div class="promotion {{ bgColour ? 'bg-' ~ bgColour }}">
					{% if heading|length %}
						<div class="heading">
							<h3>{{ heading }}</h3>
						</div>
					{% endif %}
					{% if body|length %}
						<div class="richText">{{ body }}</div>
					{% endif %}
					{% if link|length %}
						<div>
							<a class="button button-black" {{ link.linkAttributes }}>{{ link.customText ? link.customText : link.url|trim('https://', 'left')|trim('http://', 'left')|trim('www.', 'left')|trim('/', 'right') }}</a>
						</div>
					{% endif %}
				</div>
			</div>
		{% else %}
			{% set items = block.recipesTutorialsOrNews.with(['category','entryImage']).limit(4).all() %}
		{% endif %}
		{% for item in items %}
			<div class="col-3_sm-6_xs-12">
				{% include '_partials/itemCard' with{
					narrow: 1,
					image: item.entryImage[0],
					title: item.title,
					category: item.category[0]
				} %}
			</div>
		{% endfor %}
	</div>

Additional info

  • Plugin version: 2.6.5
  • Craft version: 3.5.17.1
  • Multi-site: No
@i-just
Copy link
Contributor

i-just commented Jan 21, 2021

I have the exact same problem.

  • Plugin version: 2.6.5
  • Craft version: 3.5.17.1 and 3.5.18
  • Multi-site: Yes and No (some sites are multi site, some are not - all have the same problem)

@martyspain
Copy link

martyspain commented Jan 21, 2021

I'm experiencing the same issue. A SuperTable field inside a Matrix field returns null for image fields inside the SuperTable field. I'm not sure if this affects just image fields or all fields.

I can report that rolling back to 2.6.4 resolves the issue (though there may be side-effects in doing that, since 2.6.5 looks like a bugfix release).

Plugin version: 2.6.5
Craft version: 3.5.18

@martyspain
Copy link

Looks like #395 may be related to this issue as well.

@mateostabio
Copy link

Any fix on this yet? Content in these blocks disappeared after updating everything...

@engram-design
Copy link
Member

engram-design commented Jan 26, 2021

I can't replicate this behaviour. If this seems to be an issue in 2.6.5, it must be something to do with static field.

No one has mentioned if their setups are using a static field - can anyone confirm? In addition @williamhibberd your screenshot of your field setup does cut off some of the more crucial things such as what the inner field types are.

If someone here uses Field Manager, it'd be great to get an export of the field they're using so I can try to replicate on my end.

@i-just
Copy link
Contributor

i-just commented Jan 26, 2021

I use field manager on one of my sites that have this issue.

I have attached export from field manager of 3 different fields that experience this issue:

  • "Banner" and "Tyre overview" fields are just supertable fields (no matrix there); they both have max rows set to 1 (but static lightswitch is not checked)
  • "Featured tyres" is a supertable field with a matrix in it and the supertable field is not static and doesn't have max rows set at all

supertable issue 399.json.zip

In all 3 cases, I can fix this issue by first grabbing one or all supertable blocks, where before the query defaulted to grabbing the first one even if not explicitly specified in the code. For example with the "Banner" field, the error occurs with this code: {% set image = entry.banner.image.one() %} and I can fix it by first grabbing one item from the supertable entry.banner.one().
With "Featured tyres" field, the error occurs with this code: {% for tyre in entry.featuredTyres.featuredTyres.all() %}.

I guess my biggest issue here is that it happened with a patch release.

Hope this helps. Please let me know if you'd like any more info.

@martyspain
Copy link

@engram-design I also use Field Manager. I've attached the export of the field below, although it's a Matrix content builder field and therefore quite large and complex.

content-builder.json.zip

The C04 - Home Section Panel block contains a Super Table field called Background Image which is the one I noticed the issue one. Images render from that field with 2.6.4 but not in 2.6.5. It's not set as static (thought it probably should be, come to think of it!) and there's no min/max rows set.

@williamhibberd
Copy link
Author

Hi @engram-design, please see attached my matrix field export from the issue.
mdlHomepageBuilder.json.zip
If you need anything else, please feel free to ask here or on the Craft Discord.

@engram-design
Copy link
Member

engram-design commented Jan 27, 2021

@i-just Thanks for your field setup, that's very helpful. So for starters, accessing Super Table fields like that:

{% set image = entry.banner.image.one() %}

Should only work if you're dealing with a static Super Table field. You might not believe it, but I didn't even realise your way was possible, as I've never used that syntax, tested for it or documented it. It was never intended to work that way, and in hindsight, providing a shorthand way to access static Super Table blocks is the reason we're in this mess, and it's a hacky solution.

Instead, you should be treating a Super Table field as a collection:

{% for block in entry.banner.all() %}
    {% set image = block.image.one() %}
{% endfor %}

Similarly for your second template code:

{% for tyre in entry.featuredTyres.featuredTyres.all() %}
    {{ tyre.customCopy }}
{% endfor %}

It should be:

{% for block in entry.featuredTyres.all() %}
    {% for innerBlock in block.featuredTyres.all() %}
        {{ innerBlock.customCopy }}
    {% endfor %}
{% endfor %}

Because there's not supposed to be direct access to the first bock when calling entry.featuredTyres - unless it's a static field.

I would say this is the same scenario as @martyspain and @williamhibberd and @mateostabio so clearly people are using that syntax

As for it being in a patch release, it was to address an extremely urgent issue that could crash the entire control panel, due to a change made in Craft 3.5.17+, when dealing with Super Table fields. So while its regrettable this has caused other issues, I stand by it.

For now, I would say everyone can fix this by updating their templates to reflect correct behaviour using either .one() or .all() while I continue to look at ways to get around the changes made in Craft 3.5.17+ to ensure backward-compatibility - if at all possible.

Please chime in if the above doesn't cover your issue.

@engram-design
Copy link
Member

@martyspain A word of warning if you downgrade, you'll likely hit the attached error (or similar) when saving an element that contains a Super Table field. Note you'll need to change some content in your Super Table blocks for a save to be triggered if you're testing yourself.

image

engram-design added a commit that referenced this issue Jan 27, 2021
…field, which would otherwise return null

Please see #399 (comment) in that you shouldn’t be doing this anyway, like `entry.superTableField.myField` is reserved for static fields.
@engram-design
Copy link
Member

For anyone unable to update their template code, I've just fixed this by implementing Craft 3.5.16's functionality in 2.6.6, which should restore the behaviour you're used to and fix this issue.

@i-just
Copy link
Contributor

i-just commented Jan 27, 2021

Thanks @engram-design. I haven't had a look at the documentation in a while, but I think I know how that example code ended up the way it is. Anyway, I do agree that it's not the best bit of code and I will be changing it. Thanks for looking into this!

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

No branches or pull requests

5 participants