Initial commit - Typo3 11.5.41
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTYPO3\TtAddress\Hooks\Tca;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
use TYPO3\CMS\Core\Localization\LanguageService;
|
||||
|
||||
/**
|
||||
* Class AddFieldsToSelector
|
||||
*/
|
||||
class AddFieldsToSelector
|
||||
{
|
||||
/** @var LanguageService */
|
||||
protected $languageService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->languageService = $GLOBALS['LANG'];
|
||||
}
|
||||
|
||||
// TODO consolidate with list in pi1
|
||||
const sortFields = ['gender', 'name', 'first_name', 'middle_name', 'last_name', 'title', 'company', 'address', 'building', 'room', 'birthday', 'zip', 'city', 'region', 'country', 'email', 'www', 'phone', 'mobile', 'fax'];
|
||||
|
||||
/**
|
||||
* Manipulating the input array, $params, adding new selectorbox items.
|
||||
*
|
||||
* @param array $params array of select field options (reference)
|
||||
*/
|
||||
public function main(array &$params)
|
||||
{
|
||||
$selectOptions = [];
|
||||
foreach (self::sortFields as $field) {
|
||||
$label = $this->languageService->sL($GLOBALS['TCA']['tt_address']['columns'][$field]['label']);
|
||||
$label = rtrim($label, ':');
|
||||
|
||||
$selectOptions[] = [
|
||||
'field' => $field,
|
||||
'label' => $label
|
||||
];
|
||||
}
|
||||
|
||||
// add sorting by order of single selection
|
||||
$selectOptions[] = [
|
||||
'field' => 'singleSelection',
|
||||
'label' => $this->languageService->sL('LLL:EXT:tt_address/Resources/Private/Language/ff/locallang_ff.xlf:pi1_flexform.sortBy.singleSelection')
|
||||
];
|
||||
|
||||
// sort by labels
|
||||
$labels = [];
|
||||
foreach ($selectOptions as $key => $v) {
|
||||
$labels[$key] = $v['label'];
|
||||
}
|
||||
$labels = array_map('strtolower', $labels);
|
||||
array_multisort($labels, SORT_ASC, $selectOptions);
|
||||
|
||||
// add fields to <select>
|
||||
foreach ($selectOptions as $option) {
|
||||
$params['items'][] = [
|
||||
$option['label'],
|
||||
$option['field']
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
76
typo3conf/ext/tt_address/Classes/Hooks/Tca/Label.php
Normal file
76
typo3conf/ext/tt_address/Classes/Hooks/Tca/Label.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FriendsOfTYPO3\TtAddress\Hooks\Tca;
|
||||
|
||||
/**
|
||||
* This file is part of the "tt_address" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Backend\Utility\BackendUtility;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
/**
|
||||
* Dynamic label of the address record based on tsconfig
|
||||
*/
|
||||
class Label
|
||||
{
|
||||
private const FALLBACK = [
|
||||
['last_name', 'first_name'],
|
||||
['email'],
|
||||
];
|
||||
|
||||
public function getAddressLabel(array &$params): void
|
||||
{
|
||||
if (!($params['row']['pid'] ?? 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_numeric($params['row']['uid'])) {
|
||||
$row = BackendUtility::getRecordWSOL('tt_address', (int) $params['row']['uid']);
|
||||
} else {
|
||||
$row = $params['row'];
|
||||
}
|
||||
|
||||
// record might be in deleting process
|
||||
if (!$row) {
|
||||
return;
|
||||
}
|
||||
|
||||
$configuration = $this->getConfiguration((int) $row['pid']);
|
||||
if (!$configuration) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($configuration as $fieldList) {
|
||||
$label = [];
|
||||
foreach ($fieldList as $field) {
|
||||
if (isset($row['uid'], $row[$field]) && !empty($row[$field])) {
|
||||
$label[] = BackendUtility::getProcessedValue('tt_address', $field, $row[$field], 0, false, 0, $row['uid']);
|
||||
}
|
||||
}
|
||||
if (!empty($label)) {
|
||||
$params['title'] = implode(', ', $label);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function getConfiguration(int $pid): array
|
||||
{
|
||||
$labelConfiguration = BackendUtility::getPagesTSconfig($pid)['tt_address.']['label'] ?? '';
|
||||
if (!$labelConfiguration) {
|
||||
return self::FALLBACK;
|
||||
}
|
||||
|
||||
$configuration = [];
|
||||
$options = GeneralUtility::trimExplode(';', $labelConfiguration, true);
|
||||
foreach ($options as $option) {
|
||||
$configuration[] = GeneralUtility::trimExplode(',', $option, true);
|
||||
}
|
||||
return $configuration;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user