silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
720 stars 820 forks source link

Uncaught Error: cannot call methods on accordion prior to initialization; attempted to call method 'option' #11214

Closed isaacdarcilla closed 1 month ago

isaacdarcilla commented 2 months ago

Module version(s) affected

5.2.2

Description

The following error appears in the developer console in my browser after publishing changes in the CMS admin:

Uncaught Error: cannot call methods on accordion prior to initialization; attempted to call method 'option'

With the JS for silverstripe/admin rebuilt in dev mode, the error points to LeftAndMain.EditForm.js:417 as the source of the error.

Error occurs after publishing changes in CMS admin.

How to reproduce

    public function updateCMSFields(FieldList $fields): void
    {
        $fields->removeByName(['Metadata', 'MetaTitleTemplateID']);

        $scaffoldFields = array_keys(
            array_merge(
                self::config()->get('db'),
                self::config()->get('has_one')
            )
        );

        $fields->removeByName($scaffoldFields);

        if (!$fields->fieldByName('Root.Main.SEOFields_Container')) {
           $fields->addFieldToTab(
                'Root.Main',
                ToggleCompositeField::create(
                    'SEOFields_Container',
                    'Search Engine Optimization',
                    [
                        TabSet::create('SEOTabs', [
                            Tab::create('General', 'General')->setTitle('General'),
                            Tab::create('FacebookFields', 'Facebook Fields')->setTitle('Facebook'),
                            Tab::create('TwitterFields', 'Twitter Fields')->setTitle('Twitter'),
                            Tab::create('SitemapFields', 'Sitemap')->setTitle('Sitemap'),
                            Tab::create('AdvancedFields', 'Advance')->setTitle('Advance'),
                        ])->addExtraClass('seo-tabs-padded')
                    ]
                )
            );
    }
}

Possible Solution

No response

Additional Context

No response

Validations

GuySartorelli commented 1 month ago

I can't reproduce this error with the information you've provided. It looks like that method belongs to a class which has some specific fields in its $db and $has_one configuration?

Please provide the full code snippet, and all steps required to reproduce this problem on a fresh isntallation. And by all steps I mean all steps. If I have to click anything in the browser, there should be a step telling me what to click.

GuySartorelli commented 1 month ago

Please also provide the stack trace for the error you're getting.

isaacdarcilla commented 1 month ago

@GuySartorelli

Thank you! I am creating a Silverstripe Package here.

To reproduce the error.

  1. Install the package, in your composer.json, add the code below
 "repositories": [
        {
            "type": "vcs",
            "url": "git@github.com:isaacdarcilla/silverstripe-seo.git"
        }
    ],
  1. Then, follow the installation instruction in Basic Usage section

The error occurs when I try yo update the data in Search Engine Optimization section in page.

GuySartorelli commented 1 month ago

While I can reproduce the error with that module installed, there's way too much code in there for it to be worth me to starting debugging to even see if this is a problem with a core module, or a problem with your module.

You've ticked the box that says "Double check that your reproduction steps work in a fresh installation of silverstripe/installer (with any code examples you've provided)" - which means you have been able to reproduce this error without installing your module.

Please provide the minimum code required to reproduce this bug without installing your module. I'm going to close this issue in the meantime - once you've commented with that code sample I'll reopen it.

In the meantime I've updated the issue description to add some context about the nature of the error.