Commit e1c1e8a8 authored by Kevin Ditscheid's avatar Kevin Ditscheid

[BUGFIX] Fix broken languagevisibility user field

parent 3b82464b
......@@ -27,6 +27,7 @@ namespace TYPO3\Languagevisibility\UserFunction;
use Doctrine\DBAL\DBALException;
use Exception;
use TYPO3\CMS\Backend\Form\Element\AbstractFormElement;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Imaging\Icon;
......@@ -44,7 +45,7 @@ use TYPO3\Languagevisibility\Service\VisibilityService;
/**
* User Functions for the use inside the TCA
*/
class FieldVisibilityUserFunction {
class FieldVisibilityUserFunction extends AbstractFormElement {
/**
* @var bool
......@@ -57,25 +58,21 @@ class FieldVisibilityUserFunction {
private $modTSconfig = [];
/**
* Renders the language table for the given record
*
* @param array $PA row data
* @return string
* @noinspection PhpUnused
* @throws DBALException
* @return array
*/
public function user_fieldvisibility($PA): string {
public function render() {
$result = $this->initializeResultArray();
$content = '';
//init some class attributes
$pageId = $PA['row']['pid'];
$uid = $PA['row']['uid'];
$pageId = $this->data['databaseRow']['pid'];
$uid = $this->data['databaseRow']['uid'];
if (strpos($uid, 'NEW') === 0) {
$this->isNewElement = TRUE;
}
if ($PA['table'] === 'pages' && !$this->isNewElement) {
$pageId = $PA['row']['uid'];
if ($this->data['tableName'] === 'pages' && !$this->isNewElement) {
$pageId = $this->data['databaseRow']['uid'];
}
/** @var BackendUserAuthentication $backendUser */
......@@ -85,24 +82,26 @@ class FieldVisibilityUserFunction {
$elementfactory = GeneralUtility::makeInstance(ElementFactory::class);
$value = $PA['row'][$PA['field']];
$table = $PA['table'];
$isOverlay = BackendServices::isOverlayRecord($PA['row'], $table);
$value = $this->data['databaseRow'][$this->data['fieldName']];
$table = $this->data['tableName'];
$isOverlay = BackendServices::isOverlayRecord($this->data['databaseRow'], $table);
$PA['row'][$GLOBALS['TCA'][$table]['ctrl']['languageField']] = (int) $PA['row'][$GLOBALS['TCA'][$table]['ctrl']['languageField']][0];
$PA['row'][$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] = (int) $PA['row'][$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']][0];
$this->data['databaseRow'][$GLOBALS['TCA'][$table]['ctrl']['languageField']] = (int) $this->data['databaseRow'][$GLOBALS['TCA'][$table]['ctrl']['languageField']][0];
$this->data['databaseRow'][$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] = (int) $this->data['databaseRow'][$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']][0];
try {
//This element is an original element (no overlay)
/** @var Element $originalElement */
$originalElement = $elementfactory->getElementForTable($table, $PA['row']);
$originalElement = $elementfactory->getElementForTable($table, $this->data['databaseRow']);
} catch (Exception $exception) {
return '<div class="alert alert-danger">' .
$result['html'] = '<div class="alert alert-danger">' .
$this->getLLL('backend.error.elementNotSupported') . '</div>';
return $result;
}
if ($originalElement->isMonolithicTranslated()) {
return $content;
$result['html'] = $content;
return $result;
}
$siteFinder = GeneralUtility::makeInstance(SiteFinder::class);
......@@ -110,25 +109,41 @@ class FieldVisibilityUserFunction {
try {
$site = $siteFinder->getSiteByPageId($pageId);
} catch (\Exception $e) {
return '<div class="alert alert-danger">' .
$result['html'] = '<div class="alert alert-danger">' .
$this->getLLL('backend.error.siteNotFound') . '</div>';
return $result;
}
$languageList = $site->getAvailableLanguages($backendUser);
$infosStruct = $this->_getLanguageInfoStructurListForElementAndLanguageList(
$originalElement, $languageList, $PA['itemFormElName'], FALSE
$originalElement, $languageList, $this->data['parameterArray']['itemFormElName'], FALSE
);
if (count($infosStruct) <= 0) {
return '';
$result['html'] = '';
return $result;
}
$legend = '<div><br />' . LocalizationUtility::translate('backend.visibilityLegend', 'languagevisibility') .
'</div>';
$content .= $this->renderLanguageInfos($infosStruct, $table === 'pages', $isOverlay);
return '<div id="fieldvisibility">' . $content . $legend . '</div>' . $this->_javascript();
$result['html'] = '<div id="fieldvisibility">' . $content . $legend . '</div>' . $this->_javascript();
return $result;
}
/**
* Renders the language table for the given record
*
* @param array $PA row data
* @return string
* @noinspection PhpUnused
* @throws DBALException
*/
public function user_fieldvisibility($PA): string {
}
/**
......
......@@ -38,11 +38,7 @@ call_user_func(
'label' => 'LLL:EXT:' . $extKey . '/Resources/Private/Language/locallang_db.xlf:pages.tx_languagevisibility_visibility',
'config' => [
'type' => 'user',
'size' => '30',
'userFunc' => 'TYPO3\Languagevisibility\UserFunction\FieldVisibilityUserFunction->user_fieldvisibility',
'default' => '',
'foreign_table' => 'tx_languagevisibility_visibility_flag',
'foreign_field' => 'record_uid',
'renderType' => 'languageVisibility'
]
],
];
......
......@@ -39,11 +39,7 @@ call_user_func(
'label' => 'LLL:EXT:' . $extKey . '/Resources/Private/Language/locallang_db.xlf:pages.tx_languagevisibility_visibility',
'config' => [
'type' => 'user',
'size' => '30',
'userFunc' => 'TYPO3\Languagevisibility\UserFunction\FieldVisibilityUserFunction->user_fieldvisibility',
'default' => '',
'foreign_table' => 'tx_languagevisibility_visibility_flag',
'foreign_field' => 'record_uid',
'renderType' => 'languageVisibility'
]
]
];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment