mmikkel / reasons-craft3 Goto Github PK
View Code? Open in Web Editor NEWAdd conditionals to your field layouts
License: MIT License
Add conditionals to your field layouts
License: MIT License
Experiencing something similar when trying to add Reasons to an existing site. Package installs correctly, but then all pages display the error (presumably due to config rebuild as project-config/rebuild
also throws same error):
error: SQLSTATE[42703]: Undefined column: 7 ERROR: column reasons.fieldlayoutid does not exist
LINE 3: ...fieldlayouts" "fieldlayouts" ON fieldlayouts.id = reasons.fi...
^
HINT: Perhaps you meant to reference the column "reasons.fieldLayoutId".
The SQL being executed was: SELECT "reasons"."uid", "reasons"."conditionals", "fieldlayouts"."uid" AS "fieldLayoutUid"
FROM "reasons" "reasons"
INNER JOIN "fieldlayouts" "fieldlayouts" ON fieldlayouts.id = reasons.fieldLayoutId
Can send through a DB dump and the config/project
directory if needed
Craft: Pro 3.5.14
Reasons: 2.2.2
DB Engine: PostgreSQL 12.1
Originally posted by @slavanossar in #9 (comment)
Hi,
We have a craft cms site, with nearly 300 sections, each section has only one entry type with 5 or 6 conditional fields. We see a huge delay when switching over control panel menu pages. This occurs on all menus even when switching between settings, utilities etc,
Our initial findings are showing there are a lot of duplicate queries initiated by reasons plugin is the cause for this delay.
For example, when we load the utilities page, after disabling the plugin only 60 odd queries were running, After enabling we see nearly 12000 queries were running. See attached,
Could we load the queries only on the pages needed?
System info:
PHP version 7.4.24
OS version Linux 5.4.0-91-generic
Database driver & version MySQL 5.7.35
Image driver & version GD 7.4.24
Craft edition & version Craft Pro 3.7.28
Yii version 2.0.44
Twig version v2.14.10
Guzzle version 7.4.1
Reason plugin version - 2.2.5
At least it looks that way. Updated and now Reasons is failing, although I can't see any obvious errors appearing, the fields with conditional rules applied just don't appear.
The latest release of Craft includes many accessibility improvements which could be related.
I've tried tracking this down a little in the code but have been unable to work out just where the issue starts here.
Under certain conditions the $conditionals
JSON passed to the saveFieldLayoutConditionals()
method in the ReasonsService doesn't contain valid JSON and the whole thing falls apart leaving the dashboard inaccessible etc. It's like the closing brackets of the array of conditionals are missing when I dump out the failing code.
My field layout is as follows.
competitionType - radio button field with 3 values - roundRobin, elimination, winnerStaysOn
blindDrawForEachRound - lightswitch field
blindDrawRounds - matrix
roundRobinRounds - number field
If a user selects competitionType:elimination then the blindDrawForEachRound should be visible, if they turn that on, the blindDrawRounds should be visible.
If a user selects competitionType:roundRobin the roundRobinRounds should be visible.
The issue appears to present if I set up the second conditional on the competitionType toggle field. Somehow the JSON doesn't get wrapped up properly and I've struggled (although I've not looked at it in-depth) to easily find where that's hapening.
Let me know if you want a DB/project config or anything.
Cheers
Thanks for your work! I was missing so much this plugins for v3!!
Congrats!!!
Hey,
Awesome work on Reasons for Craft 3!
I was wondering if you'd be able to support Neo Matrix field designer? I see the action in Neo's fld is fields/save-field
, but you don't seem to be doing anything with this yet here:
There's obviously more that would need to be done in order to support Neo but I would really appreciate it if you would consider adding support for Neo Matrix's fld
Not working in Safari 15, shows everything and has no effect. Works perfectly in Chrome and Firefox.
System:
Safari 15.0
Craft Pro 3.7.16
Reasons 2.2.5
Developer console reports:
ReferenceError: Can't find variable: BroadcastChannel
init โ DraftEditor.js:118
constructor โ garnish.js:764
(anonym funksjon) โ garnish.js:40
(anonym funksjon) โ garnish.js:40
Hi Mats,
Thanks so much for porting this. I've found a couple of issues locally which I was going to PR but I'm not 100% sure if my "fix" has side-effects I've not gone over.
If you run ./craft project-config/sync --force
in terminal the plugin throws an error about getBodyParam()
not existing which is true, the console version of the Craft app Request class doesn't have this method.
I "fixed" this by simply wrapping the call to it which is within the EVENT_AFTER_SAVE_FIELD_LAYOUT
handler, in a check:
if (!Craft::$app->getRequest()->getIsConsoleRequest())
{
// getBodyParam doesn't exist in console commands such as ./craft project-config/sync -- force
$conditionals = Craft::$app->getRequest()->getBodyParam('_reasons', null);
}
which meant the rest of the code ran through with it a null value (so it just returns) but obviously that means the thing that should be happening isn't happening so not sure if that's an issue, hence no PR for this. I think it's OK because you're attempting to handle save field events from the dashboard in here but I don't know if syncing project config with the force flag will mean the reasons stuff gets lost?
I'll open a different issue for the other thing I've found.
Cheers.
I've just updated from Craft 3 to Craft 4. I was previously using the Reasons plugin for CP but also front-end purpose. On front-end, I was printing field layouts and show/hide the fields based on the same Reasons conditions found in the CP.
Unfortunately, this plugin has been stopped for Craft 4 in profit of the native conditional fields. However, I don't find out the equivalent of what I could achieve using Reasons.
This is what I was doing in Craft 3 + Reasons:
{% set conditionals = [] %}
% for key, value in craft.app.getPlugins().getPlugin('reasons').reasons.getData().conditionals %}
{%
if 'section' in key
and (key | split(':') | last) | number_format == craft.app.sections.getSectionByHandle('companies').id ?? -1
%}
{% set conditionals = value %}
{% endif %}
{% endfor %}
{% set rules = [] %}
{% set syncedFields = [] %}
{% set syncedHandles = [] %}
{% set hiddenFields = [] %}
{% for id, condition in conditionals %}
{% set syncedFields = syncedFields | merge([condition.0.0.0.fieldId ?? null]) | filter | unique %}
{% set handle = craft.app.fields.getFieldById(condition.0.0.0.fieldId ?? null).handle ?? null %}
{% set syncedHandles = syncedHandles | merge(["{handle}: '{value}'" | t({
handle: handle,
value: company[handle].value ?? company[handle] ?? null
})]) | filter | unique %}
{% set hiddenFields = hiddenFields | merge([id ?? null]) | filter %}
{% set condition = {
sync: condition.0.0.0.fieldId ?? null,
field: id ?? null,
rule: '{compare} {value}' | t({
compare: condition.0.0.0.compare,
value: condition.0.0.0.value
})
} %}
{% endfor %}
In my case, the intended context here is quite simple: it's checking a Lightswitch field from another field. If the main field is switched on, subfields will be shown.
What would be the equivalent in Craft 4?
Updated to Latest Craft CMS version 3.7.46 from 3.7.45.2 and it's broken the reasons plugin functionality. I can't see any obvious errors appearing, the fields with conditional rules are applied but they just don't appear in the entries.
I've got an entry type with a lightbox to toggle between to fields - a Matrix field and a Super Table field. The toggle applies to the entire field and works perfectly in the normal "Add new entry" from the "All Entries" dashboard view.
What doesn't work is the toggle when you opt to add a new entry from the "Select an Entry" entry field. Please see diagram below for explanation
I've spent a while trying to debug why a deployment has been failing. My site uses project-config.
Craft: 3.5.11.1
Reasons: 2.2.1
DB Engine: MySQL
Steps to reproduce:
The final part of craft setup is applying the project config, but this fails with the SQL error below. Removing the reasons_conditionals
folder from config/project allows the installation to complete successfully.
Comparing the databases, the value for fieldLayoutId
(0) that's being inserted here relates to a different/incompatible field layout on this installation. My guess is that fieldLayoutId shouldn't be in the table at all, and the UUID used instead? There's apparently no fieldLayoutId in the yaml.
Aside from this, I can't get Reasons to work on this version of Craft even when it is configured correctly!
Applying changes from your project config files ... error: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`craft3`.`craft_reasons`, CONSTRAINT `craft_reasons_fieldLayoutId_fk` FOREIGN KEY (`fieldLayoutId`) REFERENCES `craft_fieldlayouts` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) The SQL being executed was: INSERT INTO `craft_reasons` (`fieldLayoutId`, `conditionals`, `uid`, `dateCreated`, `dateUpdated`) VALUES (0, '{\"2e8dd7f7-f84f-4c0a-b3b8-8ac1bce79d9d\":[[{\"field\":\"e99e7f78-3ce1-4e44-b165-a8edbc360aca\",\"compare\":\"==\",\"value\":\"true\"}]],\"9fcbd106-b808-47ec-942b-668235124254\":[[{\"field\":\"e99e7f78-3ce1-4e44-b165-a8edbc360aca\",\"compare\":\"==\",\"value\":\"true\"}]],\"6d8fcd42-634a-4dac-b682-ede47aba83f0\":[[{\"field\":\"e99e7f78-3ce1-4e44-b165-a8edbc360aca\",\"compare\":\"==\",\"value\":\"true\"}]],\"c01c6210-ed29-4fe6-a390-87eef631095c\":[[{\"field\":\"e99e7f78-3ce1-4e44-b165-a8edbc360aca\",\"compare\":\"==\",\"value\":\"true\"}]],\"19ced37f-881d-491f-898b-91ca9de7057e\":[[{\"field\":\"e99e7f78-3ce1-4e44-b165-a8edbc360aca\",\"compare\":\"==\",\"value\":\"true\"}]],\"063f327a-3e45-4cdf-b47c-43359485a7bc\":[[{\"field\":\"e99e7f78-3ce1-4e44-b165-a8edbc360aca\",\"compare\":\"==\",\"value\":\"true\"}]]}', '2ca19fa0-117f-41d6-81f2-3f2fb1e1c6dd', '2020-09-21 21:25:33', '2020-09-21 21:25:33')
Hi!
Could it be that the plugin doesn't work with Craft version 3.7.16? The plugin used to work but since version 3.7.16 no options appear when editing fields for sections and the conditions are also gone.
Thanks,
Dirk
It's great that this plugin's features can be accessed directly from the field settings cog, but it's only available if the field is being used natively. It does not work when inside NEO.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.