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 DC_File/DC_Folder #31

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Support DC_File/DC_Folder #31

wants to merge 2 commits into from

Conversation

m-vo
Copy link
Owner

@m-vo m-vo commented Nov 20, 2021

see #30

@zoglo Could you test if this works in your setup?

@m-vo m-vo added the feature New feature or request label Nov 20, 2021
@m-vo m-vo changed the title Support DC_Table/DC_Folder Support DC_File/DC_Folder Nov 20, 2021
@zoglo
Copy link

zoglo commented Nov 22, 2021

Hello @m-vo ,

thank you for your effort, i've installed and tested your new branch: "dev-feature/support-file-dcs".

Unfortunately, it still doesn't work as intended. The group widget still doesn't show within DC_File.
I've tested my DCA field within a DC_Table and it does show and save as intended.

Here is an example of my DCA field:

'groupWidgetTest' => array
(
	'exclude' => true,
	'inputType' => 'group',
	'eval' => ['tl_class' => 'clr'],
	'palette' => [
		'image',
		'textColor',
		'textSize',
		'textOffsetX',
		'textOffsetY',
		'step'
	],
	'fields' => [
		'image' => [
			'inputType' => 'fileTree',
			'eval' => ['mandatory' => true, 'fieldType' => 'radio', 'filesOnly' => true, 'extensions' => Config::get('validImageTypes')],
		],
		'textColor' => [
			'inputType' => 'text',
			'eval' => ['mandatory' => true, 'valign' => 'bottom', 'maxlength' => 6, 'size' => 1, 'colorpicker' => true, 'isHexColor' => true, 'decodeEntities' => true, 'tl_class' => 'wizard', 'style' => 'width:100px'],
		],
		'textSize' => [
			'inputType' => 'text',
			'default' => 14,
			'eval' => ['mandatory' => true, 'valign' => 'bottom', 'maxlength' => 6, 'size' => 1, 'colorpicker' => true, 'isHexColor' => true, 'decodeEntities' => true, 'tl_class' => 'wizard', 'style' => 'width:100px'],
		],
		'textOffsetX' => [
			'inputType' => 'text',
			'default' => 0,
			'eval' => ['mandatory' => true, 'valign' => 'bottom', 'style' => 'width:100px', 'rgxp' => 'digit'],
		],
		'textOffsetY' => [
			'inputType' => 'text',
			'default' => 0,
			'eval' => ['mandatory' => true, 'valign' => 'bottom', 'style' => 'width:100px', 'rgxp' => 'digit'],
		],
		'step' => [
			'inputType' => 'text',
			'default' => 0,
			'eval' => ['mandatory' => true, 'valign' => 'bottom', 'style' => 'width:80px', 'rgxp' => 'natural'],
		]
	],
	'min' => 1,
	'max' => 5,
	'order' => false,
	'sql' => [
		'type' => 'blob',
		'length' => \Doctrine\DBAL\Platforms\MySqlPlatform::LENGTH_LIMIT_BLOB,
		'notnull' => false,
	],
),

@m-vo
Copy link
Owner Author

m-vo commented Nov 22, 2021

Did you adjust the default tl_files palette?

@zoglo
Copy link

zoglo commented Nov 23, 2021

Yes, I am using the default palette for it.
We are using this DCA to save it into localconfig.php

// Config
'config' => array
(
    'dataContainer'          => 'File',
    'closed'                 => true
),


// Palettes
'palettes' => array
(
    'default' => '{default_legend},groupWidgetTest,...'
),

// Fields
'fields' => array
(
   ...
    'groupWidgetTest' => array
    (
       ...
    )
)

@m-vo
Copy link
Owner Author

m-vo commented Nov 24, 2021

Ah sorry, I thought you wanted to use this e.g. for additional fields in tl_files (this would be DC_Folder then). It should show in DC_Files as well, though. Could you debug why it's not?

Nevertheless, you would need another storage adapter as well if you want to store into a file: https://github.com/m-vo/contao-group-widget/blob/main/docs/storage/extending.md


private function getRowId(DataContainer $dc): int
{
if ($dc instanceof DC_File || $dc instanceof DC_Folder) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

This should probably return 0 (or any other static value) for DC_File.

@zoglo
Copy link

zoglo commented Nov 24, 2021

Hey @m-vo ,

I've found out a few things whist debugging, I hope that following information helps:

I do not reach getRowId due to following line:

public function initializeGroups(string $table): void
{
...
    if (!\in_array($action = $request->get('act', ''), ['edit', 'delete'], true)) {
        return;
    }
    

There is no action in the request (contao?do=config), thus it never gets registered.


After removing that part:

$dc instanceof DC_File returns true

$dc->id returns null


I'll test your suggestion with the storage adapter and will get back to you.

@m-vo
Copy link
Owner Author

m-vo commented Nov 24, 2021

@zoglo I updated the PR. The difference with the file driver is that it doesn't have a the concept of a "row" - there's only one. This PR works around this now. But you'll have to manage records yourself with your own storage.

Have a look at the SerializedStorage - you should be able to adapt your - say - FileStorage from this but change the database parts to file access.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants