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

Use concrete object types in side Panel #1077

Merged
merged 4 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion resources/js/app/components/relation-view/relations-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ export default {

return;
}
if (this.relationTypes.right.length === 1) {
if (this.relationTypes?.right?.length === 1) {
this.object.type = this.relationTypes.right[0];
} else {
this.object.type = '_choose';
Expand Down
3 changes: 2 additions & 1 deletion resources/js/app/plugins/tinymce/placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,15 @@ tinymce.util.Tools.resolve('tinymce.PluginManager').add('placeholders', function

editor.ui.registry.addButton('placeholders', {
icon: 'image',
tooltip: 'Add placeholder',
tooltip: t`Add placeholder`,
onAction() {
PanelEvents.requestPanel({
action: 'relations-add',
from: this,
data: {
relationName: 'placeholder',
relationLabel: 'Placeholder',
relationTypes: {right: BEDITA?.relationsSchema?.placeholder?.right || null},
},
});

Expand Down
3 changes: 3 additions & 0 deletions src/Controller/ModulesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,11 @@ private function setupViewRelations(array $relations): void
$this->Properties->hiddenRelationsList($this->objectType),
$this->Properties->readonlyRelationsList($this->objectType)
);

// set right types, considering the object type relations
$rel = (array)$this->viewBuilder()->getVar('relationsSchema');
$rightTypes = \App\Utility\Schema::rightTypes($rel);
$this->set('rightTypes', $rightTypes);

// set schemas for relations right types
$schemasByType = $this->Schema->getSchemasByType($rightTypes);
Expand Down
1 change: 1 addition & 0 deletions src/View/Helper/LayoutHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ public function metaConfig(): array
'canSave' => $this->Perms->canSave(),
'cloneConfig' => (array)Configure::read('Clone'),
'uploadConfig' => $this->System->uploadConfig(),
'relationsSchema' => $this->getView()->get('relationsSchema', []),
];
}

Expand Down
1 change: 1 addition & 0 deletions src/View/Helper/SchemaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ public function sortable(string $field): bool
* Return unique right types from schema "relationsSchema".
*
* @return array
* @deprecated It will be removed in version 5.x.
*/
public function rightTypes(): array
batopa marked this conversation as resolved.
Show resolved Hide resolved
{
Expand Down
2 changes: 1 addition & 1 deletion templates/Element/Panel/relations_add.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</select>
</div>

{% for type in Schema.rightTypes() %}
{% for type in rightTypes %}
{% set prefix = '_fast_create_' ~ type ~ '_' %}
{{ Form.create(null, {
'name': 'create-object',
Expand Down
2 changes: 2 additions & 0 deletions tests/TestCase/View/Helper/LayoutHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ public function testMetaConfig(): void
$viewVars = [
'modules' => ['documents' => [], 'images' => []],
'uploadable' => ['images'],
'relationsSchema' => ['whatever'],
];
$view = new View($request, null, null, compact('viewVars'));
$layout = new LayoutHelper($view);
Expand All @@ -440,6 +441,7 @@ public function testMetaConfig(): void
'canSave' => true,
'cloneConfig' => (array)Configure::read('Clone'),
'uploadConfig' => $system->uploadConfig(),
'relationsSchema' => ['whatever'],
];
static::assertSame($expected, $conf);
}
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase/View/Helper/SchemaHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,7 @@ public function testRightTypes($relationsSchema, $expected): void
{
$view = $this->Schema->getView();
$view->set('relationsSchema', $relationsSchema);
/** @phpstan-ignore-next-line */
$actual = $this->Schema->rightTypes();
static::assertSame($expected, $actual);
}
Expand Down
Loading