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

Support more widgets in DC_Folder #4595

Merged
merged 1 commit into from May 3, 2022

Conversation

fritzmg
Copy link
Contributor

@fritzmg fritzmg commented May 2, 2022

Currently it is not possible to use a widget within DC_Folder that executes an ajax request - e.g. fileTree. So something like this does not work:

// contao/dca/tl_files.php
use Contao\CoreBundle\DataContainer\PaletteManipulator;

$GLOBALS['TL_DCA']['tl_files']['fields']['alternative'] = [
    'label' => ['Alternative file', 'Alternative file reference.'],
    'inputType' => 'fileTree',
    'eval' => [
        'extensions' => Contao\Config::get('validImageTypes'),
        'filesOnly' => true, 
        'fieldType' => 'radio', 
        'tl_class' => 'clr',
    ],
    'sql' => 'binary(16) NULL',
];

PaletteManipulator::create()
    ->addField('alternative', 'meta')
    ->applyToPalette('default', 'tl_files')
;

If you select a file via this file picker, the resulting ajax request will fail:

Symfony\Component\HttpKernel\Exception\BadRequestHttpException:
Bad request

  at vendor\contao\contao\core-bundle\src\Resources\contao\classes\Ajax.php:318

System log entry:

A record with the ID "files/lorem/ipsum.jpg" does not exist in table "tl_files"

This is because the "ID" within DC_Folder will always be the relative file path, i.e. tl_files.path and not the database ID, i.e. tl_files.id.

This PR would fix that by automatically switching to tl_files.path for the database query, if the datacontainer is an instance of DC_Folder.

@fritzmg fritzmg added the bug label May 2, 2022
@fritzmg fritzmg added this to the 4.9 milestone May 2, 2022
@fritzmg fritzmg requested a review from a team May 2, 2022 18:21
@fritzmg fritzmg self-assigned this May 2, 2022
Copy link
Member

@Toflar Toflar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right place to do that but also it's a quick fix and there's a lot of specifics here already so it doesn't hurt.

@leofeyer leofeyer merged commit 09ec374 into contao:4.9 May 3, 2022
@leofeyer
Copy link
Member

leofeyer commented May 3, 2022

Thank you @fritzmg.

@fritzmg fritzmg deleted the support-more-widgets-in-dcfolder branch May 3, 2022 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants