fisharebest / webtrees

Online genealogy
https://webtrees.net
GNU General Public License v3.0
488 stars 301 forks source link

2.1.9: parameter "tree" is missing (function getFooter when calling control panel menu of new custom footer module) #4638

Closed hartenthaler closed 1 year ago

hartenthaler commented 1 year ago

I'm developing a new custom footer module that uses the control panel to let the admin set some options.

When I try (using webtrees 2.1.9) to open the menu for my module in the control panel: I get the message:

The parameter “tree” is missing.

This when I use the following code

    /**
     * A footer, to be added at the bottom of every page.
     *
     * @param ServerRequestInterface $request
     *
     * @return string
     */
    public function getFooter(ServerRequestInterface $request): string
    {
        $tree = Validator::attributes($request)->treeOptional();                   // tbd there is sometimes an error

        $url = route('module', [
            'module' => $this->name(),
            'action' => 'Page',
            'tree'   => $tree ? $tree->name() : null,
        ]);

        return view($this->name() . '::footer', ['url' => $url]);
    } 

When I replace the line $tree = Validator::attributes($request)->treeOptional(); by $tree = $request->getAttribute('tree'); I get the same result.

When I replace this line by $tree = Validator::attributes($request)->tree(); I get

Uncaught Fisharebest\Webtrees\Http\Exceptions\HttpBadRequestException: The parameter “tree” is missing. in /mnt/web109/a3/99/51547399/htdocs/hermann/hartenthaler/php/webtreestest/app/Validator.php:363 Stack trace: #0 /mnt/web109/a3/99/51547399/htdocs/hermann/hartenthaler/php/webtreestest/modules_v4/hh_imprint/ImprintFooterModule.php(328): Fisharebest\Webtrees\Validator->tree() #1 /mnt/web109/a3/99/51547399/htdocs/hermann/hartenthaler/php/webtreestest/modules_v4/vesta_classic_look_and_feel/resources/views/layouts/default.phtml(154): Hartenthaler\Webtrees\Module\Imprint\ImprintFooterModule->getFooter()

The referenced line 328 is the line that I tried in several versions.

When I disable the vesta_classical_look_and_feel module the error is nearly the same

Uncaught Fisharebest\Webtrees\Http\Exceptions\HttpBadRequestException: The parameter “tree” is missing. in /mnt/web109/a3/99/51547399/htdocs/hermann/hartenthaler/php/webtreestest/app/Validator.php:363 Stack trace: #0 /mnt/web109/a3/99/51547399/htdocs/hermann/hartenthaler/php/webtreestest/modules_v4/hh_imprint/ImprintFooterModule.php(328): Fisharebest\Webtrees\Validator->tree() #1 /mnt/web109/a3/99/51547399/htdocs/hermann/hartenthaler/php/webtreestest/resources/views/layouts/default.phtml(140): Hartenthaler\Webtrees\Module\Imprint\ImprintFooterModule->getFooter() #2 [internal function]: Fisharebest\Webtrees\View::{closure}() #3 /mnt/web109/a3/99/51547399/htdocs/hermann/hartenthaler/php/webtreestest/vendor/illuminate/collections/Collection.php(695): array_map() #4

The error was not there in webtrees 2.1.7 and I don't think that I changed anything in the cited function, but many things in other newly developed functions. When not calling the control panel menu, the module is working correctly and shows the footer as intended. Maybe the error is somewhere else. What can I do to debug this problem?

fisharebest commented 1 year ago

When I disable the vesta_classical_look_and_feel module the error is nearly the same

This time, the error is in the module hh_imprint.

It's the same thing. The code is expecting that the URL contains a tree parameter. This is not always true. Some pages do not have one. For example, the login/register pages on sites where all trees are private.

If you disable hh_imprint, do you still see the error?

fisharebest commented 1 year ago

Do you still need help with this?

hartenthaler commented 1 year ago

Yes, I was busy with other topics. I reinstalled now an earlier version of my module, and the error disappeared there. So I'm currently checking the differences in the code in order to identify the reason.

The error occurs when opening in the control panel the options menü for my module hh_imprint. When showing the control panel there is no footer, so this is a special case. But there is no error when opening the control panel itself or opening the options menu of any other module in the control panel.

hartenthaler commented 1 year ago

It was a bug in the code of my new module. Now it is working.