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

Can't edit neo conditionals, getting array key 0 error #917

Closed
LinneaHarts opened this issue Jul 30, 2024 · 7 comments
Closed

Can't edit neo conditionals, getting array key 0 error #917

LinneaHarts opened this issue Jul 30, 2024 · 7 comments

Comments

@LinneaHarts
Copy link

LinneaHarts commented Jul 30, 2024

Bug Description

I just upgraded a site to Craft 5, and now conditionals aren't working when I'm editing an entry with a neo field, and also when I try to view the conditional settings for a neo field I get "Undefined array key 0"

Here is the full stack trace.

59 [web.ERROR] [yii\base\ErrorException:2] yii\base\ErrorException: Undefined array key 0 in /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/fields/conditions/FieldConditionRuleTrait.php:154
Stack trace:
#0 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/web/ErrorHandler.php(79): yii\base\ErrorHandler->handleError()
#1 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/fields/conditions/FieldConditionRuleTrait.php(154): craft\web\ErrorHandler->handleError()
#2 /mnt/www/skillsoft.com/imarcdev2/vendor/spicyweb/craft-neo/src/elements/conditions/fields/ParentFieldConditionRuleTrait.php(41): craft\fields\conditions\OptionsFieldConditionRule->field()
#3 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/base/conditions/BaseCondition.php(471): benf\neo\elements\conditions\fields\ParentOptionsFieldConditionRule->getLabel()
#4 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/base/conditions/BaseCondition.php(336): craft\base\conditions\BaseCondition->_ruleTypeMenu()
#5 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/web/View.php(1699): craft\base\conditions\BaseCondition->craft\base\conditions{closure}()
#6 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/base/conditions/BaseCondition.php(306): craft\web\View->namespaceInputs()
#7 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/web/View.php(1699): craft\base\conditions\BaseCondition->craft\base\conditions{closure}()
#8 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/base/conditions/BaseCondition.php(276): craft\web\View->namespaceInputs()
#9 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/base/conditions/BaseCondition.php(261): craft\base\conditions\BaseCondition->getBuilderInnerHtml()
#10 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/base/FieldLayoutComponent.php(286): craft\base\conditions\BaseCondition->getBuilderHtml()
#11 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/controllers/FieldsController.php(437): craft\base\FieldLayoutComponent->getSettingsHtml()
#12 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/web/View.php(1699): craft\controllers\FieldsController->craft\controllers{closure}()
#13 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/controllers/FieldsController.php(437): craft\web\View->namespaceInputs()
#14 [internal function]: craft\controllers\FieldsController->actionRenderLayoutComponentSettings()
#15 /mnt/www/skillsoft.com/imarcdev2/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array()
#16 /mnt/www/skillsoft.com/imarcdev2/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams()
#17 /mnt/www/skillsoft.com/imarcdev2/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction()
#18 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/web/Application.php(349): yii\base\Module->runAction()
#19 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/web/Application.php(650): craft\web\Application->runAction()
#20 /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/web/Application.php(311): craft\web\Application->_processActionRequest()
#21 /mnt/www/skillsoft.com/imarcdev2/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest()
#22 /mnt/www/skillsoft.com/imarcdev2/web/index.php(28): yii\base\Application->run()
#23 {main} {"memory":127264176,"exception":"[object] (yii\base\ErrorException(code: 2): Undefined array key 0 at /mnt/www/skillsoft.com/imarcdev2/vendor/craftcms/cms/src/fields/conditions/FieldConditionRuleTrait.php:154)"}
2024-07-30 12:38:59 [web.INFO] [application] Request context:
$_GET = [
'p' => 'admin/actions/fields/render-layout-component-settings'
'site' => 'default'
'v' => '1722357537505'
]

Steps to reproduce

  1. Go to Settings > Fields and edit an existing neo field
  2. Under the field layout, next to a field with existing conditionals that reference parent blocks, try to edit Settings
  3. The error appears

I think this may be related to the fact that the available parent block conditions are also wrong. The ones I see refer to conditions on the existing block, not the parent block. See screenshot here, the Icon Style is a field on the block, not the parent block.
Screenshot 2024-07-30 at 12 58 11

Expected behaviour

I should be able to edit the conditional settings on child blocks with conditionals that reference parent blocks. The available parent block conditionals should refer to parent block fields.

Neo version

5.1.1

Craft CMS version

5.2.9

What is the affected Neo field's propagation method?

Only save blocks to the site they were created in

Does this issue involve templating, and if so, is eager-loading used?

This is not a templating issue

@ttempleton
Copy link
Contributor

I'm unable to reproduce this. If possible, could you please send your composer.json, composer.lock and database backup to [email protected], along with information about a block type and nested field this is happening with, and we'll have a look.

@ttempleton ttempleton added bug report status: unconfirmed A bug report that has not yet been reproduced by the maintainer(s), and more information is required and removed bug report status: new labels Jul 31, 2024
@LinneaHarts
Copy link
Author

I am unable to share that database with you, but I installed Neo on a Craft 5 version of our company's site, and noticed the same problem with parent conditionals.

With a child block, the only parent conditional options it's giving me are for fields on the child block. I will send this database and info.
Screenshot 2024-07-31 at 09 46 49

Note that "personAvatar" is only on the child block, but it's also the only option for a field on the parent block in the conditional choices. I believe this is similar to or related to the problem causing the error above.

@LinneaHarts
Copy link
Author

@ttempleton Would you like me to try to fully recreate the original bug on the non-client DB I was able to share with you?

Or is this parent conditional problem clear enough on what I did send? As I said, I suspect that they are related, if not the same exact bug, but I can try to recreate it more if you like.

@ttempleton
Copy link
Contributor

Thanks for sending the email @LinneaHarts.

I've been able to reproduce the array key error on a fresh Craft install, initially installed with Craft 4 and then upgraded to Craft 5. I think you're correct that the error and the missing parent field condition rules are two parts of the same bug.

Unfortunately, in trying to get more parent field options to appear, so far I've only managed to (in a fairly hacky way) get options for all fields used on any of the Neo field's block types to appear (including multiple instances of the same field). While this (besides the multiple instances) is how it was on Craft 4, I'd like to get only the fields belonging to valid parent block types to appear, but might not be able to. I'll have a new release out one way or the other on Monday.

@ttempleton ttempleton added bug report status: confirmed A bug report that has been reproduced by the maintainer(s), but has not yet been fixed and removed bug report status: unconfirmed A bug report that has not yet been reproduced by the maintainer(s), and more information is required labels Aug 8, 2024
@LinneaHarts
Copy link
Author

@ttempleton Thank you! Glad to hear it

I understand what you're trying to do, and it makes sense but FWIW the way it was on Craft 4 did also make a certain amount of sense since a child block could be a child of any parent, and especially before saving settings, I wasn't sure if the front end would have access that. Best of luck!

@ttempleton
Copy link
Contributor

I ended up going with all possible fields on any of the Neo field's field layouts that we have a parent block condition rule class for. That should be fixed now in Neo 5.2.0. Please let me know if any issues persist, though.

@ttempleton ttempleton added bug report status: fixed and removed bug report status: confirmed A bug report that has been reproduced by the maintainer(s), but has not yet been fixed labels Aug 12, 2024
@LinneaHarts
Copy link
Author

This resolved the issues. Thank you!

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

No branches or pull requests

2 participants