Skip to content

Commit

Permalink
feat: initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdmlln committed Apr 18, 2024
0 parents commit f544e51
Show file tree
Hide file tree
Showing 21 changed files with 5,617 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .build/phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer">
<config name="installed_paths" value="../../slevomat/coding-standard" />
<rule ref="Generic.Arrays.DisallowLongArraySyntax">
<type>error</type>
</rule>
<rule ref="PSR12">
<type>error</type>
</rule>
<rule ref="Generic.Files.LineLength">
<type>warning</type>
</rule>
<rule ref="SlevomatCodingStandard.Arrays.SingleLineArrayWhitespace">
<type>error</type>
</rule>
<rule ref="SlevomatCodingStandard.Arrays.MultiLineArrayEndBracketPlacement">
<type>error</type>
</rule>
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma">
<type>error</type>
</rule>
<rule ref="SlevomatCodingStandard.Classes.ClassStructure">
<type>warning</type>
</rule>
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses">
<type>error</type>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
<type>error</type>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<type>error</type>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<type>error</type>
</rule>
<rule ref="SlevomatCodingStandard.Whitespaces.DuplicateSpaces">
<type>error</type>
<properties>
<property name="ignoreSpacesInComment" value="true" />
</properties>
</rule>
<rule ref="Squiz.Strings.DoubleQuoteUsage">
<type>error</type>
</rule>
</ruleset>
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
21 changes: 21 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on:
pull_request:

jobs:
commitlint:
runs-on: ubuntu-latest
steps:
- uses: remindgmbh/commitlint-action@v1.0.0
phpcs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: intl
tools: composer:v2
- run: composer install
- run: composer run-script phpcs
14 changes: 14 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Release

on:
push:
branches:
- "main"

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: remindgmbh/semantic-release-action@v2.2.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### IDE ###
nbproject/
.idea/

### Composer ###
composer.phar

### Node ###
node_modules/

### General ###
*.log
cache.properties

### CI ###
.build/bin/
.build/vendor/
.build/web/
.build/logs/
.build/coverage/
.build/pdepend/
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"benjaminkott.typo3-typoscript",
"devsense.phptools-vscode",
"obliviousharmony.vscode-php-codesniffer"
],
"unwantedRecommendations": []
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"phpCodeSniffer.exec.linux": "./.build/bin/phpcs",
"phpCodeSniffer.standard": "Custom",
"phpCodeSniffer.standardCustom": "./.build/phpcs.xml",
"phpCodeSniffer.exclude": [
"**/vendor/{,!(remind)/**}"
]
}
29 changes: 29 additions & 0 deletions Classes/LinkHandler/LinkBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Remind\MatomoLinkHandler\LinkHandler;

use TYPO3\CMS\Frontend\Typolink\AbstractTypolinkBuilder;
use TYPO3\CMS\Frontend\Typolink\LinkResult;
use TYPO3\CMS\Frontend\Typolink\LinkResultInterface;

class LinkBuilder extends AbstractTypolinkBuilder
{
private const TYPE_MATOMO = 'matomo';

public function build(
array &$linkDetails,
string $linkText,
string $target,
array $conf,
): LinkResultInterface {
$action = $linkDetails['action'];
$url = 't3://matomo?action=' . $action;

return (new LinkResult(self::TYPE_MATOMO, $url))
->withTarget($target)
->withLinkConfiguration($conf)
->withLinkText($linkText);
}
}
78 changes: 78 additions & 0 deletions Classes/LinkHandler/LinkHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Remind\MatomoLinkHandler\LinkHandler;

use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Controller\AbstractLinkBrowserController;
use TYPO3\CMS\Backend\LinkHandler\LinkHandlerInterface;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\View\ViewInterface;

class LinkHandler implements LinkHandlerInterface
{
protected array $linkAttributes = ['title'];

protected array $linkParts = [];

protected ViewInterface $view;

protected array $configuration;

public function __construct(
private readonly PageRenderer $pageRenderer
) {
}

public function initialize(AbstractLinkBrowserController $linkBrowser, $identifier, array $configuration)
{
$this->configuration = $configuration;
}

public function canHandleLink(array $linkParts): bool
{
if ($linkParts['type'] !== 'matomo') {
return false;
}
$this->linkParts = $linkParts['url'] ?? [];
return true;
}

public function formatCurrentUrl(): string
{
return 't3://matomo?action=' . $this->linkParts['action'] ?? '';
}

public function render(ServerRequestInterface $request): string
{
$this->pageRenderer->loadJavaScriptModule('@remind/matomo-link-handler/link_handler.js');
$this->view->assign('linkParts', $this->linkParts);
$this->view->assign('action', $this->linkParts['action'] ?? '');

return $this->view->render('LinkBrowser/Matomo');
}

public function getBodyTagAttributes(): array
{
return [];
}

public function getLinkAttributes()
{
return $this->linkAttributes;
}

public function modifyLinkAttributes(array $fieldDefinitions)
{
return $fieldDefinitions;
}

public function isUpdateSupported()
{
return false;
}

public function setView(ViewInterface $view): void
{
$this->view = $view;
}
}
22 changes: 22 additions & 0 deletions Classes/LinkHandler/LinkHandling.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Remind\MatomoLinkHandler\LinkHandler;

