Skip to content

Commit

Permalink
Use concrete object types in side Panel (#1077)
Browse files Browse the repository at this point in the history
* refactor: use concrete object types

* fix: restore methods as deprecated

* fix: phpstan-ignore for deprecations in tests

* refactor: restore Schema.rightTypes
  • Loading branch information
didoda authored Jan 25, 2024
1 parent 2323b91 commit 98a0dbb
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 3 deletions.
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
{
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

0 comments on commit 98a0dbb

Please sign in to comment.