spicywebau / craft-neo

A Matrix-like field type for Craft CMS that uses existing fields
Other
403 stars 63 forks source link

Entry condition applied even for single pages #886

Closed yannkost closed 1 month ago

yannkost commented 1 month ago

Bug Description

When adding an entry condition to a neo block (let's say: only if the author belongs to the Administrator group), this condition is verified, even for a section of type single. The single type does not have an author id, so in the InputAsset.php in the following lines will lead to an error and break the cp edit page.

function($blockType) use ($conditionsService, $owner, $ownerClass) {
                    if (isset($blockType->conditions[$ownerClass])) {
                        $condition = $conditionsService->createCondition($blockType->conditions[$ownerClass]);
                        return $condition->matchElement($owner);
                    }

                    return true;
                }

Neo should check if the section type of the entry is single or not, as you can break the control panel with this condition.

Steps to reproduce

  1. Create a neo field and a neo block with a condition on the entry type (author has to be administrator)
  2. Add the field in the layout of an entrytype of a section of type single
  3. The cp can't show the edit page of the single page anymore, as no author_id is present to check for an administrator group.

Expected behaviour

No response

Neo version

4.1.2

Craft CMS version

4.8.9

What is the affected Neo field's propagation method?

No response

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

This is not a templating issue

ttempleton commented 1 month ago

I'm unable to reproduce an error when viewing a single after adding an entry author condition rule to a Neo block type. The block type with the condition applied just doesn't appear as an option on the single, which - given that singles don't have authors, as you've noted - is the correct behaviour.

I'm guessing I'm missing some other detail or misunderstanding something about how to reproduce the error. If possible, could you please provide a video demonstration of the steps you can take to reliably reproduce the error? If not, then could you please post a stack trace?

yannkost commented 1 month ago

Here is a stacktrack screenshot

image

and here the configuration for the field

image

I didn't really had time to make a video.

ttempleton commented 1 month ago

Thanks for posting those screenshots.

I can reproduce this error when applying an author group condition rule to a (non-Neo) field being used on the single's field layout. So Craft's author group condition rule code will need to be fixed, to account for the possibility that $element doesn't have an author.