TYPO3 v15 dev-main snapshot ()
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Domain\Model\Element;
|
||||
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Model for creating an immediate action element on a module
|
||||
*
|
||||
* @internal not part of TYPO3 Core API due to possible refactorings in this place.
|
||||
*/
|
||||
class ImmediateActionElement
|
||||
{
|
||||
protected string $action;
|
||||
protected ?array $args = null;
|
||||
|
||||
public static function forAction(string $action): self
|
||||
{
|
||||
return new self($action, null);
|
||||
}
|
||||
|
||||
public static function moduleStateUpdate(string $module, $identifier, ?bool $select = null): self
|
||||
{
|
||||
return new self(
|
||||
'TYPO3.Backend.Storage.ModuleStateStorage.update',
|
||||
[$module, $identifier, $select]
|
||||
);
|
||||
}
|
||||
|
||||
public static function moduleStateUpdateWithCurrentMount(string $module, $identifier, ?bool $select = null): self
|
||||
{
|
||||
return new self(
|
||||
'TYPO3.Backend.Storage.ModuleStateStorage.updateWithCurrentMount',
|
||||
[$module, $identifier, $select]
|
||||
);
|
||||
}
|
||||
|
||||
public static function dispatchCustomEvent(string $name, ?array $details = null, bool $useTop = false): self
|
||||
{
|
||||
return new self(
|
||||
'TYPO3.Backend.Event.EventDispatcher.dispatchCustomEvent',
|
||||
[$name, $details, $useTop]
|
||||
);
|
||||
}
|
||||
|
||||
private function __construct(string $action, ?array $args)
|
||||
{
|
||||
$this->action = $action;
|
||||
$this->args = $args;
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
{
|
||||
$attributes = ['action' => $this->action];
|
||||
if ($this->args !== null) {
|
||||
$attributes['args'] = GeneralUtility::jsonEncodeForHtmlAttribute($this->args);
|
||||
}
|
||||
return sprintf(
|
||||
'<typo3-immediate-action %s></typo3-immediate-action>',
|
||||
GeneralUtility::implodeAttributes($attributes, true)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Domain\Model\Language;
|
||||
|
||||
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||
|
||||
/**
|
||||
* Represents a single language with its status and UI properties.
|
||||
* Contains all information needed to render language menu items.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final readonly class LanguageItem
|
||||
{
|
||||
public function __construct(
|
||||
public SiteLanguage $siteLanguage,
|
||||
public LanguageStatus $status,
|
||||
) {}
|
||||
|
||||
public function isExisting(): bool
|
||||
{
|
||||
return $this->status === LanguageStatus::Existing;
|
||||
}
|
||||
|
||||
public function isCreatable(): bool
|
||||
{
|
||||
return $this->status === LanguageStatus::Creatable;
|
||||
}
|
||||
|
||||
public function isAvailable(): bool
|
||||
{
|
||||
return $this->status !== LanguageStatus::Unavailable;
|
||||
}
|
||||
|
||||
public function getTitle(): string
|
||||
{
|
||||
return $this->siteLanguage->getTitle();
|
||||
}
|
||||
|
||||
public function getFlagIdentifier(): string
|
||||
{
|
||||
return $this->siteLanguage->getFlagIdentifier();
|
||||
}
|
||||
|
||||
public function getLanguageId(): int
|
||||
{
|
||||
return $this->siteLanguage->getLanguageId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Domain\Model\Language;
|
||||
|
||||
/**
|
||||
* Status of a language for a specific page.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
enum LanguageStatus
|
||||
{
|
||||
/**
|
||||
* Translation exists for this language
|
||||
*/
|
||||
case Existing;
|
||||
|
||||
/**
|
||||
* Translation can be created (language is available for the page and user has permission)
|
||||
*/
|
||||
case Creatable;
|
||||
|
||||
/**
|
||||
* Translation cannot be created (e.g. due to insufficient permissions)
|
||||
*/
|
||||
case Unavailable;
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
namespace TYPO3\CMS\Backend\Domain\Model\Language;
|
||||
|
||||
use TYPO3\CMS\Core\Site\Entity\SiteLanguage;
|
||||
|
||||
/**
|
||||
* Data Transfer Object representing language availability information for a specific page.
|
||||
* Contains both existing translations and potential new translations.
|
||||
*
|
||||
* This provides a single source of truth for:
|
||||
* - Which languages are configured and available
|
||||
* - Which languages have translations on this page
|
||||
* - Which languages can be created (permissions)
|
||||
* - Translation records with workspace overlay applied
|
||||
* - UI-ready language items for display
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final readonly class PageLanguageInformation
|
||||
{
|
||||
/**
|
||||
* @param int $pageId Page ID this information belongs to
|
||||
* @param SiteLanguage[] $availableLanguages All available languages
|
||||
* @param array<int, LanguageStatus> $languageStatuses Status for each language (existing/creatable/unavailable)
|
||||
* @param array<int, array> $existingTranslations Raw page translation records, keyed by language ID
|
||||
* @param int[] $creatableLanguageIds IDs of languages that can be created
|
||||
* @param bool $canUserCreateTranslations Whether user has permission to create translations
|
||||
* @param LanguageItem[] $languageItems UI-ready language items
|
||||
*/
|
||||
public function __construct(
|
||||
public int $pageId,
|
||||
public array $availableLanguages,
|
||||
public array $languageStatuses,
|
||||
public array $existingTranslations,
|
||||
public array $creatableLanguageIds,
|
||||
public bool $canUserCreateTranslations,
|
||||
public array $languageItems,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Check if a translation exists for a specific language.
|
||||
*/
|
||||
public function hasTranslation(int $languageId): bool
|
||||
{
|
||||
return array_key_exists($languageId, $this->existingTranslations);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a translation can be created for a specific language.
|
||||
*/
|
||||
public function canCreateTranslation(int $languageId): bool
|
||||
{
|
||||
return in_array($languageId, $this->creatableLanguageIds, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translation record for a specific language.
|
||||
*
|
||||
* @return array|null Translation record or null if not found
|
||||
*/
|
||||
public function getTranslationRecord(int $languageId): ?array
|
||||
{
|
||||
return $this->existingTranslations[$languageId] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the status of a specific language.
|
||||
*/
|
||||
public function getLanguageStatus(int $languageId): LanguageStatus
|
||||
{
|
||||
return $this->languageStatuses[$languageId] ?? LanguageStatus::Unavailable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all language IDs including default (0) and all translations.
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function getAllExistingLanguageIds(): array
|
||||
{
|
||||
return array_merge([0], array_keys($this->existingTranslations));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user