Skip to content

Commit

Permalink
Tabellenseiten über nur eine Datei yform.php anzeigen
Browse files Browse the repository at this point in the history
  • Loading branch information
christophboecker committed Sep 2, 2024
1 parent 40e68c1 commit 6cdad5c
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 135 deletions.
14 changes: 14 additions & 0 deletions package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,22 @@ pages:
title: translate:neues_entry
icon: rex-icon fa-bullhorn
perm: neues[date]
subPath: pages\yform.php
category:
title: translate:neues_category
icon: rex-icon fa-folder
perm: neues[category]
subPath: pages\yform.php
author:
title: translate:neues_author
icon: rex-icon fa-user
perm: neues[author]
subPath: pages\yform.php
lang:
title: translate:neues_lang
perm: neues[lang]
icon: rex-icon fa-flag
subPath: pages\yform.php
settings:
title: translate:neues_settings
icon: rex-icon fa-gear
Expand All @@ -54,6 +58,16 @@ pages:
itemClass: pull-right
perm: neues[docs]

yform:
neues/entry:
table_name: FriendsOfRedaxo\Neues\Entry
neues/category:
table_name: FriendsOfRedaxo\Neues\Category
neues/author:
table_name: FriendsOfRedaxo\Neues\Author
neues/lang:
table_name: FriendsOfRedaxo\Neues\EntryLang

default_config:
default_author: "Redaktion"
default_thumbnail: "neues_entry_fallback_image.png"
Expand Down
34 changes: 0 additions & 34 deletions pages/neues.author.php

This file was deleted.

33 changes: 0 additions & 33 deletions pages/neues.category.php

This file was deleted.

33 changes: 0 additions & 33 deletions pages/neues.entry.php

This file was deleted.

33 changes: 0 additions & 33 deletions pages/neues.lang.php

This file was deleted.

12 changes: 12 additions & 0 deletions pages/neues.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
<?php

/** @var rex_addon $this */

/**
* für docs gilt: es sind Vorarbeiten notwendig, damit das Menü korrekt angezeigt
* wird. Daher abweichender Ablauf.
*/
if('neues/docs' === rex_be_controller::getCurrentPage()) {
$this->includeFile(__DIR__ . '/neues.docs.php');
return;
}

echo rex_view::title(rex_addon::get('neues')->getProperty('page')['title']);
rex_be_controller::includeCurrentPageSubPath();
2 changes: 0 additions & 2 deletions pages/neues.settings.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

echo rex_view::title(rex_addon::get('neues')->getProperty('page')['title']);

$addon = rex_addon::get('neues');

$form = rex_config_form::factory($addon->getName());
Expand Down
80 changes: 80 additions & 0 deletions pages/yform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Ruft Seiten des YForm-Tablemanagers als native Addon-Seiten auf.
*
* Dies ist eine allgemeine Routine und bildet eine Klammer um den Aufruf der data_edit.php
* aus yform. Details sind in den FOR-Tricks zu finden.
*
* Die Seiten sind in der package.yml des Addons definiert:
*
* ...
* subpage:
* mytable1:
* title: 'Cest moi'
* subPath: pages/yform.php
*
* yform:
* «addon»/mytable1:
* table_name: mytable_a mandatory; sieh Anmerkung unten!!!
* show_title: FALSE/true optional; default ist false!
* wrapper_class: myclass optional
*
* "table_name" entweder als Tabellenname ohne den Prefix angegeben werden oder
* als Model-Class/Dataset-Class:
* tabelle: wird über rex::getTable($table_name) zu rex_tabelle
* Namespace\Tabelle: wird über $table_name::table()->getTableName() zu rex_tabelle
*
* @see https://friendsofredaxo.github.io/tricks/addons/yform/im-addon
* @var \rex_addon $this
*/

$yform = $this->getProperty('yform', []);
$yform = $yform[\rex_be_controller::getCurrentPage()] ?? [];

if( isset($yform['table_name']) ) {
$table_name = $yform['table_name'];
if( is_subclass_of($table_name,rex_yform_manager_dataset::class)) {
// table_name ist eine Dataset-Klasse
$table_name = $table_name::table()->getTableName();
} else {
// table_name ist ein Tabellenname
$table_name = rex::getTable($table_name);
}
} else {
$table_name = '';
}

$table_name = rex_request('table_name', 'string', $table_name);
$show_title = true === ($yform['show_title'] ?? false);
$wrapper_class = $yform['wrapper_class'] ?? '';

if ('' !== $table_name) {
/**
* STAN: Using $_REQUEST is forbidden, use rex_request::request() or rex_request() instead.
* Hierfür gibt es keinen Ersatz durch eine REX-Methode/Funktion.
* @phpstan-ignore-next-line
*/
$_REQUEST['table_name'] = $table_name;
}

if (!$show_title) {
\rex_extension::register(
'YFORM_MANAGER_DATA_PAGE_HEADER',
static function (rex_extension_point $ep) {
if ($ep->getParam('yform')->table->getTableName() === $ep->getParam('table_name')) {
return '';
}
},
\rex_extension::EARLY, ['table_name' => $table_name]
);
}

if ('' !== $wrapper_class) {
echo '<div class="',$wrapper_class,'">';
}

include \rex_path::plugin('yform', 'manager', 'pages/data_edit.php');

if ('' !== $wrapper_class) {
echo '</div>';
}

0 comments on commit 6cdad5c

Please sign in to comment.