Skip to content

Commit 85bcbd4

Browse files
committed
Paste Position
1 parent 5a34240 commit 85bcbd4

File tree

6 files changed

+63
-15
lines changed

6 files changed

+63
-15
lines changed

lang/de_de.lang

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ bloecks_settings = Einstellungen
44
bloecks_docs = Doku
55
bloecks_enable_copy_paste = Copy & Paste aktivieren
66
bloecks_enable_drag_drop = Drag & Drop aktivieren
7+
bloecks_paste_position = Einfügeposition
8+
bloecks_paste_position_after = Nach unten (unterhalb)
9+
bloecks_paste_position_before = Nach oben (oberhalb)
710
bloecks_active = aktiv
811
bloecks_templates_exclude = Template-IDs ausschließen
912
bloecks_modules_exclude = Modul-IDs ausschließen
@@ -25,7 +28,8 @@ perm_general_bloecks[order] = Slices per Drag & Drop sortieren
2528
# Copy/Cut/Paste functionality
2629
bloecks_copy_slice = Slice kopieren
2730
bloecks_cut_slice = Slice ausschneiden
28-
bloecks_paste_slice = Slice einfügen (nach diesem)
31+
bloecks_paste_slice_after = Slice einfügen (unterhalb)
32+
bloecks_paste_slice_before = Slice einfügen (oberhalb)
2933
bloecks_paste_from_clipboard = Slice aus Zwischenablage einfügen
3034
bloecks_paste_module = Einfügen: {0}
3135
bloecks_action_copied = Kopiert

lang/en_gb.lang

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ bloecks_settings = Settings
44
bloecks_docs = Docs
55
bloecks_enable_copy_paste = Enable Copy & Paste
66
bloecks_enable_drag_drop = Enable Drag & Drop
7+
bloecks_paste_position = Paste Position
8+
bloecks_paste_position_after = Insert below (after)
9+
bloecks_paste_position_before = Insert above (before)
710
bloecks_active = active
811
bloecks_templates_exclude = Exclude template IDs
912
bloecks_modules_exclude = Exclude module IDs
@@ -25,7 +28,8 @@ perm_general_bloecks[order] = Reorder slices via drag & drop
2528
# Copy/Cut/Paste functionality
2629
bloecks_copy_slice = Copy slice
2730
bloecks_cut_slice = Cut slice
28-
bloecks_paste_slice = Paste slice (after this)
31+
bloecks_paste_slice_after = Paste slice (below)
32+
bloecks_paste_slice_before = Paste slice (above)
2933
bloecks_paste_from_clipboard = Paste slice from clipboard
3034
bloecks_paste_module = Paste: {0}
3135
bloecks_action_copied = Copied

lib/bloecks_api.php

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace FriendsOfRedaxo\Bloecks;
44

55
use rex;
6+
use rex_addon;
67
use rex_api_function;
78
use rex_article;
89
use rex_article_cache;
@@ -199,18 +200,36 @@ private function handlePaste()
199200
$revision = rex_article_revision::getSessionArticleRevision($articleId);
200201
}
201202

