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

Tabellenseiten über nur ein Script yform.php darstellen #96

Merged
merged 4 commits into from
Sep 2, 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
1 change: 1 addition & 0 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
if (null === rex_media::get($fallbackImage)) {
rex_file::copy(__DIR__ . '/install/' . $fallbackImage, rex_path::media($fallbackImage));
$data = [];
// TODO: Text nach *.lang verlagern
$data['title'] = 'Aktuelles - Fallback-Image';
$data['category_id'] = 0;
$data['file'] = [
Expand Down
1 change: 1 addition & 0 deletions lib/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ public static function findByCategoryIds(string|array|null $category_ids = null,
}

// whereInList anwenden
// FIXME: whereInList gibt es nicht! Ist $query->whereListContains() gemeint?
$query->whereInList('category_ids', $category_ids);
}

Expand Down
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>';
}
1 change: 1 addition & 0 deletions uninstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
$scope = rex_request::get('nscope', 'int', 0);
if (!in_array($scope, [1, 2], true)) {
$context = rex_context::fromGet();
// TODO: Texte nach *.lang verlagern
$msg = '### Bitte den De-Installations-Umfang auswählen' . PHP_EOL;
$msg .= '- **Minimal** (YForm-Tablesets entfernen) ⇒ **[Start](' . $context->getUrl(['nscope' => 1], false) . ')**' . PHP_EOL;
$msg .= '- **Vollständig** (Tabellen, Tablesets, Cronjobs etc. entfernen) ⇒ **[Start](' . $context->getUrl(['nscope' => 2], false) . ')**' . PHP_EOL;
Expand Down
Loading