use TYPO3\CMS\Core\LinkHandling\LinkHandlingInterface;

class LinkHandling implements LinkHandlingInterface
{
protected $baseUrn = 't3://matomo';

public function asString(array $parameters): string
{
return $this->baseUrn . '?action=' . $parameters['action'];
}

public function resolveHandlerData(array $data): array
{
return [
'action' => $data['action'] ?? '',
];
}
}
11 changes: 11 additions & 0 deletions Configuration/JavaScriptModules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

return [
'dependencies' => ['core', 'backend'],
'tags' => [
'backend.contextmenu',
],
'imports' => [
'@remind/matomo-link-handler/' => 'EXT:rmnd_matomo_link_handler/Resources/Public/JavaScript/',
],
];
8 changes: 8 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false
Remind\MatomoLinkHandler\LinkHandler\LinkHandler:
shared: false
public: true
12 changes: 12 additions & 0 deletions Configuration/TSConfig/Page/TCEMAIN.tsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TCEMAIN.linkHandler {
matomo {
handler = Remind\MatomoLinkHandler\LinkHandler\LinkHandler
label = LLL:EXT:rmnd_matomo_link_handler/Resources/Private/Language/locallang.xlf:title
displayAfter = url
scanBefore = url
configuration {
project = TYPO3-Documentation/TYPO3CMS-Reference-CoreApi
action = issues
}
}
}
5 changes: 5 additions & 0 deletions Configuration/TSConfig/Page/templates.tsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
templates {
typo3/cms-backend {
1713438106 = remind/matomo-link-handler:Resources/Private
}
}
1 change: 1 addition & 0 deletions Configuration/page.tsconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import 'EXT:rmnd_matomo_link_handler/Configuration/TSConfig/Page/*.tsconfig'
23 changes: 23 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<xliff version="1.0">
<file source-language="en" datatype="plaintext">
<header/>
<body>
<trans-unit id="action">
<source>Action</source>
</trans-unit>
<trans-unit id="opt-in">
<source>Opt-In</source>
</trans-unit>
<trans-unit id="opt-out">
<source>Opt-Out</source>
</trans-unit>
<trans-unit id="title">
<source>Matomo</source>
</trans-unit>
<trans-unit id="toggle">
<source>Toggle</source>
</trans-unit>
</body>
</file>
</xliff>
32 changes: 32 additions & 0 deletions Resources/Private/Templates/Default/LinkBrowser/Matomo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
data-namespace-typo3-fluid="true"
>

<f:layout name="LinkBrowser" />

<f:section name="Content">
<form class="form" action="" id="lmatomoform">
<div class="element-browser-form-group">
<label for="lmatomo" class="form-label">
<f:translate key="LLL:EXT:rmnd_matomo_link_handler/Resources/Private/Language/locallang.xlf:action" />
</label>
<div class="input-group">
<select name="lmatomo" class="form-select" id="lmatomo" reqiured>
<option value="opt-out" {f:if(condition: '{action} === "opt-out"', then: 'selected')}>
<f:translate key="LLL:EXT:rmnd_matomo_link_handler/Resources/Private/Language/locallang.xlf:opt-out" />
</option>
<option value="opt-in" {f:if(condition: '{action} === "opt-in"', then: 'selected')}>
<f:translate key="LLL:EXT:rmnd_matomo_link_handler/Resources/Private/Language/locallang.xlf:opt-in" />
</option>
<option value="toggle" {f:if(condition: '{action} === "toggle"', then: 'selected')}>
<f:translate key="LLL:EXT:rmnd_matomo_link_handler/Resources/Private/Language/locallang.xlf:toggle" />
</option>
</select>
<input class="btn btn-primary" type="submit" value="{f:translate(key: 'LLL:EXT:backend/Resources/Private/Language/locallang_browse_links.xlf:setLink')}" />
</div>
</div>
</form>
</f:section>

</html>
14 changes: 14 additions & 0 deletions Resources/Public/JavaScript/link_handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import LinkBrowser from "@typo3/backend/link-browser.js";

class LinkHandler {
constructor() {
var form_el = document.getElementById("lmatomoform");
form_el.addEventListener("submit", function(event) {
event.preventDefault();
var value = document.getElementById('lmatomo').value;
LinkBrowser.finalizeFunction('t3://matomo?action=' + value);
});
}
}

export default new LinkHandler();
Loading

0 comments on commit f544e51

Please sign in to comment.