confluxgroup / craft-level-entry-types

A Craft CMS 3.x plugin that allows developers to limit the entry types available at each level of a structure section.
Other
5 stars 1 forks source link

Various javascript errors, plugin doesn't seem to work #2

Closed howells closed 4 years ago

howells commented 4 years ago

Describe the bug I've installed the plugin and defined my config file, but there are various Javascript errors that pop up in the console, which means the plugin doesn't seem to work for me.

a) When editing a non-structure section, a javascript error appears that prevents some fields from working, in this case a Neo field:

jquery.js:4055 Uncaught TypeError: Cannot read property 'getElements' of undefined
    at s.constructor.init (EditEntryScreen.js?v=1590440437:23)`

b) Having defined a section courses as follows, I seem to be able to add an overview type as a child... and basically do anything as normal, but with various "A Server Error" warnings (with nothing in the logs):

<?php

return [
    'structures' => [
        // list your structure section handles
        'courses' => [
            // add each level you want to limit
            1 => [
                // add each entry type that's allowed at this level
                'overview',
            ],
            2 => [
                'units',
                'staff',
                'studentWork',
                'careersAlumni',
                'askAStudent',
                'resources',
                'page',
            ],
        ],
    ],
];

c) If I drag entries around on the structure, I get the following console error. This error means I'm unable to drag and drop entries further.

EntryIndexScreen.js?v=1590440445:74 Uncaught TypeError: Cannot read property 'includes' of undefined
    at HTMLTableCellElement.<anonymous> (EntryIndexScreen.js?v=1590440445:74)

Any ideas what's going on would be great, I'd love to be able to use this plugin!

this is using the latest version, and with Craft 3.4.20

dreadfullyposh commented 4 years ago

@howells we will take a look

dreadfullyposh commented 4 years ago

@howells I released v1.0.3 which fixes part A of your issue and prevents the Level Entry Types JS from firing on non-structure entries.

We are still looking into parts B and C, which are very likely related. I haven't been able to replicate them though, even after updating to Craft 3.4.20.

I'm wondering if you could view the source of your structure's index page (/admin/entries/structureHandle) and find the LevelEntryTypesData object and send that over.

It should look something like this:

var LevelEntryTypesData={"map":{"3":{"Nonprotected Structure":[],"Another Nonprotected Type":[]},"1":{"Test Structure":[1],"Type 1":[1,3],"Type 2":[2],"Type 3":[3]},"2":{"Channel":[]}},"limitedLevels":{"3":[],"1":[1,2,3]}};

That will hopefully give me a better idea of what's going on with your configuration.

Thanks,

Jeremy

howells commented 4 years ago

Hi thanks for looking into this. Since my issue, I changed the various child page names, and so updated the config file:

<?php

return [
    'structures' => [
        // list your structure section handles
        'courses' => [
            // add each level you want to limit
            1 => [
                // add each entry type that's allowed at this level
                'course',
            ],
            2 => [
                'coursePage',
            ],
        ],
    ],
];

However, when I view source to find var LevelEntryTypesData, the old ones are there:

var LevelEntryTypesData={"map":{"22":{"Call to Actions":[]},"3":{"Course":[1],"Course Page":[2]},"4":{"Pages":[]},"6":{"Profiles":[]},"10":{"Resources":[]},"21":{"Stories":[]},"1":{"Homepage":[]},"2":{"Course Index":[]},"5":{"People Index":[]},"7":{"Events":[]},"8":{"Event Index":[]},"9":{"Virtual Tour Index":[]},"11":{"Resource Index":[]},"12":{"Prospectus":[]},"13":{"Open Days":[]},"14":{"Contact":[]},"15":{"Posts Index":[]},"16":{"Posts":[]},"17":{"Apply":[]},"18":{"Student Work Index":[]},"19":{"Projects":[]},"20":{"Social Media Posts":[]}},"limitedLevels":{"22":[],"3":[1,2],"4":[],"6":[],"10":[],"21":[]}};

I tried emptying all caches, but they're still there.

dreadfullyposh commented 4 years ago

@howells One more update. I was eventually able to replicate the error you were seeing on the entry index pages and fix it. (back story: I wrongly assumed that the structure ID Craft uses was the same as the section ID... wrong!)

You'll see that fixed when you update to 1.0.4.

Let me know how that works for you!