Closed davebeesley closed 5 years ago
Craft 3.2 appeared with some major changes which have introduced some bugs into a few plugins (not just mine!). Just to check, are you on the latest versions of Craft and Dynamic Fields?
Hey Lewis, Thanks for getting back to me so quickly Plugin "version": "3.0.9", Craft "version": "3.2.4.1",
Copied from composer.lock
Just bumping Craft to the latest version
All up to date. Now on 3.2.6
OK, I can see the problem. I'll try and release a fix in the next few hours. Craft 3.2 and subsequent minor releases have been causing a few issues with existing plugins. To quote another dev on Discord, "3.2 was released too early with lots of problems". I'll update this thread shortly.
Awesome thank you. Is this something you pipe through then, and Craft have removed the variable/method that you hook in to? I was really struggling to find any Craft Release Notes. I hate raising issues until I have exhausted all other avenues
Just to check, is [fieldNameRedacted] another field within the same entry? And what type of field is it? An entries field?
Yeah on all counts :)
OK, can you please try this:
{% if element is defined %}
{% if element.[fieldNameRedacted] is defined %}
{% set myLocationsField = element.[fieldNameRedacted].all() %}
{% if myLocationsField | length %}
{% for location in myLocationsField %}
{{ loop.index > 1 ? ',' }} {
"value":"{{ location.id }}",
"label":"{{ location.title }}"
}
{% endfor %}
{% else %}
{ "value":"", "label":"Please add some locations and save entry to continue..." }
{% endif %}
{% endif %}
{% endif %}
No dice. I'm not getting any options displayed, or the fallback message, so I presume either element or element.[field] isn't coming through. There isn't an update to the plugin I need to pull through is there? The repo doesn't seem to have updated and element appears to be null still
Please let me know the result of this.
{% if element is defined %}
{ "value":"", "label":"Element exists" }
{% else %}
{ "value":"", "label":"Element does not exist." }
{% endif %}
Interestingly. Element does exist, but the field definitions on it don't
Now try this:
{% if element is defined and element.featuredLocations is defined %}
{ "value":"", "label":"{{ element.featuredLocations.count() }}" }
{% else %}
{ "value":"", "label":"Nope." }
{% endif %}
Featured Locations as an example
{% if element is defined %}
{% if element.practitionerPracticesAt is defined %}
{% set myLocationsField = element.practitionerPracticesAt.all() %}
{% if myLocationsField | length %}
{% for location in myLocationsField %}
{{ loop.index > 1 ? ',' }} {
"value":"{{ location.id }}",
"label":"{{ location.title }}"
}
{% endfor %}
{% else %}
{ "value":"", "label":"Please add some locations and save entry to continue..." }
{% endif %}
{% else %}
{ "value":"", "label":"Field 'practitionerPracticesAt' is not defined" }
{% endif %}
{% else %}
{ "value":"", "label":"Element is not defined" }
{% endif %}
Sorry, commented at the same time there
{% if element is defined and element.practitionerPracticesAt is defined %}
{ "value":"", "label":"{{ element.practitionerPracticesAt.count() }}" }
{% else %}
{ "value":"", "label":"Nope." }
{% endif %}
Cool, implemented what you have put there (practitionerPracticesAt)
OK, looks like a bug. I was using a dropdown field and it was working, however you were using a checkboxes field and it's not working (now also confirmed here). I'll take a look now...
Cool. Nice one man. Thanks for being so responsive it is appreciated
I've fixed the issue. I'm going to do some further bug testing before I do an official release later today, but in the meantime can you replace /vendor/lewisjenkins/craft-dynamic-fields/src/fields/Checkboxes.php
with this, and try the following once again:
{% if element is defined %}
{% if element.practitionerPracticesAt is defined %}
{% set myLocationsField = element.practitionerPracticesAt.all() %}
{% if myLocationsField | length %}
{% for location in myLocationsField %}
{{ loop.index > 1 ? ',' }} {
"value":"{{ location.id }}",
"label":"{{ location.title }}"
}
{% endfor %}
{% else %}
{ "value":"", "label":"Please add some locations and save entry to continue..." }
{% endif %}
{% else %}
{ "value":"", "label":"Field 'practitionerPracticesAt' is not defined" }
{% endif %}
{% else %}
{ "value":"", "label":"Element is not defined" }
{% endif %}
Legend! Thank you
Cool, thanks for bringing it to my attention. I'll push a proper release later today because this also affects the other fieldtypes. The element
feature is undocumented, but if you use element.owner
rather than element
then you can also access the current entry from within Matrix fields as well.
Cool. I've got quite a big roll out of this fix now, as this field is used quite extensively on this site
I tend to use {% include 'somefile.json' ignore missing %}
for my dynamic field settings because it's so much easier to test and make quick changes to field behaviour.
Good call! I may just do that, then it will also be source controlled across environments (assuming this doesn't get propagated by Crafts yml file)
I'll just add a couple of screenshots to both sanity check what I am doing, and to help anybody who stumbles across this in future
Many thanks. Also, I've just pushed the latest release to the Plugin Store.
I deployed this plugin on a site built on Craft 3.1 and the following twig worked fine
Since upgrading to 3.2 - element appears to be coming through as null or nothing Has element disappeared/been replaced?