Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
TYPO3
languagevisibility
Commits
f17c7b9b
Commit
f17c7b9b
authored
Jun 16, 2020
by
Fabio Stegmeyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[TASK] Copy and move visibility flags when copying or moving records
parent
ebee2ee6
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
108 additions
and
11 deletions
+108
-11
Classes/Hook/TceMainHook.php
Classes/Hook/TceMainHook.php
+69
-6
Classes/Repository/VisibilityFlagRepository.php
Classes/Repository/VisibilityFlagRepository.php
+32
-0
Configuration/TCA/tx_languagevisibility_visibility_flag.php
Configuration/TCA/tx_languagevisibility_visibility_flag.php
+4
-4
ext_localconf.php
ext_localconf.php
+3
-0
ext_tables.sql
ext_tables.sql
+0
-1
No files found.
Classes/Hook/TceMainHook.php
View file @
f17c7b9b
...
...
@@ -57,11 +57,8 @@ class TceMainHook {
public
function
processCmdmap_postProcess
(
$command
,
$table
,
$identity
,
$value
,
$dataHandler
,
$pasteUpdate
,
$pasteDatamap
)
{
if
(
$table
!==
'pages'
)
{
return
;
}
if
(
$command
===
'copy'
)
{
if
(
$command
===
'copy'
&&
$table
===
'pages'
)
{
$originalPageId
=
(
int
)
$identity
;
if
(
$originalPageId
<=
0
)
{
return
;
...
...
@@ -80,6 +77,71 @@ class TceMainHook {
}
elseif
(
$command
===
'move'
)
{
$this
->
copyLanguageVisibilityFlagsFromParentPage
(
$identity
);
}
if
(
$command
===
'copy'
&&
$table
!==
'pages'
&&
in_array
(
$table
,
VisibilityService
::
getSupportedTables
(),
TRUE
))
{
$oldId
=
$identity
;
$newId
=
$dataHandler
->
copyMappingArray
[
$table
][
$identity
];
$languageRep
=
GeneralUtility
::
makeInstance
(
LanguageRepository
::
class
);
$visibilityFlagRepository
=
GeneralUtility
::
makeInstance
(
VisibilityFlagRepository
::
class
);
$availableLanguages
=
$languageRep
->
getLanguages
();
$visibilityFlags
=
[];
foreach
(
$availableLanguages
as
$language
)
{
$lid
=
$language
->
getUid
();
$visibilityFlag
=
$visibilityFlagRepository
->
getVisibilityFlag
(
$table
,
$oldId
,
$lid
);
if
(
$visibilityFlag
!==
FALSE
&&
$visibilityFlag
!==
NULL
)
{
$visibilityFlags
[
$lid
]
=
$visibilityFlag
[
'flag'
];
}
}
foreach
(
$visibilityFlags
as
$lid
=>
$flag
)
{
$visibilityFlagRepository
->
setVisibilityFlag
(
$flag
,
$table
,
$newId
,
$lid
);
}
}
}
/**
* Changes the pid of the visibility flags of a moved record
*
* @param $table
* @param $uid
* @param $destPid
* @param $propArr
* @param $moveRec
* @param $resolvedPid
* @param $recordWasMoved
* @param $dataHandler
*/
public
function
moveRecord
(
$table
,
$uid
,
$destPid
,
$propArr
,
$moveRec
,
$resolvedPid
,
$recordWasMoved
,
$dataHandler
)
{
if
(
$table
!==
'pages'
&&
in_array
(
$table
,
VisibilityService
::
getSupportedTables
(),
TRUE
))
{
$languageRep
=
GeneralUtility
::
makeInstance
(
LanguageRepository
::
class
);
$visibilityFlagRepository
=
GeneralUtility
::
makeInstance
(
VisibilityFlagRepository
::
class
);
$availableLanguages
=
$languageRep
->
getLanguages
();
foreach
(
$availableLanguages
as
$language
)
{
$lid
=
$language
->
getUid
();
$visibilityFlag
=
$visibilityFlagRepository
->
getVisibilityFlag
(
$table
,
$uid
,
$lid
);
if
(
$visibilityFlag
!==
FALSE
&&
$visibilityFlag
!==
NULL
)
{
$flagUid
=
$visibilityFlag
[
'uid'
];
$visibilityFlagRepository
->
moveVisibilityFlag
(
$flagUid
,
$resolvedPid
);
}
}
}
}
/**
...
...
@@ -130,6 +192,7 @@ class TceMainHook {
$queryBuilder
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getQueryBuilderForTable
(
'tx_languagevisibility_visibility_flag'
);
$queryBuilder
->
insert
(
'tx_languagevisibility_visibility_flag'
)
->
values
(
...
...
@@ -247,8 +310,8 @@ class TceMainHook {
// flush all caches
CacheManager
::
getInstance
()
->
flushAllCaches
();
//todo: uncomment
//GeneralUtility::makeInstance(VisibilityFlagRepository::class)
->deleteDefaultFlags();
GeneralUtility
::
makeInstance
(
VisibilityFlagRepository
::
class
)
->
deleteDefaultFlags
();
// Flush TYPO3 Caching Framework caches
GeneralUtility
::
makeInstance
(
\
TYPO3\CMS\Core\Cache\CacheManager
::
class
)
...
...
Classes/Repository/VisibilityFlagRepository.php
View file @
f17c7b9b
...
...
@@ -29,6 +29,7 @@ use TYPO3\CMS\Core\Database\ConnectionPool;
use
TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\Languagevisibility\Manager\CacheManager
;
use
TYPO3\CMS\Backend\Utility\BackendUtility
;
/**
* @author Fabio Stegmeyer <fabio.stegmeyer@sgalinski.de>
...
...
@@ -58,6 +59,16 @@ class VisibilityFlagRepository {
self
::
DB_TABLE
);
if
(
$table
===
'pages'
)
{
$pid
=
$recordUid
;
}
else
{
$record
=
BackendUtility
::
getRecord
(
$table
,
$recordUid
,
$fields
=
'pid'
);
if
(
!
is_null
(
$record
))
{
$pid
=
$record
[
'pid'
];
}
}
if
(
!
is_null
(
$existingVisibilityFlag
))
{
//flag already exists and only needs to changed
$uid
=
(
int
)
$existingVisibilityFlag
[
'uid'
];
...
...
@@ -74,16 +85,37 @@ class VisibilityFlagRepository {
->
insert
(
self
::
DB_TABLE
)
->
values
(
[
'pid'
=>
$pid
,
'flag'
=>
$flag
,
'record_table'
=>
$table
,
'record_uid'
=>
$table
.
'_'
.
$recordUid
,
'record_language_uid'
=>
$lUid
,
'tstamp'
=>
time
(),
'crdate'
=>
time
(),
'cruser_id'
=>
$GLOBALS
[
'BE_USER'
]
->
user
[
'uid'
],
]
)
->
execute
();
}
}
/**
* @param $uid
* @param $destPid
* @return void
*/
public
function
moveVisibilityFlag
(
$uid
,
$destPid
):
void
{
$queryBuilder
=
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getQueryBuilderForTable
(
self
::
DB_TABLE
);
$queryBuilder
->
update
(
self
::
DB_TABLE
)
->
where
(
$queryBuilder
->
expr
()
->
eq
(
'uid'
,
$uid
))
->
set
(
'pid'
,
$destPid
)
->
execute
();
}
/**
* Returns a complete flag row or NULL if none is found
*
...
...
Configuration/TCA/tx_languagevisibility_visibility_flag.php
View file @
f17c7b9b
...
...
@@ -24,11 +24,11 @@ return [
'config'
=>
[
'type'
=>
'group'
,
'internal_type'
=>
'db'
,
'allowed'
=>
implode
(
','
,
VisibilityService
::
getSupportedTables
()),
'allowed'
=>
implode
(
','
,
VisibilityService
::
getSupportedTables
()),
'foreign_table'
=>
'tt_content'
,
//
'maxitems' => 1,
//
'minitems' => 0,
//
'size' => 1,
'maxitems'
=>
1
,
'minitems'
=>
0
,
'size'
=>
1
,
'default'
=>
0
,
]
],
...
...
ext_localconf.php
View file @
f17c7b9b
...
...
@@ -33,6 +33,9 @@ call_user_func(
$GLOBALS
[
'TYPO3_CONF_VARS'
][
'SC_OPTIONS'
][
'GLOBAL'
][
'extTablesInclusion-PostProcessing'
][
$extKey
]
=
\
TYPO3\Languagevisibility\Hook\TcaHook
::
class
;
$GLOBALS
[
'TYPO3_CONF_VARS'
][
'SC_OPTIONS'
][
't3lib/class.t3lib_tcemain.php'
][
'moveRecordClass'
][
$extKey
]
=
\
TYPO3\Languagevisibility\Hook\TceMainHook
::
class
;
// overriding option because this is done by languagevisibility and will not work if set
$GLOBALS
[
'TYPO3_CONF_VARS'
][
'FE'
][
'hidePagesIfNotTranslatedByDefault'
]
=
0
;
...
...
ext_tables.sql
View file @
f17c7b9b
...
...
@@ -38,6 +38,5 @@ CREATE TABLE tx_languagevisibility_visibility_flag (
record_uid
text
DEFAULT
''
NOT
NULL
,
record_language_uid
int
(
11
)
DEFAULT
'0'
NOT
NULL
,
flag
text
NOT
NULL
,
default_language_record_uid
int
(
11
)
DEFAULT
'0'
NOT
NULL
,
PRIMARY
KEY
(
uid
)
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment