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

[FEATURE] Add links for backend editor on the frontend #800

Merged
merged 1 commit into from
Jan 13, 2025
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
51 changes: 51 additions & 0 deletions Classes/Frontend/BackendEditorUrl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

/*
* This file is part of the "headless" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.md file that was distributed with this source code.
*/

declare(strict_types=1);

namespace FriendsOfTYPO3\Headless\Frontend;

use TYPO3\CMS\Backend\Routing\UriBuilder;

/**
* @codeCoverageIgnore
*/
class BackendEditorUrl
{
public function __construct(protected UriBuilder $uriBuilder) {}

public function page(): string
{
return $this->generateUrl('pages');
}

public function record(): string
{
return $this->generateUrl();
}

private function generateUrl(string $table = 'tt_content'): string
{
$beUser = $GLOBALS['BE_USER'] ?? null;

if ($beUser === null) {
return '';
}

$params = [
'edit' => [
$table => [
'__id__' => 'edit',
],
],
];

return (string)$this->uriBuilder->buildUriFromRoute('record_edit', $params, UriBuilder::ABSOLUTE_URL);
}
}
2 changes: 2 additions & 0 deletions Configuration/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use FriendsOfTYPO3\Headless\Event\Listener\HeadlessHreflangGeneratorListener;
use FriendsOfTYPO3\Headless\Event\Listener\LoginConfirmedEventListener;
use FriendsOfTYPO3\Headless\Form\Service\FormTranslationService;
use FriendsOfTYPO3\Headless\Frontend\BackendEditorUrl;
use FriendsOfTYPO3\Headless\Utility\FileUtility;
use FriendsOfTYPO3\Headless\Utility\HeadlessFrontendUrlInterface;
use FriendsOfTYPO3\Headless\Utility\UrlUtility;
Expand Down Expand Up @@ -74,6 +75,7 @@
$toLoad->set(IntegerContentObject::class)->tag('frontend.contentobject', ['identifier' => 'INT']);
$toLoad->set(FloatContentObject::class)->tag('frontend.contentobject', ['identifier' => 'FLOAT']);

$services->set(BackendEditorUrl::class)->public();
$services->set(FileUtility::class)->public();
$services->set(HeadlessFrontendUrlInterface::class, UrlUtility::class)->autowire(false);
$services->set(AfterLinkIsGeneratedListener::class)->tag(
Expand Down
14 changes: 14 additions & 0 deletions Configuration/TypoScript/Configuration/BackendEditor.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
lib.backendEditor = JSON
lib.backendEditor {
fields {
record = USER_INT
record {
userFunc = FriendsOfTYPO3\Headless\Frontend\BackendEditorUrl->record
}

page = USER_INT
page {
userFunc = FriendsOfTYPO3\Headless\Frontend\BackendEditorUrl->page
}
}
}
3 changes: 3 additions & 0 deletions Configuration/TypoScript/LoggedUser/BackendEditor.typoscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[backend.user.isLoggedIn]
initialData.10.fields.backendEditor < lib.backendEditor
[END]
6 changes: 6 additions & 0 deletions Configuration/TypoScript/Mixed/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ plugin.tx_headless {
[request && traverse(request.getHeaders(), 'accept')[0] == 'application/json']
## Include page
@import "EXT:headless/Configuration/TypoScript/Page/*.typoscript"
## Include helpers
@import "EXT:headless/Configuration/TypoScript/Helpers/*.typoscript"
## Include content elements
@import "EXT:headless/Configuration/TypoScript/ContentElement/*.typoscript"
## Include configuration
Expand All @@ -19,3 +21,7 @@ plugin.tx_headless {
logged.value = 1
}
[END]

[request && traverse(request.getHeaders(), 'accept')[0] == 'application/json' && backend.user.isLoggedIn]
initialData.10.fields.backendEditor < lib.backendEditor
[END]
2 changes: 1 addition & 1 deletion Configuration/TypoScript/setup.typoscript
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ plugin.tx_headless {
@import "EXT:headless/Configuration/TypoScript/ContentElement/*.typoscript"
## Include configuration
@import "EXT:headless/Configuration/TypoScript/Configuration/*.typoscript"
@import "EXT:headless/Configuration/TypoScript/LoggedUser/FeLogin.typoscript"
@import "EXT:headless/Configuration/TypoScript/LoggedUser/*.typoscript"
Loading