203+
// Get paste position from config
204+
$addon = rex_addon::get('bloecks');
205+
$pastePosition = $addon->getConfig('paste_position', 'after');
206+
202207
if ($targetSlice) {
203208
$sql->setQuery('SELECT priority FROM ' . rex::getTablePrefix() . 'article_slice WHERE id=?', [$targetSlice]);
204209
if ($sql->getRows()) {
205-
$priority = (int) $sql->getValue('priority') + 1; // Insert AFTER target slice
206-
// Shift existing slices down (only in current revision)
207-
$shift = rex_sql::factory();
208-
$shift->setQuery(
209-
'UPDATE ' . rex::getTablePrefix() . 'article_slice
210-
SET priority = priority + 1
211-
WHERE article_id=? AND clang_id=? AND revision=? AND priority>=?',
212-
[$articleId, $clang, $revision, $priority],
213-
);
210+
$currentPriority = (int) $sql->getValue('priority');
211+
212+
if ($pastePosition === 'before') {
213+
$priority = $currentPriority; // Insert at current priority
214+
// Shift target slice and all following slices down
215+
$shift = rex_sql::factory();
216+
$shift->setQuery(
217+
'UPDATE ' . rex::getTablePrefix() . 'article_slice
218+
SET priority = priority + 1
219+
WHERE article_id=? AND clang_id=? AND revision=? AND priority>=?',
220+
[$articleId, $clang, $revision, $priority],
221+
);
222+
} else {
223+
$priority = $currentPriority + 1; // Insert AFTER target slice
224+
// Shift existing slices down (only in current revision)
225+
$shift = rex_sql::factory();
226+
$shift->setQuery(
227+
'UPDATE ' . rex::getTablePrefix() . 'article_slice
228+
SET priority = priority + 1
229+
WHERE article_id=? AND clang_id=? AND revision=? AND priority>=?',
230+
[$articleId, $clang, $revision, $priority],
231+
);
232+
}
214233
}
215234
} else {
216235
$priority = (int) ($sql->getArray(

lib/bloecks_backend.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,30 @@ public static function addButtons(rex_extension_point $ep): array
193193
// Paste button - always available in slice menu
194194
if ($clipboard) {
195195
$sourceInfo = $clipboard['source_info'] ?? null;
196-
$tooltipText = rex_i18n::msg('bloecks_paste_slice');
196+
197+
// Get paste position from config
198+
$pastePosition = $addon->getConfig('paste_position', 'after');
199+
$isPasteBefore = $pastePosition === 'before';
200+
201+
// Set tooltip text based on paste position
202+
$tooltipText = $isPasteBefore ? rex_i18n::msg('bloecks_paste_slice_before') : rex_i18n::msg('bloecks_paste_slice_after');
203+
$hiddenLabel = $isPasteBefore ? 'Paste before' : 'Paste after';
197204

198205
if ($sourceInfo) {
199206
$actionText = 'cut' === $clipboard['action'] ? rex_i18n::msg('bloecks_action_cut') : rex_i18n::msg('bloecks_action_copied');
207+
$positionText = $isPasteBefore ? rex_i18n::msg('paste_position_before') : rex_i18n::msg('paste_position_after');
200208
$tooltipText = sprintf(
201-
'%s: "%s" aus "%s" (ID: %d)',
209+
'%s: "%s" aus "%s" (ID: %d) - %s',
202210
$actionText,
203211
$sourceInfo['module_name'],
204212
$sourceInfo['article_name'],
205213
$sourceInfo['article_id'],
214+
$positionText
206215
);
207216
}
208217

209218
$buttons[] = [
210-
'hidden_label' => 'Paste after',
219+
'hidden_label' => $hiddenLabel,
211220
'url' => '#',
212221
'icon' => 'paste',
213222
'attributes' => [
@@ -217,6 +226,7 @@ public static function addButtons(rex_extension_point $ep): array
217226
'data-article-id' => $articleId,
218227
'data-clang-id' => $clang,
219228
'data-ctype-id' => $ctype,
229+
'data-paste-position' => $pastePosition,
220230
],
221231
];
222232
}
@@ -302,6 +312,9 @@ public static function addPasteToModuleSelect(rex_extension_point $ep): string
302312

303313
// Add paste button before module selection
304314
$sourceInfo = $clipboard['source_info'] ?? null;
315+
316+
// Get paste position from config
317+
$pastePosition = $addon->getConfig('paste_position', 'after');
305318

306319
// Bestimme den Modulnamen für den Button-Text
307320
$moduleName = '';
@@ -349,11 +362,12 @@ public static function addPasteToModuleSelect(rex_extension_point $ep): string
349362
}
350363

351364
$pasteButton = sprintf(
352-
'<div class="rex-toolbar"><div class="btn-toolbar"><a href="#" class="btn btn-success bloecks-paste" title="%s" data-target-slice="0" data-article-id="%d" data-clang-id="%d" data-ctype-id="%d"><i class="rex-icon rex-icon-paste"></i> %s</a></div></div>',
365+
'<div class="rex-toolbar"><div class="btn-toolbar"><a href="#" class="btn btn-success bloecks-paste" title="%s" data-target-slice="0" data-article-id="%d" data-clang-id="%d" data-ctype-id="%d" data-paste-position="%s"><i class="rex-icon rex-icon-paste"></i> %s</a></div></div>',
353366
htmlspecialchars($tooltipText),
354367
$articleId,
355368
$clang,
356369
$ctype,
370+
$pastePosition,
357371
htmlspecialchars($buttonText),
358372
);
359373

package.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ requires:
2828
default_config:
2929
enable_copy_paste: false
3030
enable_drag_drop: false
31+
paste_position: 'after'
3132
templates_exclude: ''
3233
modules_exclude: ''
3334

pages/settings.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
$field->setLabel(rex_i18n::msg('bloecks_enable_drag_drop'));
1919
$field->addOption(rex_i18n::msg('bloecks_active'), 1);
2020

21+
$field = $form->addSelectField('paste_position');
22+
$field->setLabel(rex_i18n::msg('bloecks_paste_position'));
23+
$select = $field->getSelect();
24+
$select->addOption(rex_i18n::msg('bloecks_paste_position_after'), 'after');
25+
$select->addOption(rex_i18n::msg('bloecks_paste_position_before'), 'before');
26+
2127
$field = $form->addTextField('templates_exclude');
2228
$field->setLabel(rex_i18n::msg('bloecks_templates_exclude'));
2329
$field->setNotice(rex_i18n::msg('bloecks_csv_notice'));

0 commit comments

Comments
 (0)