-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Implemented PHPStan level 8, introduced some DTO classes to…
… prevent some multidimensional array shapes, introduced BackendUserTrait and LanguageServiceTrait
- Loading branch information
Showing
67 changed files
with
1,024 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
parameters: | ||
level: 0 | ||
level: 8 | ||
paths: | ||
- ../Classes | ||
- ../Configuration | ||
excludePaths: | ||
- ../Classes/Updates | ||
ignoreErrors: | ||
- '#Parameter \$event of method#' | ||
- '#TYPO3\\CMS\\Frontend\\Page\\PageInformation#' | ||
- '#TYPO3\\CMS\\Backend\\View\\BackendViewFactory#' | ||
- '#TYPO3\\CMS\\Install\\Attribute\\UpgradeWizard#' | ||
- '#TYPO3\\CMS\\Backend\\Template\\ModuleTemplate#' | ||
- '#TYPO3\\CMS\\Extbase\\Mvc\\RequestInterface#' | ||
- '#TYPO3\\CMS\\Core\\View\\ViewInterface#' | ||
- '#TYPO3\\CMS\\Core\\Domain\\Repository\\PageRepository::getLanguageOverlay#' | ||
- '#frontend.page.information#' | ||
- '#ModifyPageLayoutContentEvent#' | ||
- '#AfterCacheableContentIsGeneratedEvent#' | ||
- '#loadJavaScriptModule#' | ||
- '#getLanguageCode#' | ||
- '#addJsInlineCode#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
parameters: | ||
level: 0 | ||
level: 8 | ||
paths: | ||
- ../Classes | ||
- ../Configuration | ||
excludePaths: | ||
- ../Classes/Updates | ||
ignoreErrors: | ||
- '#TYPO3\\CMS\\Backend\\ViewHelpers\\ModuleLayoutViewHelper#' | ||
- '#TYPO3\\CMS\\Frontend\\Page\\PageInformation#' | ||
- '#frontend.page.information#' | ||
- '#protected method getRecordOverlay#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
parameters: | ||
level: 0 | ||
level: 8 | ||
paths: | ||
- ../Classes | ||
- ../Configuration | ||
excludePaths: | ||
- ../Classes/Updates | ||
ignoreErrors: | ||
- '#TYPO3\\CMS\\Backend\\ViewHelpers\\ModuleLayoutViewHelper#' | ||
- '#TYPO3\\CMS\\Backend\\Template\\ModuleTemplate#' | ||
- '#getRecordOverlay#' | ||
- '#loadRequireJsModule#' | ||
typo3: | ||
requestGetAttributeMapping: | ||
frontend.page.information: TYPO3\CMS\Frontend\Page\PageInformation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,64 @@ | ||
# EditorConfig is awesome: http://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[{*.rst,*.rst.txt}] | ||
# Unix-style newlines with a newline ending every file | ||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 4 | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
indent_size = 3 | ||
|
||
# TS/JS-Files | ||
[*.{ts,js,mjs}] | ||
indent_size = 2 | ||
|
||
# JSON-Files | ||
[*.json] | ||
indent_style = tab | ||
|
||
# ReST-Files | ||
[*.{rst,rst.txt}] | ||
indent_size = 4 | ||
max_line_length = 80 | ||
|
||
# MD-Files | ||
# Markdown-Files | ||
[*.md] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
indent_size = 4 | ||
max_line_length = 80 | ||
|
||
# YAML-Files | ||
[*.{yaml,yml}] | ||
indent_size = 2 | ||
|
||
# NEON-Files | ||
[*.neon] | ||
indent_size = 2 | ||
indent_style = tab | ||
|
||
# stylelint | ||
[.stylelintrc] | ||
indent_size = 2 | ||
|
||
# package.json | ||
[package.json] | ||
indent_size = 2 | ||
|
||
# TypoScript | ||
[*.{typoscript,tsconfig}] | ||
indent_size = 2 | ||
|
||
# XLF-Files | ||
[*.xlf] | ||
indent_style = tab | ||
|
||
# SQL-Files | ||
[*.sql] | ||
indent_style = tab | ||
indent_size = 2 | ||
|
||
# .htaccess | ||
[{_.htaccess,.htaccess}] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace YoastSeoForTypo3\YoastSeo\Backend\Overview; | ||
|
||
class DataProviderRequest | ||
{ | ||
public function __construct( | ||
protected int $id = 0, | ||
protected int $language = 0, | ||
protected string $table = '', | ||
) {} | ||
|
||
public function getId(): int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getLanguage(): int | ||
{ | ||
return $this->language; | ||
} | ||
|
||
public function getTable(): string | ||
{ | ||
return $this->table; | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
Classes/Backend/Overview/LanguageMenu/LanguageMenuFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace YoastSeoForTypo3\YoastSeo\Backend\Overview\LanguageMenu; | ||
|
||
use TYPO3\CMS\Backend\Template\Components\Menu\Menu; | ||
use TYPO3\CMS\Backend\Template\ModuleTemplate; | ||
use TYPO3\CMS\Core\Exception\SiteNotFoundException; | ||
use TYPO3\CMS\Core\Site\Entity\SiteLanguage; | ||
use TYPO3\CMS\Core\Site\SiteFinder; | ||
use TYPO3\CMS\Extbase\Mvc\RequestInterface; | ||
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder; | ||
use YoastSeoForTypo3\YoastSeo\Traits\BackendUserTrait; | ||
use YoastSeoForTypo3\YoastSeo\Traits\LanguageServiceTrait; | ||
|
||
class LanguageMenuFactory | ||
{ | ||
use BackendUserTrait, LanguageServiceTrait; | ||
|
||
protected RequestInterface $request; | ||
protected ModuleTemplate $moduleTemplate; | ||
protected int $pageUid; | ||
|
||
public function __construct( | ||
protected SiteFinder $siteFinder, | ||
protected UriBuilder $uriBuilder | ||
) { | ||
} | ||
|
||
public function create( | ||
RequestInterface $request, | ||
ModuleTemplate $moduleTemplate, | ||
int $pageUid | ||
): ?Menu { | ||
try { | ||
$site = $this->siteFinder->getSiteByPageId($pageUid); | ||
} catch (SiteNotFoundException) { | ||
return null; | ||
} | ||
|
||
$languages = $site->getAvailableLanguages($this->getBackendUser()); | ||
if (empty($languages)) { | ||
return null; | ||
} | ||
|
||
$this->request = $request; | ||
$this->moduleTemplate = $moduleTemplate; | ||
$this->pageUid = $pageUid; | ||
|
||
return $this->buildLanguageMenu($languages); | ||
} | ||
|
||
/** | ||
* @param SiteLanguage[] $languages | ||
*/ | ||
protected function buildLanguageMenu( | ||
array $languages | ||
): Menu { | ||
$languageMenu = $this->moduleTemplate->getDocHeaderComponent()->getMenuRegistry()->makeMenu(); | ||
$languageMenu->setIdentifier('languageMenu'); | ||
$languageMenu->setLabel( | ||
$this->getLanguageService()->sL( | ||
'LLL:EXT:core/Resources/Private/Language/locallang_general.xlf:LGL.language' | ||
) | ||
); | ||
foreach ($this->getLanguageMenuItems($languages) as $languageMenuItem) { | ||
$menuItem = $languageMenu | ||
->makeMenuItem() | ||
->setTitle($languageMenuItem->getTitle()) | ||
->setHref($languageMenuItem->getHref()) | ||
->setActive($languageMenuItem->isActive()); | ||
$languageMenu->addMenuItem($menuItem); | ||
} | ||
return $languageMenu; | ||
} | ||
|
||
/** | ||
* @param SiteLanguage[] $languages | ||
* @return LanguageMenuItem[] | ||
*/ | ||
protected function getLanguageMenuItems( | ||
array $languages | ||
): array { | ||
$arguments = $this->getArguments(); | ||
|
||
$filter = $arguments['filter'] ?? ''; | ||
$returnUrl = $arguments['returnUrl'] ?? ''; | ||
$items = []; | ||
foreach ($languages as $language) { | ||
$url = $this->uriBuilder | ||
->reset() | ||
->setRequest($this->request) | ||
->setTargetPageUid($this->pageUid) | ||
->setArguments([ | ||
'tx_yoastseo_yoast_yoastseooverview' => [ | ||
'filter' => $filter, | ||
'language' => $language->getLanguageId(), | ||
'returnUrl' => $returnUrl, | ||
'controller' => 'Overview', | ||
], | ||
]) | ||
->build(); | ||
$items[] = new LanguageMenuItem( | ||
$language->getTitle(), | ||
$url, | ||
(int)($arguments['language'] ?? 0) === $language->getLanguageId() | ||
); | ||
} | ||
return $items; | ||
} | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
protected function getArguments(): array | ||
{ | ||
return $this->request->getArguments()['tx_yoastseo_yoast_yoastseooverview'] ?? $this->request->getArguments(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
Classes/Backend/Overview/LanguageMenu/LanguageMenuItem.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace YoastSeoForTypo3\YoastSeo\Backend\Overview\LanguageMenu; | ||
|
||
class LanguageMenuItem | ||
{ | ||
public function __construct( | ||
protected string $title = '', | ||
protected string $href = '', | ||
protected bool $active = false, | ||
) { | ||
} | ||
|
||
public function getTitle(): string | ||
{ | ||
return $this->title; | ||
} | ||
|
||
public function setTitle(string $title): void | ||
{ | ||
$this->title = $title; | ||
} | ||
|
||
public function getHref(): string | ||
{ | ||
return $this->href; | ||
} | ||
|
||
public function setHref(string $href): void | ||
{ | ||
$this->href = $href; | ||
} | ||
|
||
public function isActive(): bool | ||
{ | ||
return $this->active; | ||
} | ||
|
||
public function setActive(bool $active): void | ||
{ | ||
$this->active = $active; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.