@@ -2,55 +2,55 @@ |
||
| 2 | 2 | if (!defined('TYPO3_MODE')) die ('Access denied.'); |
| 3 | 3 | |
| 4 | 4 | $tca = [ |
| 5 | - 'grid' => [ |
|
| 6 | - 'facets' => [ |
|
| 7 | - 'uid', |
|
| 8 | - 'title', |
|
| 9 | - 'description', |
|
| 10 | - ], |
|
| 11 | - 'vidi' => [ |
|
| 12 | - // Special case when the field name does not follow the conventions. |
|
| 13 | - // Vidi needs a bit of help to find the equivalence fieldName <-> propertyName. |
|
| 14 | - 'mappings' => [ |
|
| 15 | - 'lockToDomain' => 'lockToDomain', |
|
| 16 | - 'TSconfig' => 'tsConfig', |
|
| 17 | - 'felogin_redirectPid' => 'feLoginRedirectPid', |
|
| 18 | - ], |
|
| 19 | - ], |
|
| 20 | - 'columns' => [ |
|
| 21 | - '__checkbox' => [ |
|
| 22 | - 'renderer' => new \Fab\Vidi\Grid\CheckBoxRenderer(), |
|
| 23 | - ], |
|
| 24 | - 'uid' => [ |
|
| 25 | - 'visible' => false, |
|
| 26 | - 'label' => 'Id', |
|
| 27 | - 'width' => '5px', |
|
| 28 | - ], |
|
| 29 | - 'title' => [ |
|
| 30 | - 'visible' => true, |
|
| 31 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_groups.xlf:title', |
|
| 32 | - 'editable' => true, |
|
| 33 | - ], |
|
| 34 | - 'tstamp' => [ |
|
| 35 | - 'visible' => false, |
|
| 36 | - 'format' => 'Fab\Vidi\Formatter\Date', |
|
| 37 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:tstamp', |
|
| 38 | - ], |
|
| 39 | - 'crdate' => [ |
|
| 40 | - 'visible' => false, |
|
| 41 | - 'format' => 'Fab\Vidi\Formatter\Date', |
|
| 42 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:crdate', |
|
| 43 | - ], |
|
| 44 | - 'hidden' => [ |
|
| 45 | - 'renderer' => 'Fab\Vidi\Grid\VisibilityRenderer', |
|
| 46 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:visibility_abbreviation', |
|
| 47 | - 'width' => '3%', |
|
| 48 | - ], |
|
| 49 | - '__buttons' => [ |
|
| 50 | - 'renderer' => new \Fab\Vidi\Grid\ButtonGroupRenderer(), |
|
| 51 | - ], |
|
| 52 | - ] |
|
| 53 | - ] |
|
| 5 | + 'grid' => [ |
|
| 6 | + 'facets' => [ |
|
| 7 | + 'uid', |
|
| 8 | + 'title', |
|
| 9 | + 'description', |
|
| 10 | + ], |
|
| 11 | + 'vidi' => [ |
|
| 12 | + // Special case when the field name does not follow the conventions. |
|
| 13 | + // Vidi needs a bit of help to find the equivalence fieldName <-> propertyName. |
|
| 14 | + 'mappings' => [ |
|
| 15 | + 'lockToDomain' => 'lockToDomain', |
|
| 16 | + 'TSconfig' => 'tsConfig', |
|
| 17 | + 'felogin_redirectPid' => 'feLoginRedirectPid', |
|
| 18 | + ], |
|
| 19 | + ], |
|
| 20 | + 'columns' => [ |
|
| 21 | + '__checkbox' => [ |
|
| 22 | + 'renderer' => new \Fab\Vidi\Grid\CheckBoxRenderer(), |
|
| 23 | + ], |
|
| 24 | + 'uid' => [ |
|
| 25 | + 'visible' => false, |
|
| 26 | + 'label' => 'Id', |
|
| 27 | + 'width' => '5px', |
|
| 28 | + ], |
|
| 29 | + 'title' => [ |
|
| 30 | + 'visible' => true, |
|
| 31 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_groups.xlf:title', |
|
| 32 | + 'editable' => true, |
|
| 33 | + ], |
|
| 34 | + 'tstamp' => [ |
|
| 35 | + 'visible' => false, |
|
| 36 | + 'format' => 'Fab\Vidi\Formatter\Date', |
|
| 37 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:tstamp', |
|
| 38 | + ], |
|
| 39 | + 'crdate' => [ |
|
| 40 | + 'visible' => false, |
|
| 41 | + 'format' => 'Fab\Vidi\Formatter\Date', |
|
| 42 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:crdate', |
|
| 43 | + ], |
|
| 44 | + 'hidden' => [ |
|
| 45 | + 'renderer' => 'Fab\Vidi\Grid\VisibilityRenderer', |
|
| 46 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:visibility_abbreviation', |
|
| 47 | + 'width' => '3%', |
|
| 48 | + ], |
|
| 49 | + '__buttons' => [ |
|
| 50 | + 'renderer' => new \Fab\Vidi\Grid\ButtonGroupRenderer(), |
|
| 51 | + ], |
|
| 52 | + ] |
|
| 53 | + ] |
|
| 54 | 54 | ]; |
| 55 | 55 | |
| 56 | 56 | \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TCA']['fe_groups'], $tca); |
| 57 | 57 | \ No newline at end of file |
@@ -2,8 +2,8 @@ discard block |
||
| 2 | 2 | if (!defined('TYPO3_MODE')) die ('Access denied.'); |
| 3 | 3 | |
| 4 | 4 | $tca = [ |
| 5 | - 'grid' => [ |
|
| 6 | - 'excluded_fields' => 'image, imagewidth, imageorient, imagecols, imageborder, image_noRows, image_effects, image_compression, tx_impexp_origuid, image_zoom, |
|
| 5 | + 'grid' => [ |
|
| 6 | + 'excluded_fields' => 'image, imagewidth, imageorient, imagecols, imageborder, image_noRows, image_effects, image_compression, tx_impexp_origuid, image_zoom, |
|
| 7 | 7 | spaceAfter, spaceBefore, |
| 8 | 8 | uploads_description, uploads_type, |
| 9 | 9 | media, assets, table_caption, table_delimiter, table_enclosure, table_header_position, table_tfoot, table_bgColor, table_border, table_cellpadding, table_cellspacing, |
@@ -13,39 +13,39 @@ discard block |
||
| 13 | 13 | target, linkToTop, menu_type, list_type, select_key, |
| 14 | 14 | file_collections, filelink_size, filelink_sorting, |
| 15 | 15 | external_media_ratio, external_media_source', |
| 16 | - 'columns' => [ |
|
| 17 | - '__checkbox' => [ |
|
| 18 | - 'renderer' => new Fab\Vidi\Grid\CheckBoxRenderer(), |
|
| 19 | - ], |
|
| 20 | - 'uid' => [ |
|
| 21 | - 'visible' => false, |
|
| 22 | - 'label' => 'Id', |
|
| 23 | - 'width' => '5px', |
|
| 24 | - ], |
|
| 25 | - 'header' => [ |
|
| 26 | - 'editable' => true, |
|
| 27 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/tt_content.xlf:header', |
|
| 28 | - ], |
|
| 29 | - 'tstamp' => [ |
|
| 30 | - 'visible' => false, |
|
| 31 | - 'format' => 'Fab\Vidi\Formatter\Date', |
|
| 32 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:tstamp', |
|
| 33 | - ], |
|
| 34 | - 'crdate' => [ |
|
| 35 | - 'visible' => false, |
|
| 36 | - 'format' => 'Fab\Vidi\Formatter\Date', |
|
| 37 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:crdate', |
|
| 38 | - ], |
|
| 39 | - 'hidden' => [ |
|
| 40 | - 'renderer' => 'Fab\Vidi\Grid\VisibilityRenderer', |
|
| 41 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active', |
|
| 42 | - 'width' => '3%', |
|
| 43 | - ], |
|
| 44 | - '__buttons' => [ |
|
| 45 | - 'renderer' => new Fab\Vidi\Grid\ButtonGroupRenderer(), |
|
| 46 | - ], |
|
| 47 | - ], |
|
| 48 | - ], |
|
| 16 | + 'columns' => [ |
|
| 17 | + '__checkbox' => [ |
|
| 18 | + 'renderer' => new Fab\Vidi\Grid\CheckBoxRenderer(), |
|
| 19 | + ], |
|
| 20 | + 'uid' => [ |
|
| 21 | + 'visible' => false, |
|
| 22 | + 'label' => 'Id', |
|
| 23 | + 'width' => '5px', |
|
| 24 | + ], |
|
| 25 | + 'header' => [ |
|
| 26 | + 'editable' => true, |
|
| 27 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/tt_content.xlf:header', |
|
| 28 | + ], |
|
| 29 | + 'tstamp' => [ |
|
| 30 | + 'visible' => false, |
|
| 31 | + 'format' => 'Fab\Vidi\Formatter\Date', |
|
| 32 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:tstamp', |
|
| 33 | + ], |
|
| 34 | + 'crdate' => [ |
|
| 35 | + 'visible' => false, |
|
| 36 | + 'format' => 'Fab\Vidi\Formatter\Date', |
|
| 37 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:crdate', |
|
| 38 | + ], |
|
| 39 | + 'hidden' => [ |
|
| 40 | + 'renderer' => 'Fab\Vidi\Grid\VisibilityRenderer', |
|
| 41 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active', |
|
| 42 | + 'width' => '3%', |
|
| 43 | + ], |
|
| 44 | + '__buttons' => [ |
|
| 45 | + 'renderer' => new Fab\Vidi\Grid\ButtonGroupRenderer(), |
|
| 46 | + ], |
|
| 47 | + ], |
|
| 48 | + ], |
|
| 49 | 49 | ]; |
| 50 | 50 | |
| 51 | 51 | \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TCA']['tt_content'], $tca); |
@@ -2,107 +2,107 @@ |
||
| 2 | 2 | if (!defined('TYPO3_MODE')) die ('Access denied.'); |
| 3 | 3 | |
| 4 | 4 | $tca = [ |
| 5 | - 'ctrl' => [ |
|
| 6 | - // By default "searchFields" has many fields which has a performance cost when dealing with large data-set. |
|
| 7 | - // Override search field for performance reason. |
|
| 8 | - // To restore default values, just replace with this: $GLOBALS['TCA']['fe_users']['ctrl']['searchFields'] . ',usergroup', |
|
| 9 | - 'searchFields' => 'username, first_name, last_name, usergroup', |
|
| 10 | - ], |
|
| 11 | - 'vidi' => [ |
|
| 12 | - // Special case when the field name does not follow the conventions. |
|
| 13 | - // Vidi needs a bit of help to find the equivalence fieldName <-> propertyName. |
|
| 14 | - 'mappings' => [ |
|
| 15 | - 'lockToDomain' => 'lockToDomain', |
|
| 16 | - 'TSconfig' => 'tsConfig', |
|
| 17 | - 'felogin_redirectPid' => 'feLoginRedirectPid', |
|
| 18 | - 'felogin_forgotHash' => 'feLoginForgotHash', |
|
| 19 | - ], |
|
| 20 | - ], |
|
| 21 | - 'grid' => [ |
|
| 22 | - 'excluded_fields' => 'lockToDomain, TSconfig, felogin_redirectPid, felogin_forgotHash, auth_token', |
|
| 23 | - 'export' => [ |
|
| 24 | - 'include_files' => false, |
|
| 25 | - ], |
|
| 26 | - 'facets' => [ |
|
| 27 | - 'uid', |
|
| 28 | - 'username', |
|
| 29 | - 'name', |
|
| 30 | - 'first_name', |
|
| 31 | - 'last_name', |
|
| 32 | - 'middle_name', |
|
| 33 | - 'address', |
|
| 34 | - 'telephone', |
|
| 35 | - 'fax', |
|
| 36 | - 'email', |
|
| 37 | - 'title', |
|
| 38 | - 'zip', |
|
| 39 | - 'city', |
|
| 40 | - 'country', |
|
| 41 | - 'company', |
|
| 42 | - 'usergroup', |
|
| 43 | - new \Fab\Vidi\Facet\StandardFacet( |
|
| 44 | - 'disable', |
|
| 45 | - 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active', |
|
| 46 | - [ |
|
| 47 | - '0' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active.0', |
|
| 48 | - '1' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active.1' |
|
| 49 | - ] |
|
| 50 | - ), |
|
| 51 | - ], |
|
| 52 | - 'columns' => [ |
|
| 53 | - '__checkbox' => [ |
|
| 54 | - 'renderer' => new Fab\Vidi\Grid\CheckBoxRenderer(), |
|
| 55 | - ], |
|
| 56 | - 'uid' => [ |
|
| 57 | - 'visible' => false, |
|
| 58 | - 'label' => 'Id', |
|
| 59 | - 'width' => '5px', |
|
| 60 | - ], |
|
| 61 | - 'username' => [ |
|
| 62 | - 'visible' => true, |
|
| 63 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf:username', |
|
| 64 | - 'editable' => true, |
|
| 65 | - ], |
|
| 66 | - 'name' => [ |
|
| 67 | - 'visible' => true, |
|
| 68 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf:name', |
|
| 69 | - 'editable' => true, |
|
| 70 | - ], |
|
| 71 | - 'email' => [ |
|
| 72 | - 'visible' => true, |
|
| 73 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf:email', |
|
| 74 | - 'editable' => true, |
|
| 75 | - ], |
|
| 76 | - 'usergroup' => [ |
|
| 77 | - 'visible' => true, |
|
| 78 | - 'renderers' => [ |
|
| 79 | - 'Fab\Vidi\Grid\RelationEditRenderer', |
|
| 80 | - 'Fab\Vidi\Grid\RelationRenderer', |
|
| 81 | - ], |
|
| 82 | - 'editable' => true, |
|
| 83 | - 'sortable' => false, |
|
| 84 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf:usergroup', |
|
| 85 | - ], |
|
| 86 | - 'tstamp' => [ |
|
| 87 | - 'visible' => false, |
|
| 88 | - 'format' => 'Fab\Vidi\Formatter\Date', |
|
| 89 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:tstamp', |
|
| 90 | - ], |
|
| 91 | - 'crdate' => [ |
|
| 92 | - 'visible' => false, |
|
| 93 | - 'format' => 'Fab\Vidi\Formatter\Date', |
|
| 94 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:crdate', |
|
| 95 | - ], |
|
| 96 | - 'disable' => [ |
|
| 97 | - 'renderer' => 'Fab\Vidi\Grid\VisibilityRenderer', |
|
| 98 | - 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active', |
|
| 99 | - 'width' => '3%', |
|
| 100 | - ], |
|
| 101 | - '__buttons' => [ |
|
| 102 | - 'renderer' => new Fab\Vidi\Grid\ButtonGroupRenderer(), |
|
| 103 | - ], |
|
| 104 | - ], |
|
| 105 | - ], |
|
| 5 | + 'ctrl' => [ |
|
| 6 | + // By default "searchFields" has many fields which has a performance cost when dealing with large data-set. |
|
| 7 | + // Override search field for performance reason. |
|
| 8 | + // To restore default values, just replace with this: $GLOBALS['TCA']['fe_users']['ctrl']['searchFields'] . ',usergroup', |
|
| 9 | + 'searchFields' => 'username, first_name, last_name, usergroup', |
|
| 10 | + ], |
|
| 11 | + 'vidi' => [ |
|
| 12 | + // Special case when the field name does not follow the conventions. |
|
| 13 | + // Vidi needs a bit of help to find the equivalence fieldName <-> propertyName. |
|
| 14 | + 'mappings' => [ |
|
| 15 | + 'lockToDomain' => 'lockToDomain', |
|
| 16 | + 'TSconfig' => 'tsConfig', |
|
| 17 | + 'felogin_redirectPid' => 'feLoginRedirectPid', |
|
| 18 | + 'felogin_forgotHash' => 'feLoginForgotHash', |
|
| 19 | + ], |
|
| 20 | + ], |
|
| 21 | + 'grid' => [ |
|
| 22 | + 'excluded_fields' => 'lockToDomain, TSconfig, felogin_redirectPid, felogin_forgotHash, auth_token', |
|
| 23 | + 'export' => [ |
|
| 24 | + 'include_files' => false, |
|
| 25 | + ], |
|
| 26 | + 'facets' => [ |
|
| 27 | + 'uid', |
|
| 28 | + 'username', |
|
| 29 | + 'name', |
|
| 30 | + 'first_name', |
|
| 31 | + 'last_name', |
|
| 32 | + 'middle_name', |
|
| 33 | + 'address', |
|
| 34 | + 'telephone', |
|
| 35 | + 'fax', |
|
| 36 | + 'email', |
|
| 37 | + 'title', |
|
| 38 | + 'zip', |
|
| 39 | + 'city', |
|
| 40 | + 'country', |
|
| 41 | + 'company', |
|
| 42 | + 'usergroup', |
|
| 43 | + new \Fab\Vidi\Facet\StandardFacet( |
|
| 44 | + 'disable', |
|
| 45 | + 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active', |
|
| 46 | + [ |
|
| 47 | + '0' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active.0', |
|
| 48 | + '1' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active.1' |
|
| 49 | + ] |
|
| 50 | + ), |
|
| 51 | + ], |
|
| 52 | + 'columns' => [ |
|
| 53 | + '__checkbox' => [ |
|
| 54 | + 'renderer' => new Fab\Vidi\Grid\CheckBoxRenderer(), |
|
| 55 | + ], |
|
| 56 | + 'uid' => [ |
|
| 57 | + 'visible' => false, |
|
| 58 | + 'label' => 'Id', |
|
| 59 | + 'width' => '5px', |
|
| 60 | + ], |
|
| 61 | + 'username' => [ |
|
| 62 | + 'visible' => true, |
|
| 63 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf:username', |
|
| 64 | + 'editable' => true, |
|
| 65 | + ], |
|
| 66 | + 'name' => [ |
|
| 67 | + 'visible' => true, |
|
| 68 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf:name', |
|
| 69 | + 'editable' => true, |
|
| 70 | + ], |
|
| 71 | + 'email' => [ |
|
| 72 | + 'visible' => true, |
|
| 73 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf:email', |
|
| 74 | + 'editable' => true, |
|
| 75 | + ], |
|
| 76 | + 'usergroup' => [ |
|
| 77 | + 'visible' => true, |
|
| 78 | + 'renderers' => [ |
|
| 79 | + 'Fab\Vidi\Grid\RelationEditRenderer', |
|
| 80 | + 'Fab\Vidi\Grid\RelationRenderer', |
|
| 81 | + ], |
|
| 82 | + 'editable' => true, |
|
| 83 | + 'sortable' => false, |
|
| 84 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf:usergroup', |
|
| 85 | + ], |
|
| 86 | + 'tstamp' => [ |
|
| 87 | + 'visible' => false, |
|
| 88 | + 'format' => 'Fab\Vidi\Formatter\Date', |
|
| 89 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:tstamp', |
|
| 90 | + ], |
|
| 91 | + 'crdate' => [ |
|
| 92 | + 'visible' => false, |
|
| 93 | + 'format' => 'Fab\Vidi\Formatter\Date', |
|
| 94 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:crdate', |
|
| 95 | + ], |
|
| 96 | + 'disable' => [ |
|
| 97 | + 'renderer' => 'Fab\Vidi\Grid\VisibilityRenderer', |
|
| 98 | + 'label' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active', |
|
| 99 | + 'width' => '3%', |
|
| 100 | + ], |
|
| 101 | + '__buttons' => [ |
|
| 102 | + 'renderer' => new Fab\Vidi\Grid\ButtonGroupRenderer(), |
|
| 103 | + ], |
|
| 104 | + ], |
|
| 105 | + ], |
|
| 106 | 106 | ]; |
| 107 | 107 | |
| 108 | 108 | \TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($GLOBALS['TCA']['fe_users'], $tca); |
@@ -1,171 +1,171 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if (!defined('TYPO3_MODE')) { |
| 4 | - die ('Access denied.'); |
|
| 4 | + die ('Access denied.'); |
|
| 5 | 5 | } |
| 6 | 6 | |
| 7 | 7 | // Check from Vidi configuration what default module should be loaded. |
| 8 | 8 | // Make sure the class exists to avoid a Runtime Error |
| 9 | 9 | if (TYPO3_MODE === 'BE') { |
| 10 | 10 | |
| 11 | - // Add content main module before 'user' |
|
| 12 | - if (!isset($GLOBALS['TBE_MODULES']['content'])) { |
|
| 13 | - |
|
| 14 | - // Position module "content" after module "user" manually. No API is available for that, it seems... |
|
| 15 | - $modules = []; |
|
| 16 | - foreach ($GLOBALS['TBE_MODULES'] as $key => $val) { |
|
| 17 | - if ($key === 'user') { |
|
| 18 | - $modules['content'] = ''; |
|
| 19 | - } |
|
| 20 | - $modules[$key] = $val; |
|
| 21 | - } |
|
| 22 | - $GLOBALS['TBE_MODULES'] = $modules; |
|
| 23 | - |
|
| 24 | - // Register "data management" module. |
|
| 25 | - \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule( |
|
| 26 | - 'content', |
|
| 27 | - '', |
|
| 28 | - '', |
|
| 29 | - '', |
|
| 30 | - [ |
|
| 31 | - 'name' => 'content', |
|
| 32 | - 'access' => 'user,group', |
|
| 33 | - 'labels' => [ |
|
| 34 | - 'll_ref' => 'LLL:EXT:vidi/Resources/Private/Language/content_module.xlf', |
|
| 35 | - ], |
|
| 36 | - ] |
|
| 37 | - ); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */ |
|
| 41 | - $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager'); |
|
| 42 | - |
|
| 43 | - /** @var \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility */ |
|
| 44 | - $configurationUtility = $objectManager->get('TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility'); |
|
| 45 | - $configuration = $configurationUtility->getCurrentConfiguration('vidi'); |
|
| 46 | - |
|
| 47 | - $pids = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $configuration['default_pid']['value'], true); |
|
| 48 | - $defaultPid = array_shift($pids); |
|
| 49 | - $defaultPids = []; |
|
| 50 | - foreach ($pids as $dataTypeAndPid) { |
|
| 51 | - $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(':', $dataTypeAndPid); |
|
| 52 | - if (count($parts) === 2) { |
|
| 53 | - $defaultPids[$parts[0]] = $parts[1]; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - // Loop around the data types and register them to be displayed within a BE module. |
|
| 58 | - if ($configuration['data_types']['value']) { |
|
| 59 | - |
|
| 60 | - $dataTypes = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $configuration['data_types']['value'], true); |
|
| 61 | - foreach ($dataTypes as $dataType) { |
|
| 62 | - |
|
| 63 | - /** @var \Fab\Vidi\Module\ModuleLoader $moduleLoader */ |
|
| 64 | - $moduleLoader = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Fab\Vidi\Module\ModuleLoader', $dataType); |
|
| 65 | - |
|
| 66 | - // Special case already defined in Vidi. |
|
| 67 | - if ($dataType === 'fe_users') { |
|
| 68 | - $languageFile = 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf'; |
|
| 69 | - $icon = 'EXT:core/Resources/Public/Icons/T3Icons/status/status-user-frontend.svg'; |
|
| 70 | - $icon = 'EXT:vidi/Resources/Public/Images/fe_users.png'; |
|
| 71 | - } elseif ($dataType === 'fe_groups') { |
|
| 72 | - $languageFile = 'LLL:EXT:vidi/Resources/Private/Language/fe_groups.xlf'; |
|
| 73 | - $icon = 'EXT:core/Resources/Public/Icons/T3Icons/status/status-user-group-frontend.svg'; |
|
| 74 | - $icon = 'EXT:vidi/Resources/Public/Images/fe_groups.png'; |
|
| 75 | - } else { |
|
| 76 | - /** @var \Fab\Vidi\Backend\LanguageFileGenerator $languageService */ |
|
| 77 | - $languageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Fab\Vidi\Backend\LanguageFileGenerator::class); |
|
| 78 | - $languageFile = $languageService->generate($dataType); |
|
| 79 | - $icon = ''; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - $pid = isset($defaultPids[$dataType]) ? $defaultPids[$dataType] : $defaultPid; |
|
| 83 | - |
|
| 84 | - /** @var \Fab\Vidi\Module\ModuleLoader $moduleLoader */ |
|
| 85 | - $moduleLoader->setIcon($icon) |
|
| 86 | - ->setModuleLanguageFile($languageFile) |
|
| 87 | - ->setDefaultPid($pid) |
|
| 88 | - ->register(); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - // Possible Static TS loading |
|
| 93 | - if (true === isset($configuration['autoload_typoscript']['value']) && false === (bool)$configuration['autoload_typoscript']['value']) { |
|
| 94 | - \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('vidi', 'Configuration/TypoScript', 'Vidi: versatile and interactive display'); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // Register List2 only if beta feature is enabled. |
|
| 98 | - // @todo let see what we do with that |
|
| 99 | - #if ($configuration['activate_beta_features']['value']) { |
|
| 100 | - # $labelFile = 'LLL:EXT:vidi/Resources/Private/Language/locallang_module.xlf'; |
|
| 101 | - # |
|
| 102 | - # if (!$configuration['hide_module_list']['value']) { |
|
| 103 | - # $labelFile = 'LLL:EXT:vidi/Resources/Private/Language/locallang_module_transitional.xlf'; |
|
| 104 | - # } |
|
| 105 | - # |
|
| 106 | - # \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule( |
|
| 107 | - # 'vidi', |
|
| 108 | - # 'web', // Make module a submodule of 'web' |
|
| 109 | - # 'm1', // Submodule key |
|
| 110 | - # 'after:list', // Position |
|
| 111 | - # array( |
|
| 112 | - # 'Content' => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard', |
|
| 113 | - # 'Tool' => 'welcome, work', |
|
| 114 | - # 'Facet' => 'autoSuggest, autoSuggests', |
|
| 115 | - # 'Selection' => 'edit, update, create, delete, list, show', |
|
| 116 | - # 'UserPreferences' => 'save', |
|
| 117 | - # 'Clipboard' => 'save, flush, show', |
|
| 118 | - # ), array( |
|
| 119 | - # 'access' => 'user,group', |
|
| 120 | - # 'icon' => 'EXT:vidi/Resources/Public/Images/list.png', |
|
| 121 | - # 'labels' => $labelFile, |
|
| 122 | - # ) |
|
| 123 | - # ); |
|
| 124 | - #} |
|
| 125 | - #if ($configuration['hide_module_list']['value']) { |
|
| 126 | - # |
|
| 127 | - # // Default User TSConfig to be added in any case. |
|
| 128 | - # TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig(' |
|
| 129 | - # |
|
| 130 | - # # Hide the module in the BE. |
|
| 131 | - # options.hideModules.web := addToList(list) |
|
| 132 | - # '); |
|
| 133 | - #} |
|
| 134 | - |
|
| 135 | - /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */ |
|
| 136 | - $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager'); |
|
| 137 | - |
|
| 138 | - /** @var $signalSlotDispatcher \TYPO3\CMS\Extbase\SignalSlot\Dispatcher */ |
|
| 139 | - $signalSlotDispatcher = $objectManager->get('TYPO3\CMS\Extbase\SignalSlot\Dispatcher'); |
|
| 140 | - |
|
| 141 | - // Connect "processContentData" signal slot with the "ContentObjectProcessor". |
|
| 142 | - $signalSlotDispatcher->connect( |
|
| 143 | - 'Fab\Vidi\Controller\Backend\ContentController', |
|
| 144 | - 'processContentData', |
|
| 145 | - 'Fab\Vidi\Processor\ContentObjectProcessor', |
|
| 146 | - 'processRelations', |
|
| 147 | - true |
|
| 148 | - ); |
|
| 149 | - |
|
| 150 | - // Connect "processContentData" signal with the "MarkerProcessor". |
|
| 151 | - $signalSlotDispatcher->connect( |
|
| 152 | - 'Fab\Vidi\Controller\Backend\ContentController', |
|
| 153 | - 'processContentData', |
|
| 154 | - 'Fab\Vidi\Processor\MarkerProcessor', |
|
| 155 | - 'processMarkers', |
|
| 156 | - true |
|
| 157 | - ); |
|
| 158 | - |
|
| 159 | - // Register default Tools for Vidi. |
|
| 160 | - \Fab\Vidi\Tool\ToolRegistry::getInstance()->register('*', 'Fab\Vidi\Tool\ModulePreferencesTool'); |
|
| 161 | - \Fab\Vidi\Tool\ToolRegistry::getInstance()->register('*', 'Fab\Vidi\Tool\RelationAnalyserTool'); |
|
| 11 | + // Add content main module before 'user' |
|
| 12 | + if (!isset($GLOBALS['TBE_MODULES']['content'])) { |
|
| 13 | + |
|
| 14 | + // Position module "content" after module "user" manually. No API is available for that, it seems... |
|
| 15 | + $modules = []; |
|
| 16 | + foreach ($GLOBALS['TBE_MODULES'] as $key => $val) { |
|
| 17 | + if ($key === 'user') { |
|
| 18 | + $modules['content'] = ''; |
|
| 19 | + } |
|
| 20 | + $modules[$key] = $val; |
|
| 21 | + } |
|
| 22 | + $GLOBALS['TBE_MODULES'] = $modules; |
|
| 23 | + |
|
| 24 | + // Register "data management" module. |
|
| 25 | + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addModule( |
|
| 26 | + 'content', |
|
| 27 | + '', |
|
| 28 | + '', |
|
| 29 | + '', |
|
| 30 | + [ |
|
| 31 | + 'name' => 'content', |
|
| 32 | + 'access' => 'user,group', |
|
| 33 | + 'labels' => [ |
|
| 34 | + 'll_ref' => 'LLL:EXT:vidi/Resources/Private/Language/content_module.xlf', |
|
| 35 | + ], |
|
| 36 | + ] |
|
| 37 | + ); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */ |
|
| 41 | + $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager'); |
|
| 42 | + |
|
| 43 | + /** @var \TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility $configurationUtility */ |
|
| 44 | + $configurationUtility = $objectManager->get('TYPO3\CMS\Extensionmanager\Utility\ConfigurationUtility'); |
|
| 45 | + $configuration = $configurationUtility->getCurrentConfiguration('vidi'); |
|
| 46 | + |
|
| 47 | + $pids = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $configuration['default_pid']['value'], true); |
|
| 48 | + $defaultPid = array_shift($pids); |
|
| 49 | + $defaultPids = []; |
|
| 50 | + foreach ($pids as $dataTypeAndPid) { |
|
| 51 | + $parts = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(':', $dataTypeAndPid); |
|
| 52 | + if (count($parts) === 2) { |
|
| 53 | + $defaultPids[$parts[0]] = $parts[1]; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + // Loop around the data types and register them to be displayed within a BE module. |
|
| 58 | + if ($configuration['data_types']['value']) { |
|
| 59 | + |
|
| 60 | + $dataTypes = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $configuration['data_types']['value'], true); |
|
| 61 | + foreach ($dataTypes as $dataType) { |
|
| 62 | + |
|
| 63 | + /** @var \Fab\Vidi\Module\ModuleLoader $moduleLoader */ |
|
| 64 | + $moduleLoader = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Fab\Vidi\Module\ModuleLoader', $dataType); |
|
| 65 | + |
|
| 66 | + // Special case already defined in Vidi. |
|
| 67 | + if ($dataType === 'fe_users') { |
|
| 68 | + $languageFile = 'LLL:EXT:vidi/Resources/Private/Language/fe_users.xlf'; |
|
| 69 | + $icon = 'EXT:core/Resources/Public/Icons/T3Icons/status/status-user-frontend.svg'; |
|
| 70 | + $icon = 'EXT:vidi/Resources/Public/Images/fe_users.png'; |
|
| 71 | + } elseif ($dataType === 'fe_groups') { |
|
| 72 | + $languageFile = 'LLL:EXT:vidi/Resources/Private/Language/fe_groups.xlf'; |
|
| 73 | + $icon = 'EXT:core/Resources/Public/Icons/T3Icons/status/status-user-group-frontend.svg'; |
|
| 74 | + $icon = 'EXT:vidi/Resources/Public/Images/fe_groups.png'; |
|
| 75 | + } else { |
|
| 76 | + /** @var \Fab\Vidi\Backend\LanguageFileGenerator $languageService */ |
|
| 77 | + $languageService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(Fab\Vidi\Backend\LanguageFileGenerator::class); |
|
| 78 | + $languageFile = $languageService->generate($dataType); |
|
| 79 | + $icon = ''; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + $pid = isset($defaultPids[$dataType]) ? $defaultPids[$dataType] : $defaultPid; |
|
| 83 | + |
|
| 84 | + /** @var \Fab\Vidi\Module\ModuleLoader $moduleLoader */ |
|
| 85 | + $moduleLoader->setIcon($icon) |
|
| 86 | + ->setModuleLanguageFile($languageFile) |
|
| 87 | + ->setDefaultPid($pid) |
|
| 88 | + ->register(); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + // Possible Static TS loading |
|
| 93 | + if (true === isset($configuration['autoload_typoscript']['value']) && false === (bool)$configuration['autoload_typoscript']['value']) { |
|
| 94 | + \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile('vidi', 'Configuration/TypoScript', 'Vidi: versatile and interactive display'); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // Register List2 only if beta feature is enabled. |
|
| 98 | + // @todo let see what we do with that |
|
| 99 | + #if ($configuration['activate_beta_features']['value']) { |
|
| 100 | + # $labelFile = 'LLL:EXT:vidi/Resources/Private/Language/locallang_module.xlf'; |
|
| 101 | + # |
|
| 102 | + # if (!$configuration['hide_module_list']['value']) { |
|
| 103 | + # $labelFile = 'LLL:EXT:vidi/Resources/Private/Language/locallang_module_transitional.xlf'; |
|
| 104 | + # } |
|
| 105 | + # |
|
| 106 | + # \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerModule( |
|
| 107 | + # 'vidi', |
|
| 108 | + # 'web', // Make module a submodule of 'web' |
|
| 109 | + # 'm1', // Submodule key |
|
| 110 | + # 'after:list', // Position |
|
| 111 | + # array( |
|
| 112 | + # 'Content' => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard', |
|
| 113 | + # 'Tool' => 'welcome, work', |
|
| 114 | + # 'Facet' => 'autoSuggest, autoSuggests', |
|
| 115 | + # 'Selection' => 'edit, update, create, delete, list, show', |
|
| 116 | + # 'UserPreferences' => 'save', |
|
| 117 | + # 'Clipboard' => 'save, flush, show', |
|
| 118 | + # ), array( |
|
| 119 | + # 'access' => 'user,group', |
|
| 120 | + # 'icon' => 'EXT:vidi/Resources/Public/Images/list.png', |
|
| 121 | + # 'labels' => $labelFile, |
|
| 122 | + # ) |
|
| 123 | + # ); |
|
| 124 | + #} |
|
| 125 | + #if ($configuration['hide_module_list']['value']) { |
|
| 126 | + # |
|
| 127 | + # // Default User TSConfig to be added in any case. |
|
| 128 | + # TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addUserTSConfig(' |
|
| 129 | + # |
|
| 130 | + # # Hide the module in the BE. |
|
| 131 | + # options.hideModules.web := addToList(list) |
|
| 132 | + # '); |
|
| 133 | + #} |
|
| 134 | + |
|
| 135 | + /** @var \TYPO3\CMS\Extbase\Object\ObjectManager $objectManager */ |
|
| 136 | + $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager'); |
|
| 137 | + |
|
| 138 | + /** @var $signalSlotDispatcher \TYPO3\CMS\Extbase\SignalSlot\Dispatcher */ |
|
| 139 | + $signalSlotDispatcher = $objectManager->get('TYPO3\CMS\Extbase\SignalSlot\Dispatcher'); |
|
| 140 | + |
|
| 141 | + // Connect "processContentData" signal slot with the "ContentObjectProcessor". |
|
| 142 | + $signalSlotDispatcher->connect( |
|
| 143 | + 'Fab\Vidi\Controller\Backend\ContentController', |
|
| 144 | + 'processContentData', |
|
| 145 | + 'Fab\Vidi\Processor\ContentObjectProcessor', |
|
| 146 | + 'processRelations', |
|
| 147 | + true |
|
| 148 | + ); |
|
| 149 | + |
|
| 150 | + // Connect "processContentData" signal with the "MarkerProcessor". |
|
| 151 | + $signalSlotDispatcher->connect( |
|
| 152 | + 'Fab\Vidi\Controller\Backend\ContentController', |
|
| 153 | + 'processContentData', |
|
| 154 | + 'Fab\Vidi\Processor\MarkerProcessor', |
|
| 155 | + 'processMarkers', |
|
| 156 | + true |
|
| 157 | + ); |
|
| 158 | + |
|
| 159 | + // Register default Tools for Vidi. |
|
| 160 | + \Fab\Vidi\Tool\ToolRegistry::getInstance()->register('*', 'Fab\Vidi\Tool\ModulePreferencesTool'); |
|
| 161 | + \Fab\Vidi\Tool\ToolRegistry::getInstance()->register('*', 'Fab\Vidi\Tool\RelationAnalyserTool'); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // Add new sprite icon. |
| 165 | 165 | \TYPO3\CMS\Backend\Sprite\SpriteManager::addSingleIcons( |
| 166 | - [ |
|
| 167 | - 'go' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('vidi') . 'Resources/Public/Images/bullet_go.png', |
|
| 168 | - 'query' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('vidi') . 'Resources/Public/Images/drive_disk.png', |
|
| 169 | - ], |
|
| 170 | - 'vidi' |
|
| 166 | + [ |
|
| 167 | + 'go' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('vidi') . 'Resources/Public/Images/bullet_go.png', |
|
| 168 | + 'query' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('vidi') . 'Resources/Public/Images/drive_disk.png', |
|
| 169 | + ], |
|
| 170 | + 'vidi' |
|
| 171 | 171 | ); |
| 172 | 172 | \ No newline at end of file |
@@ -19,113 +19,113 @@ |
||
| 19 | 19 | class FacetSuggestionService |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Retrieve possible suggestions for a field name |
|
| 24 | - * |
|
| 25 | - * @param string $fieldNameAndPath |
|
| 26 | - * @return array |
|
| 27 | - * @throws \Exception |
|
| 28 | - */ |
|
| 29 | - public function getSuggestions($fieldNameAndPath) |
|
| 30 | - { |
|
| 31 | - |
|
| 32 | - $values = []; |
|
| 33 | - |
|
| 34 | - $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath); |
|
| 35 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 36 | - |
|
| 37 | - if (Tca::grid()->facet($fieldNameAndPath)->hasSuggestions()) { |
|
| 38 | - $values = Tca::grid()->facet($fieldNameAndPath)->getSuggestions(); |
|
| 39 | - } else if (Tca::table($dataType)->hasField($fieldName)) { |
|
| 40 | - |
|
| 41 | - if (Tca::table($dataType)->field($fieldName)->hasRelation()) { |
|
| 42 | - |
|
| 43 | - // Fetch the adequate repository |
|
| 44 | - $foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable(); |
|
| 45 | - $contentRepository = ContentRepositoryFactory::getInstance($foreignTable); |
|
| 46 | - $table = Tca::table($foreignTable); |
|
| 47 | - |
|
| 48 | - // Initialize the matcher object. |
|
| 49 | - $matcher = MatcherObjectFactory::getInstance()->getMatcher([], $foreignTable); |
|
| 50 | - |
|
| 51 | - $numberOfValues = $contentRepository->countBy($matcher); |
|
| 52 | - if ($numberOfValues <= $this->getLimit()) { |
|
| 53 | - |
|
| 54 | - $contents = $contentRepository->findBy($matcher); |
|
| 55 | - |
|
| 56 | - foreach ($contents as $content) { |
|
| 57 | - $values[] = array($content->getUid() => $content[$table->getLabelField()]); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } elseif (!Tca::table($dataType)->field($fieldName)->isTextArea()) { // We don't want suggestion if field is text area. |
|
| 61 | - |
|
| 62 | - // Fetch the adequate repository |
|
| 63 | - /** @var \Fab\Vidi\Domain\Repository\ContentRepository $contentRepository */ |
|
| 64 | - $contentRepository = ContentRepositoryFactory::getInstance($dataType); |
|
| 65 | - |
|
| 66 | - // Initialize some objects related to the query |
|
| 67 | - $matcher = MatcherObjectFactory::getInstance()->getMatcher([], $dataType); |
|
| 68 | - |
|
| 69 | - // Count the number of objects. |
|
| 70 | - $numberOfValues = $contentRepository->countDistinctValues($fieldName, $matcher); |
|
| 71 | - |
|
| 72 | - // Only returns suggestion if there are not too many for the browser. |
|
| 73 | - if ($numberOfValues <= $this->getLimit()) { |
|
| 74 | - |
|
| 75 | - // Query the repository. |
|
| 76 | - $contents = $contentRepository->findDistinctValues($fieldName, $matcher); |
|
| 77 | - |
|
| 78 | - foreach ($contents as $content) { |
|
| 79 | - |
|
| 80 | - $value = $content[$fieldName]; |
|
| 81 | - $label = $content[$fieldName]; |
|
| 82 | - if (Tca::table($dataType)->field($fieldName)->isSelect()) { |
|
| 83 | - $label = Tca::table($dataType)->field($fieldName)->getLabelForItem($value); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $values[] = $label; |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - return $values; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Return from settings the suggestion limit. |
|
| 96 | - * |
|
| 97 | - * @return int |
|
| 98 | - */ |
|
| 99 | - protected function getLimit() |
|
| 100 | - { |
|
| 101 | - $settings = $this->getSettings(); |
|
| 102 | - $suggestionLimit = (int)$settings['suggestionLimit']; |
|
| 103 | - if ($suggestionLimit <= 0) { |
|
| 104 | - $suggestionLimit = 1000; |
|
| 105 | - } |
|
| 106 | - return $suggestionLimit; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @return \Fab\Vidi\Resolver\FieldPathResolver |
|
| 111 | - */ |
|
| 112 | - protected function getFieldPathResolver() |
|
| 113 | - { |
|
| 114 | - return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver'); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Returns the module settings. |
|
| 119 | - * |
|
| 120 | - * @return array |
|
| 121 | - */ |
|
| 122 | - protected function getSettings() |
|
| 123 | - { |
|
| 124 | - /** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */ |
|
| 125 | - $objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager'); |
|
| 126 | - $backendConfigurationManager = $objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager'); |
|
| 127 | - $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
|
| 128 | - return $configuration['module.']['tx_vidi.']['settings.']; |
|
| 129 | - } |
|
| 22 | + /** |
|
| 23 | + * Retrieve possible suggestions for a field name |
|
| 24 | + * |
|
| 25 | + * @param string $fieldNameAndPath |
|
| 26 | + * @return array |
|
| 27 | + * @throws \Exception |
|
| 28 | + */ |
|
| 29 | + public function getSuggestions($fieldNameAndPath) |
|
| 30 | + { |
|
| 31 | + |
|
| 32 | + $values = []; |
|
| 33 | + |
|
| 34 | + $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath); |
|
| 35 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath); |
|
| 36 | + |
|
| 37 | + if (Tca::grid()->facet($fieldNameAndPath)->hasSuggestions()) { |
|
| 38 | + $values = Tca::grid()->facet($fieldNameAndPath)->getSuggestions(); |
|
| 39 | + } else if (Tca::table($dataType)->hasField($fieldName)) { |
|
| 40 | + |
|
| 41 | + if (Tca::table($dataType)->field($fieldName)->hasRelation()) { |
|
| 42 | + |
|
| 43 | + // Fetch the adequate repository |
|
| 44 | + $foreignTable = Tca::table($dataType)->field($fieldName)->getForeignTable(); |
|
| 45 | + $contentRepository = ContentRepositoryFactory::getInstance($foreignTable); |
|
| 46 | + $table = Tca::table($foreignTable); |
|
| 47 | + |
|
| 48 | + // Initialize the matcher object. |
|
| 49 | + $matcher = MatcherObjectFactory::getInstance()->getMatcher([], $foreignTable); |
|
| 50 | + |
|
| 51 | + $numberOfValues = $contentRepository->countBy($matcher); |
|
| 52 | + if ($numberOfValues <= $this->getLimit()) { |
|
| 53 | + |
|
| 54 | + $contents = $contentRepository->findBy($matcher); |
|
| 55 | + |
|
| 56 | + foreach ($contents as $content) { |
|
| 57 | + $values[] = array($content->getUid() => $content[$table->getLabelField()]); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } elseif (!Tca::table($dataType)->field($fieldName)->isTextArea()) { // We don't want suggestion if field is text area. |
|
| 61 | + |
|
| 62 | + // Fetch the adequate repository |
|
| 63 | + /** @var \Fab\Vidi\Domain\Repository\ContentRepository $contentRepository */ |
|
| 64 | + $contentRepository = ContentRepositoryFactory::getInstance($dataType); |
|
| 65 | + |
|
| 66 | + // Initialize some objects related to the query |
|
| 67 | + $matcher = MatcherObjectFactory::getInstance()->getMatcher([], $dataType); |
|
| 68 | + |
|
| 69 | + // Count the number of objects. |
|
| 70 | + $numberOfValues = $contentRepository->countDistinctValues($fieldName, $matcher); |
|
| 71 | + |
|
| 72 | + // Only returns suggestion if there are not too many for the browser. |
|
| 73 | + if ($numberOfValues <= $this->getLimit()) { |
|
| 74 | + |
|
| 75 | + // Query the repository. |
|
| 76 | + $contents = $contentRepository->findDistinctValues($fieldName, $matcher); |
|
| 77 | + |
|
| 78 | + foreach ($contents as $content) { |
|
| 79 | + |
|
| 80 | + $value = $content[$fieldName]; |
|
| 81 | + $label = $content[$fieldName]; |
|
| 82 | + if (Tca::table($dataType)->field($fieldName)->isSelect()) { |
|
| 83 | + $label = Tca::table($dataType)->field($fieldName)->getLabelForItem($value); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $values[] = $label; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + return $values; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Return from settings the suggestion limit. |
|
| 96 | + * |
|
| 97 | + * @return int |
|
| 98 | + */ |
|
| 99 | + protected function getLimit() |
|
| 100 | + { |
|
| 101 | + $settings = $this->getSettings(); |
|
| 102 | + $suggestionLimit = (int)$settings['suggestionLimit']; |
|
| 103 | + if ($suggestionLimit <= 0) { |
|
| 104 | + $suggestionLimit = 1000; |
|
| 105 | + } |
|
| 106 | + return $suggestionLimit; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @return \Fab\Vidi\Resolver\FieldPathResolver |
|
| 111 | + */ |
|
| 112 | + protected function getFieldPathResolver() |
|
| 113 | + { |
|
| 114 | + return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver'); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Returns the module settings. |
|
| 119 | + * |
|
| 120 | + * @return array |
|
| 121 | + */ |
|
| 122 | + protected function getSettings() |
|
| 123 | + { |
|
| 124 | + /** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */ |
|
| 125 | + $objectManager = GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager'); |
|
| 126 | + $backendConfigurationManager = $objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager'); |
|
| 127 | + $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
|
| 128 | + return $configuration['module.']['tx_vidi.']['settings.']; |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | 131 | } |
@@ -18,145 +18,145 @@ |
||
| 18 | 18 | class StandardFacet implements FacetInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - protected $name; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - protected $label; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected $suggestions = []; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - protected $dataType; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var bool |
|
| 43 | - */ |
|
| 44 | - protected $canModifyMatcher = false; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Constructor of a Generic Facet in Vidi. |
|
| 48 | - * |
|
| 49 | - * @param string $name |
|
| 50 | - * @param string $label |
|
| 51 | - * @param array $suggestions |
|
| 52 | - */ |
|
| 53 | - public function __construct($name, $label = '', array $suggestions = array()) |
|
| 54 | - { |
|
| 55 | - $this->name = $name; |
|
| 56 | - if (empty($label)) { |
|
| 57 | - $label = $this->name; |
|
| 58 | - } |
|
| 59 | - $this->label = $label; |
|
| 60 | - $this->suggestions = $suggestions; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @return string |
|
| 65 | - */ |
|
| 66 | - public function getName() |
|
| 67 | - { |
|
| 68 | - return $this->name; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function getLabel() |
|
| 75 | - { |
|
| 76 | - if ($this->label === $this->name) { |
|
| 77 | - $label = Tca::table($this->dataType)->field($this->getName())->getLabel(); |
|
| 78 | - } else { |
|
| 79 | - $label = LocalizationUtility::translate($this->label, ''); |
|
| 80 | - if (empty($label)) { |
|
| 81 | - $label = $this->label; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - return $label; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @return array |
|
| 90 | - */ |
|
| 91 | - public function getSuggestions() |
|
| 92 | - { |
|
| 93 | - |
|
| 94 | - $values = []; |
|
| 95 | - foreach ($this->suggestions as $key => $label) { |
|
| 96 | - $localizedLabel = $this->getLanguageService()->sL($label); |
|
| 97 | - if (!empty($localizedLabel)) { |
|
| 98 | - $label = $localizedLabel; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $values[] = [$key => $label]; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return $values; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @return \TYPO3\CMS\Lang\LanguageService |
|
| 109 | - */ |
|
| 110 | - protected function getLanguageService() |
|
| 111 | - { |
|
| 112 | - return $GLOBALS['LANG']; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return bool |
|
| 117 | - */ |
|
| 118 | - public function hasSuggestions() |
|
| 119 | - { |
|
| 120 | - return !empty($this->suggestions); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * @param string $dataType |
|
| 125 | - * @return $this |
|
| 126 | - */ |
|
| 127 | - public function setDataType($dataType) |
|
| 128 | - { |
|
| 129 | - $this->dataType = $dataType; |
|
| 130 | - return $this; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @return bool |
|
| 135 | - */ |
|
| 136 | - public function canModifyMatcher() |
|
| 137 | - { |
|
| 138 | - return $this->canModifyMatcher; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param Matcher $matcher |
|
| 143 | - * @param $value |
|
| 144 | - * @return Matcher |
|
| 145 | - */ |
|
| 146 | - public function modifyMatcher(Matcher $matcher, $value) |
|
| 147 | - { |
|
| 148 | - return $matcher; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Magic method implementation for retrieving state. |
|
| 153 | - * |
|
| 154 | - * @param array $states |
|
| 155 | - * @return StandardFacet |
|
| 156 | - */ |
|
| 157 | - static public function __set_state($states) |
|
| 158 | - { |
|
| 159 | - return new StandardFacet($states['name'], $states['label'], $states['suggestions']); |
|
| 160 | - } |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + protected $name; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + protected $label; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected $suggestions = []; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + protected $dataType; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var bool |
|
| 43 | + */ |
|
| 44 | + protected $canModifyMatcher = false; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Constructor of a Generic Facet in Vidi. |
|
| 48 | + * |
|
| 49 | + * @param string $name |
|
| 50 | + * @param string $label |
|
| 51 | + * @param array $suggestions |
|
| 52 | + */ |
|
| 53 | + public function __construct($name, $label = '', array $suggestions = array()) |
|
| 54 | + { |
|
| 55 | + $this->name = $name; |
|
| 56 | + if (empty($label)) { |
|
| 57 | + $label = $this->name; |
|
| 58 | + } |
|
| 59 | + $this->label = $label; |
|
| 60 | + $this->suggestions = $suggestions; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @return string |
|
| 65 | + */ |
|
| 66 | + public function getName() |
|
| 67 | + { |
|
| 68 | + return $this->name; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function getLabel() |
|
| 75 | + { |
|
| 76 | + if ($this->label === $this->name) { |
|
| 77 | + $label = Tca::table($this->dataType)->field($this->getName())->getLabel(); |
|
| 78 | + } else { |
|
| 79 | + $label = LocalizationUtility::translate($this->label, ''); |
|
| 80 | + if (empty($label)) { |
|
| 81 | + $label = $this->label; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + return $label; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @return array |
|
| 90 | + */ |
|
| 91 | + public function getSuggestions() |
|
| 92 | + { |
|
| 93 | + |
|
| 94 | + $values = []; |
|
| 95 | + foreach ($this->suggestions as $key => $label) { |
|
| 96 | + $localizedLabel = $this->getLanguageService()->sL($label); |
|
| 97 | + if (!empty($localizedLabel)) { |
|
| 98 | + $label = $localizedLabel; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $values[] = [$key => $label]; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return $values; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @return \TYPO3\CMS\Lang\LanguageService |
|
| 109 | + */ |
|
| 110 | + protected function getLanguageService() |
|
| 111 | + { |
|
| 112 | + return $GLOBALS['LANG']; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @return bool |
|
| 117 | + */ |
|
| 118 | + public function hasSuggestions() |
|
| 119 | + { |
|
| 120 | + return !empty($this->suggestions); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * @param string $dataType |
|
| 125 | + * @return $this |
|
| 126 | + */ |
|
| 127 | + public function setDataType($dataType) |
|
| 128 | + { |
|
| 129 | + $this->dataType = $dataType; |
|
| 130 | + return $this; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @return bool |
|
| 135 | + */ |
|
| 136 | + public function canModifyMatcher() |
|
| 137 | + { |
|
| 138 | + return $this->canModifyMatcher; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param Matcher $matcher |
|
| 143 | + * @param $value |
|
| 144 | + * @return Matcher |
|
| 145 | + */ |
|
| 146 | + public function modifyMatcher(Matcher $matcher, $value) |
|
| 147 | + { |
|
| 148 | + return $matcher; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Magic method implementation for retrieving state. |
|
| 153 | + * |
|
| 154 | + * @param array $states |
|
| 155 | + * @return StandardFacet |
|
| 156 | + */ |
|
| 157 | + static public function __set_state($states) |
|
| 158 | + { |
|
| 159 | + return new StandardFacet($states['name'], $states['label'], $states['suggestions']); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | 162 | } |
@@ -19,439 +19,439 @@ |
||
| 19 | 19 | class TableService extends AbstractTca |
| 20 | 20 | { |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var array |
|
| 24 | - */ |
|
| 25 | - protected $tca; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected $columnTca; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 35 | - protected $tableName; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected $instances; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @throws InvalidKeyInArrayException |
|
| 44 | - * @param string $tableName |
|
| 45 | - * @return \Fab\Vidi\Tca\TableService |
|
| 46 | - */ |
|
| 47 | - public function __construct($tableName) |
|
| 48 | - { |
|
| 49 | - $this->tableName = $tableName; |
|
| 50 | - if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
| 51 | - throw new InvalidKeyInArrayException(sprintf('No TCA existence for table "%s"', $this->tableName), 1356945106); |
|
| 52 | - } |
|
| 53 | - $this->tca = $GLOBALS['TCA'][$this->tableName]['ctrl']; |
|
| 54 | - $this->columnTca = $GLOBALS['TCA'][$this->tableName]['columns']; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Tell whether the table has a label field. |
|
| 59 | - * |
|
| 60 | - * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function hasLabelField() |
|
| 64 | - { |
|
| 65 | - return $this->has('label'); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Get the label name of table name. |
|
| 70 | - * |
|
| 71 | - * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - public function getLabelField() |
|
| 75 | - { |
|
| 76 | - $labelField = $this->get('label'); |
|
| 77 | - if (empty($labelField)) { |
|
| 78 | - throw new InvalidKeyInArrayException(sprintf('No label configured for table "%s"', $this->tableName), 1385586726); |
|
| 79 | - } |
|
| 80 | - return $labelField; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Returns the translated label of the table name. |
|
| 85 | - * |
|
| 86 | - * @return string |
|
| 87 | - */ |
|
| 88 | - public function getLabel() |
|
| 89 | - { |
|
| 90 | - $result = LocalizationUtility::translate($this->getLabelField(), ''); |
|
| 91 | - if (!$result) { |
|
| 92 | - $result = $this->getLabelField(); |
|
| 93 | - } |
|
| 94 | - return $result; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Returns the title of the table. |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - public function getTitle() |
|
| 103 | - { |
|
| 104 | - $result = LocalizationUtility::translate($this->get('title'), ''); |
|
| 105 | - if (!$result) { |
|
| 106 | - $result = $this->get('title'); |
|
| 107 | - } |
|
| 108 | - return $result; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Return the "disabled" field. |
|
| 113 | - * |
|
| 114 | - * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
|
| 115 | - * @return string|null |
|
| 116 | - */ |
|
| 117 | - public function getHiddenField() |
|
| 118 | - { |
|
| 119 | - $hiddenField = null; |
|
| 120 | - $enableColumns = $this->get('enablecolumns'); |
|
| 121 | - if (is_array($enableColumns) && !empty($enableColumns['disabled'])) { |
|
| 122 | - $hiddenField = $enableColumns['disabled']; |
|
| 123 | - } |
|
| 124 | - return $hiddenField; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Return the "starttime" field. |
|
| 129 | - * |
|
| 130 | - * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
|
| 131 | - * @return string|null |
|
| 132 | - */ |
|
| 133 | - public function getStartTimeField() |
|
| 134 | - { |
|
| 135 | - $startTimeField = null; |
|
| 136 | - $enableColumns = $this->get('enablecolumns'); |
|
| 137 | - if (is_array($enableColumns) && !empty($enableColumns['starttime'])) { |
|
| 138 | - $startTimeField = $enableColumns['starttime']; |
|
| 139 | - } |
|
| 140 | - return $startTimeField; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Return the "endtime" field. |
|
| 145 | - * |
|
| 146 | - * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
|
| 147 | - * @return string|null |
|
| 148 | - */ |
|
| 149 | - public function getEndTimeField() |
|
| 150 | - { |
|
| 151 | - $endTimeField = null; |
|
| 152 | - $enableColumns = $this->get('enablecolumns'); |
|
| 153 | - if (is_array($enableColumns) && !empty($enableColumns['endtime'])) { |
|
| 154 | - $endTimeField = $enableColumns['endtime']; |
|
| 155 | - } |
|
| 156 | - return $endTimeField; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Tells whether the table is hidden. |
|
| 161 | - * |
|
| 162 | - * @return bool |
|
| 163 | - */ |
|
| 164 | - public function isHidden() |
|
| 165 | - { |
|
| 166 | - return isset($this->tca['hideTable']) ? $this->tca['hideTable'] : false; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Tells whether the table is not hidden. |
|
| 171 | - * |
|
| 172 | - * @return bool |
|
| 173 | - */ |
|
| 174 | - public function isNotHidden() |
|
| 175 | - { |
|
| 176 | - return !$this->isHidden(); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Get the "deleted" field for the table. |
|
| 181 | - * |
|
| 182 | - * @return string|null |
|
| 183 | - */ |
|
| 184 | - public function getDeletedField() |
|
| 185 | - { |
|
| 186 | - return $this->get('delete'); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Get the modification time stamp field. |
|
| 191 | - * |
|
| 192 | - * @return string|null |
|
| 193 | - */ |
|
| 194 | - public function getTimeModificationField() |
|
| 195 | - { |
|
| 196 | - return $this->get('tstamp'); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Get the creation time stamp field. |
|
| 201 | - * |
|
| 202 | - * @return string|null |
|
| 203 | - */ |
|
| 204 | - public function getTimeCreationField() |
|
| 205 | - { |
|
| 206 | - return $this->get('crdate'); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Get the language field for the table. |
|
| 211 | - * |
|
| 212 | - * @return string|null |
|
| 213 | - */ |
|
| 214 | - public function getLanguageField() |
|
| 215 | - { |
|
| 216 | - return $this->get('languageField'); |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - /** |
|
| 220 | - * Get the field which points to the parent. |
|
| 221 | - * |
|
| 222 | - * @return string|null |
|
| 223 | - */ |
|
| 224 | - public function getLanguageParentField() |
|
| 225 | - { |
|
| 226 | - return $this->get('transOrigPointerField'); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Returns the default order in the form of a SQL segment. |
|
| 231 | - * |
|
| 232 | - * @return string|null |
|
| 233 | - */ |
|
| 234 | - public function getDefaultOrderSql() |
|
| 235 | - { |
|
| 236 | - // "sortby" typically has "sorting" as value. |
|
| 237 | - $order = $this->get('sortby') ? $this->get('sortby') . ' ASC' : $this->get('default_sortby'); |
|
| 238 | - return $order; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Returns the parsed default orderings. |
|
| 243 | - * Returns array looks like array('title' => 'ASC'); |
|
| 244 | - * |
|
| 245 | - * @return array |
|
| 246 | - */ |
|
| 247 | - public function getDefaultOrderings() |
|
| 248 | - { |
|
| 249 | - |
|
| 250 | - // first clean up the sql segment |
|
| 251 | - $defaultOrder = str_replace('ORDER BY', '', $this->getDefaultOrderSql()); |
|
| 252 | - $defaultOrderParts = GeneralUtility::trimExplode(',', $defaultOrder, true); |
|
| 253 | - |
|
| 254 | - $orderings = []; |
|
| 255 | - foreach ($defaultOrderParts as $defaultOrderPart) { |
|
| 256 | - $parts = GeneralUtility::trimExplode(' ', $defaultOrderPart); |
|
| 257 | - if (empty($parts[1])) { |
|
| 258 | - $parts[1] = QueryInterface::ORDER_DESCENDING; |
|
| 259 | - } |
|
| 260 | - $orderings[$parts[0]] = $parts[1]; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - return $orderings; |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - /** |
|
| 267 | - * Returns the searchable fields. |
|
| 268 | - * |
|
| 269 | - * @return string|null |
|
| 270 | - */ |
|
| 271 | - public function getSearchFields() |
|
| 272 | - { |
|
| 273 | - return $this->get('searchFields'); |
|
| 274 | - } |
|
| 275 | - |
|
| 276 | - /** |
|
| 277 | - * Returns an array containing the field names. |
|
| 278 | - * |
|
| 279 | - * @return array |
|
| 280 | - */ |
|
| 281 | - public function getFields() |
|
| 282 | - { |
|
| 283 | - return array_keys($this->columnTca); |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Returns an array containing the fields and their configuration. |
|
| 288 | - * |
|
| 289 | - * @return array |
|
| 290 | - */ |
|
| 291 | - public function getFieldsAndConfiguration() |
|
| 292 | - { |
|
| 293 | - return $this->columnTca; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Tell whether we have a field "sorting". |
|
| 298 | - * |
|
| 299 | - * @return array |
|
| 300 | - */ |
|
| 301 | - public function hasSortableField() |
|
| 302 | - { |
|
| 303 | - return $this->has('sortby'); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Tell whether the field exists or not. |
|
| 308 | - * |
|
| 309 | - * @param string $fieldName |
|
| 310 | - * @return array |
|
| 311 | - */ |
|
| 312 | - public function hasField($fieldName) |
|
| 313 | - { |
|
| 314 | - if ($this->isComposite($fieldName)) { |
|
| 315 | - $parts = explode('.', $fieldName); |
|
| 316 | - $strippedFieldName = $parts[0]; |
|
| 317 | - $tableName = $parts[1]; |
|
| 318 | - |
|
| 319 | - $hasField = $this->columnTca[$strippedFieldName] && isset($GLOBALS['TCA'][$tableName]); |
|
| 320 | - |
|
| 321 | - // Continue checking that the $strippedFieldName is of type "group" |
|
| 322 | - if (isset($GLOBALS['TCA'][$this->tableName]['columns'][$strippedFieldName])) { |
|
| 323 | - $hasField = Tca::table($this->tableName)->field($strippedFieldName)->isGroup(); // Group |
|
| 324 | - } |
|
| 325 | - } else { |
|
| 326 | - $hasField = isset($this->columnTca[$fieldName]) || in_array($fieldName, Tca::getSystemFields()); |
|
| 327 | - } |
|
| 328 | - return $hasField; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * Tell whether the field name contains a path, e.g. metadata.title |
|
| 333 | - * |
|
| 334 | - * @param string $fieldName |
|
| 335 | - * @return boolean |
|
| 336 | - */ |
|
| 337 | - public function isComposite($fieldName) |
|
| 338 | - { |
|
| 339 | - return strpos($fieldName, '.') > 0; |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Tells whether the $key exists. |
|
| 344 | - * |
|
| 345 | - * @param string $key |
|
| 346 | - * @return string |
|
| 347 | - */ |
|
| 348 | - public function has($key) |
|
| 349 | - { |
|
| 350 | - return isset($this->tca[$key]); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Tells whether the table name has "workspace" support. |
|
| 355 | - * |
|
| 356 | - * @return string |
|
| 357 | - */ |
|
| 358 | - public function hasWorkspaceSupport() |
|
| 359 | - { |
|
| 360 | - return isset($this->tca['versioningWS']); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Tells whether the table name has "language" support. |
|
| 365 | - * |
|
| 366 | - * @return string |
|
| 367 | - */ |
|
| 368 | - public function hasLanguageSupport() |
|
| 369 | - { |
|
| 370 | - return isset($this->tca['languageField']); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * Return configuration value given a key. |
|
| 375 | - * |
|
| 376 | - * @param string $key |
|
| 377 | - * @return string|null |
|
| 378 | - */ |
|
| 379 | - public function get($key) |
|
| 380 | - { |
|
| 381 | - return $this->has($key) ? $this->tca[$key] : null; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - /** |
|
| 385 | - * @return array |
|
| 386 | - */ |
|
| 387 | - public function getTca() |
|
| 388 | - { |
|
| 389 | - return $this->tca; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Tell whether the current BE User has access to this field. |
|
| 394 | - * |
|
| 395 | - * @return bool |
|
| 396 | - */ |
|
| 397 | - public function hasAccess() |
|
| 398 | - { |
|
| 399 | - $hasAccess = true; |
|
| 400 | - if ($this->isBackendMode()) { |
|
| 401 | - $hasAccess = $this->getBackendUser()->check('tables_modify', $this->tableName); |
|
| 402 | - } |
|
| 403 | - return $hasAccess; |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * @param string $fieldName |
|
| 408 | - * @throws \Exception |
|
| 409 | - * @return \Fab\Vidi\Tca\FieldService |
|
| 410 | - */ |
|
| 411 | - public function field($fieldName) |
|
| 412 | - { |
|
| 413 | - |
|
| 414 | - // In case field contains items.tx_table for field type "group" |
|
| 415 | - $compositeField = ''; |
|
| 416 | - if (strpos($fieldName, '.') !== false) { |
|
| 417 | - $compositeField = $fieldName; |
|
| 418 | - $fieldParts = explode('.', $compositeField, 2); |
|
| 419 | - $fieldName = $fieldParts[0]; |
|
| 420 | - |
|
| 421 | - // Special when field has been instantiated without the field name and path. |
|
| 422 | - if (!empty($this->instances[$fieldName])) { |
|
| 423 | - /** @var FieldService $field */ |
|
| 424 | - $field = $this->instances[$fieldName]; |
|
| 425 | - $field->setCompositeField($compositeField); |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // True for system fields such as uid, pid that don't necessarily have a TCA. |
|
| 430 | - if (empty($this->columnTca[$fieldName]) && in_array($fieldName, Tca::getSystemFields())) { |
|
| 431 | - $this->columnTca[$fieldName] = []; |
|
| 432 | - } elseif (empty($this->columnTca[$fieldName])) { |
|
| 433 | - $message = sprintf( |
|
| 434 | - 'Does the field really exist? No TCA entry found for field "%s" for table "%s"', |
|
| 435 | - $fieldName, |
|
| 436 | - $this->tableName |
|
| 437 | - ); |
|
| 438 | - throw new \Exception($message, 1385554481); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - if (empty($this->instances[$fieldName])) { |
|
| 443 | - |
|
| 444 | - $instance = GeneralUtility::makeInstance( |
|
| 445 | - 'Fab\Vidi\Tca\FieldService', |
|
| 446 | - $fieldName, |
|
| 447 | - $this->columnTca[$fieldName], |
|
| 448 | - $this->tableName, |
|
| 449 | - $compositeField |
|
| 450 | - ); |
|
| 451 | - |
|
| 452 | - $this->instances[$fieldName] = $instance; |
|
| 453 | - } |
|
| 454 | - return $this->instances[$fieldName]; |
|
| 455 | - } |
|
| 22 | + /** |
|
| 23 | + * @var array |
|
| 24 | + */ |
|
| 25 | + protected $tca; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected $columnTca; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | + protected $tableName; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected $instances; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @throws InvalidKeyInArrayException |
|
| 44 | + * @param string $tableName |
|
| 45 | + * @return \Fab\Vidi\Tca\TableService |
|
| 46 | + */ |
|
| 47 | + public function __construct($tableName) |
|
| 48 | + { |
|
| 49 | + $this->tableName = $tableName; |
|
| 50 | + if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
| 51 | + throw new InvalidKeyInArrayException(sprintf('No TCA existence for table "%s"', $this->tableName), 1356945106); |
|
| 52 | + } |
|
| 53 | + $this->tca = $GLOBALS['TCA'][$this->tableName]['ctrl']; |
|
| 54 | + $this->columnTca = $GLOBALS['TCA'][$this->tableName]['columns']; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Tell whether the table has a label field. |
|
| 59 | + * |
|
| 60 | + * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function hasLabelField() |
|
| 64 | + { |
|
| 65 | + return $this->has('label'); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Get the label name of table name. |
|
| 70 | + * |
|
| 71 | + * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + public function getLabelField() |
|
| 75 | + { |
|
| 76 | + $labelField = $this->get('label'); |
|
| 77 | + if (empty($labelField)) { |
|
| 78 | + throw new InvalidKeyInArrayException(sprintf('No label configured for table "%s"', $this->tableName), 1385586726); |
|
| 79 | + } |
|
| 80 | + return $labelField; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Returns the translated label of the table name. |
|
| 85 | + * |
|
| 86 | + * @return string |
|
| 87 | + */ |
|
| 88 | + public function getLabel() |
|
| 89 | + { |
|
| 90 | + $result = LocalizationUtility::translate($this->getLabelField(), ''); |
|
| 91 | + if (!$result) { |
|
| 92 | + $result = $this->getLabelField(); |
|
| 93 | + } |
|
| 94 | + return $result; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Returns the title of the table. |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + public function getTitle() |
|
| 103 | + { |
|
| 104 | + $result = LocalizationUtility::translate($this->get('title'), ''); |
|
| 105 | + if (!$result) { |
|
| 106 | + $result = $this->get('title'); |
|
| 107 | + } |
|
| 108 | + return $result; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Return the "disabled" field. |
|
| 113 | + * |
|
| 114 | + * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
|
| 115 | + * @return string|null |
|
| 116 | + */ |
|
| 117 | + public function getHiddenField() |
|
| 118 | + { |
|
| 119 | + $hiddenField = null; |
|
| 120 | + $enableColumns = $this->get('enablecolumns'); |
|
| 121 | + if (is_array($enableColumns) && !empty($enableColumns['disabled'])) { |
|
| 122 | + $hiddenField = $enableColumns['disabled']; |
|
| 123 | + } |
|
| 124 | + return $hiddenField; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Return the "starttime" field. |
|
| 129 | + * |
|
| 130 | + * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
|
| 131 | + * @return string|null |
|
| 132 | + */ |
|
| 133 | + public function getStartTimeField() |
|
| 134 | + { |
|
| 135 | + $startTimeField = null; |
|
| 136 | + $enableColumns = $this->get('enablecolumns'); |
|
| 137 | + if (is_array($enableColumns) && !empty($enableColumns['starttime'])) { |
|
| 138 | + $startTimeField = $enableColumns['starttime']; |
|
| 139 | + } |
|
| 140 | + return $startTimeField; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Return the "endtime" field. |
|
| 145 | + * |
|
| 146 | + * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
|
| 147 | + * @return string|null |
|
| 148 | + */ |
|
| 149 | + public function getEndTimeField() |
|
| 150 | + { |
|
| 151 | + $endTimeField = null; |
|
| 152 | + $enableColumns = $this->get('enablecolumns'); |
|
| 153 | + if (is_array($enableColumns) && !empty($enableColumns['endtime'])) { |
|
| 154 | + $endTimeField = $enableColumns['endtime']; |
|
| 155 | + } |
|
| 156 | + return $endTimeField; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Tells whether the table is hidden. |
|
| 161 | + * |
|
| 162 | + * @return bool |
|
| 163 | + */ |
|
| 164 | + public function isHidden() |
|
| 165 | + { |
|
| 166 | + return isset($this->tca['hideTable']) ? $this->tca['hideTable'] : false; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Tells whether the table is not hidden. |
|
| 171 | + * |
|
| 172 | + * @return bool |
|
| 173 | + */ |
|
| 174 | + public function isNotHidden() |
|
| 175 | + { |
|
| 176 | + return !$this->isHidden(); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Get the "deleted" field for the table. |
|
| 181 | + * |
|
| 182 | + * @return string|null |
|
| 183 | + */ |
|
| 184 | + public function getDeletedField() |
|
| 185 | + { |
|
| 186 | + return $this->get('delete'); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Get the modification time stamp field. |
|
| 191 | + * |
|
| 192 | + * @return string|null |
|
| 193 | + */ |
|
| 194 | + public function getTimeModificationField() |
|
| 195 | + { |
|
| 196 | + return $this->get('tstamp'); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Get the creation time stamp field. |
|
| 201 | + * |
|
| 202 | + * @return string|null |
|
| 203 | + */ |
|
| 204 | + public function getTimeCreationField() |
|
| 205 | + { |
|
| 206 | + return $this->get('crdate'); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Get the language field for the table. |
|
| 211 | + * |
|
| 212 | + * @return string|null |
|
| 213 | + */ |
|
| 214 | + public function getLanguageField() |
|
| 215 | + { |
|
| 216 | + return $this->get('languageField'); |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + /** |
|
| 220 | + * Get the field which points to the parent. |
|
| 221 | + * |
|
| 222 | + * @return string|null |
|
| 223 | + */ |
|
| 224 | + public function getLanguageParentField() |
|
| 225 | + { |
|
| 226 | + return $this->get('transOrigPointerField'); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Returns the default order in the form of a SQL segment. |
|
| 231 | + * |
|
| 232 | + * @return string|null |
|
| 233 | + */ |
|
| 234 | + public function getDefaultOrderSql() |
|
| 235 | + { |
|
| 236 | + // "sortby" typically has "sorting" as value. |
|
| 237 | + $order = $this->get('sortby') ? $this->get('sortby') . ' ASC' : $this->get('default_sortby'); |
|
| 238 | + return $order; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Returns the parsed default orderings. |
|
| 243 | + * Returns array looks like array('title' => 'ASC'); |
|
| 244 | + * |
|
| 245 | + * @return array |
|
| 246 | + */ |
|
| 247 | + public function getDefaultOrderings() |
|
| 248 | + { |
|
| 249 | + |
|
| 250 | + // first clean up the sql segment |
|
| 251 | + $defaultOrder = str_replace('ORDER BY', '', $this->getDefaultOrderSql()); |
|
| 252 | + $defaultOrderParts = GeneralUtility::trimExplode(',', $defaultOrder, true); |
|
| 253 | + |
|
| 254 | + $orderings = []; |
|
| 255 | + foreach ($defaultOrderParts as $defaultOrderPart) { |
|
| 256 | + $parts = GeneralUtility::trimExplode(' ', $defaultOrderPart); |
|
| 257 | + if (empty($parts[1])) { |
|
| 258 | + $parts[1] = QueryInterface::ORDER_DESCENDING; |
|
| 259 | + } |
|
| 260 | + $orderings[$parts[0]] = $parts[1]; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + return $orderings; |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + /** |
|
| 267 | + * Returns the searchable fields. |
|
| 268 | + * |
|
| 269 | + * @return string|null |
|
| 270 | + */ |
|
| 271 | + public function getSearchFields() |
|
| 272 | + { |
|
| 273 | + return $this->get('searchFields'); |
|
| 274 | + } |
|
| 275 | + |
|
| 276 | + /** |
|
| 277 | + * Returns an array containing the field names. |
|
| 278 | + * |
|
| 279 | + * @return array |
|
| 280 | + */ |
|
| 281 | + public function getFields() |
|
| 282 | + { |
|
| 283 | + return array_keys($this->columnTca); |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Returns an array containing the fields and their configuration. |
|
| 288 | + * |
|
| 289 | + * @return array |
|
| 290 | + */ |
|
| 291 | + public function getFieldsAndConfiguration() |
|
| 292 | + { |
|
| 293 | + return $this->columnTca; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Tell whether we have a field "sorting". |
|
| 298 | + * |
|
| 299 | + * @return array |
|
| 300 | + */ |
|
| 301 | + public function hasSortableField() |
|
| 302 | + { |
|
| 303 | + return $this->has('sortby'); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Tell whether the field exists or not. |
|
| 308 | + * |
|
| 309 | + * @param string $fieldName |
|
| 310 | + * @return array |
|
| 311 | + */ |
|
| 312 | + public function hasField($fieldName) |
|
| 313 | + { |
|
| 314 | + if ($this->isComposite($fieldName)) { |
|
| 315 | + $parts = explode('.', $fieldName); |
|
| 316 | + $strippedFieldName = $parts[0]; |
|
| 317 | + $tableName = $parts[1]; |
|
| 318 | + |
|
| 319 | + $hasField = $this->columnTca[$strippedFieldName] && isset($GLOBALS['TCA'][$tableName]); |
|
| 320 | + |
|
| 321 | + // Continue checking that the $strippedFieldName is of type "group" |
|
| 322 | + if (isset($GLOBALS['TCA'][$this->tableName]['columns'][$strippedFieldName])) { |
|
| 323 | + $hasField = Tca::table($this->tableName)->field($strippedFieldName)->isGroup(); // Group |
|
| 324 | + } |
|
| 325 | + } else { |
|
| 326 | + $hasField = isset($this->columnTca[$fieldName]) || in_array($fieldName, Tca::getSystemFields()); |
|
| 327 | + } |
|
| 328 | + return $hasField; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * Tell whether the field name contains a path, e.g. metadata.title |
|
| 333 | + * |
|
| 334 | + * @param string $fieldName |
|
| 335 | + * @return boolean |
|
| 336 | + */ |
|
| 337 | + public function isComposite($fieldName) |
|
| 338 | + { |
|
| 339 | + return strpos($fieldName, '.') > 0; |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Tells whether the $key exists. |
|
| 344 | + * |
|
| 345 | + * @param string $key |
|
| 346 | + * @return string |
|
| 347 | + */ |
|
| 348 | + public function has($key) |
|
| 349 | + { |
|
| 350 | + return isset($this->tca[$key]); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Tells whether the table name has "workspace" support. |
|
| 355 | + * |
|
| 356 | + * @return string |
|
| 357 | + */ |
|
| 358 | + public function hasWorkspaceSupport() |
|
| 359 | + { |
|
| 360 | + return isset($this->tca['versioningWS']); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Tells whether the table name has "language" support. |
|
| 365 | + * |
|
| 366 | + * @return string |
|
| 367 | + */ |
|
| 368 | + public function hasLanguageSupport() |
|
| 369 | + { |
|
| 370 | + return isset($this->tca['languageField']); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * Return configuration value given a key. |
|
| 375 | + * |
|
| 376 | + * @param string $key |
|
| 377 | + * @return string|null |
|
| 378 | + */ |
|
| 379 | + public function get($key) |
|
| 380 | + { |
|
| 381 | + return $this->has($key) ? $this->tca[$key] : null; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + /** |
|
| 385 | + * @return array |
|
| 386 | + */ |
|
| 387 | + public function getTca() |
|
| 388 | + { |
|
| 389 | + return $this->tca; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Tell whether the current BE User has access to this field. |
|
| 394 | + * |
|
| 395 | + * @return bool |
|
| 396 | + */ |
|
| 397 | + public function hasAccess() |
|
| 398 | + { |
|
| 399 | + $hasAccess = true; |
|
| 400 | + if ($this->isBackendMode()) { |
|
| 401 | + $hasAccess = $this->getBackendUser()->check('tables_modify', $this->tableName); |
|
| 402 | + } |
|
| 403 | + return $hasAccess; |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * @param string $fieldName |
|
| 408 | + * @throws \Exception |
|
| 409 | + * @return \Fab\Vidi\Tca\FieldService |
|
| 410 | + */ |
|
| 411 | + public function field($fieldName) |
|
| 412 | + { |
|
| 413 | + |
|
| 414 | + // In case field contains items.tx_table for field type "group" |
|
| 415 | + $compositeField = ''; |
|
| 416 | + if (strpos($fieldName, '.') !== false) { |
|
| 417 | + $compositeField = $fieldName; |
|
| 418 | + $fieldParts = explode('.', $compositeField, 2); |
|
| 419 | + $fieldName = $fieldParts[0]; |
|
| 420 | + |
|
| 421 | + // Special when field has been instantiated without the field name and path. |
|
| 422 | + if (!empty($this->instances[$fieldName])) { |
|
| 423 | + /** @var FieldService $field */ |
|
| 424 | + $field = $this->instances[$fieldName]; |
|
| 425 | + $field->setCompositeField($compositeField); |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // True for system fields such as uid, pid that don't necessarily have a TCA. |
|
| 430 | + if (empty($this->columnTca[$fieldName]) && in_array($fieldName, Tca::getSystemFields())) { |
|
| 431 | + $this->columnTca[$fieldName] = []; |
|
| 432 | + } elseif (empty($this->columnTca[$fieldName])) { |
|
| 433 | + $message = sprintf( |
|
| 434 | + 'Does the field really exist? No TCA entry found for field "%s" for table "%s"', |
|
| 435 | + $fieldName, |
|
| 436 | + $this->tableName |
|
| 437 | + ); |
|
| 438 | + throw new \Exception($message, 1385554481); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + if (empty($this->instances[$fieldName])) { |
|
| 443 | + |
|
| 444 | + $instance = GeneralUtility::makeInstance( |
|
| 445 | + 'Fab\Vidi\Tca\FieldService', |
|
| 446 | + $fieldName, |
|
| 447 | + $this->columnTca[$fieldName], |
|
| 448 | + $this->tableName, |
|
| 449 | + $compositeField |
|
| 450 | + ); |
|
| 451 | + |
|
| 452 | + $this->instances[$fieldName] = $instance; |
|
| 453 | + } |
|
| 454 | + return $this->instances[$fieldName]; |
|
| 455 | + } |
|
| 456 | 456 | |
| 457 | 457 | } |
@@ -25,684 +25,684 @@ |
||
| 25 | 25 | class GridService extends AbstractTca |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $tca; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - protected $tableName; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * All fields available in the Grid. |
|
| 40 | - * |
|
| 41 | - * @var array |
|
| 42 | - */ |
|
| 43 | - protected $fields; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * All fields regardless whether they have been excluded or not. |
|
| 47 | - * |
|
| 48 | - * @var array |
|
| 49 | - */ |
|
| 50 | - protected $allFields; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - protected $instances; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var array |
|
| 59 | - */ |
|
| 60 | - protected $facets; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * __construct |
|
| 64 | - * |
|
| 65 | - * @throws InvalidKeyInArrayException |
|
| 66 | - * @param string $tableName |
|
| 67 | - * @return \Fab\Vidi\Tca\GridService |
|
| 68 | - */ |
|
| 69 | - public function __construct($tableName) |
|
| 70 | - { |
|
| 71 | - |
|
| 72 | - $this->tableName = $tableName; |
|
| 73 | - |
|
| 74 | - if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
| 75 | - throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $this->tca = $GLOBALS['TCA'][$this->tableName]['grid']; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Returns an array containing column names. |
|
| 83 | - * |
|
| 84 | - * @return array |
|
| 85 | - */ |
|
| 86 | - public function getFieldNames() |
|
| 87 | - { |
|
| 88 | - $fields = $this->getFields(); |
|
| 89 | - return array_keys($fields); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Returns an array containing column names. |
|
| 94 | - * |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - public function getAllFieldNames() |
|
| 98 | - { |
|
| 99 | - $allFields = $this->getAllFields(); |
|
| 100 | - return array_keys($allFields); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Get the label key. |
|
| 105 | - * |
|
| 106 | - * @param string $fieldNameAndPath |
|
| 107 | - * @return string |
|
| 108 | - * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
|
| 109 | - */ |
|
| 110 | - public function getLabelKey($fieldNameAndPath) |
|
| 111 | - { |
|
| 112 | - |
|
| 113 | - $field = $this->getField($fieldNameAndPath); |
|
| 114 | - |
|
| 115 | - // First option is to get the label from the Grid TCA. |
|
| 116 | - $rawLabel = ''; |
|
| 117 | - if (isset($field['label'])) { |
|
| 118 | - $rawLabel = $field['label']; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // Second option is to fetch the label from the Column Renderer object. |
|
| 122 | - if (!$rawLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
| 123 | - $renderers = $this->getRenderers($fieldNameAndPath); |
|
| 124 | - /** @var $renderer ColumnRendererInterface */ |
|
| 125 | - foreach ($renderers as $renderer) { |
|
| 126 | - if (isset($renderer['label'])) { |
|
| 127 | - $rawLabel = $renderer['label']; |
|
| 128 | - break; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - return $rawLabel; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Get the translation of a label given a column name. |
|
| 137 | - * |
|
| 138 | - * @param string $fieldNameAndPath |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - public function getLabel($fieldNameAndPath) |
|
| 142 | - { |
|
| 143 | - $label = ''; |
|
| 144 | - if ($this->hasLabel($fieldNameAndPath)) { |
|
| 145 | - $labelKey = $this->getLabelKey($fieldNameAndPath); |
|
| 146 | - $label = LocalizationUtility::translate($labelKey, ''); |
|
| 147 | - if (is_null($label)) { |
|
| 148 | - $label = $labelKey; |
|
| 149 | - } |
|
| 150 | - } else { |
|
| 151 | - |
|
| 152 | - // Important to notice the label can contains a path, e.g. metadata.categories and must be resolved. |
|
| 153 | - $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->tableName); |
|
| 154 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->tableName); |
|
| 155 | - $table = Tca::table($dataType); |
|
| 156 | - |
|
| 157 | - if ($table->hasField($fieldName) && $table->field($fieldName)->hasLabel()) { |
|
| 158 | - $label = $table->field($fieldName)->getLabel(); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - return $label; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Returns the field name given its position. |
|
| 167 | - * |
|
| 168 | - * @param string $position the position of the field in the grid |
|
| 169 | - * @throws InvalidKeyInArrayException |
|
| 170 | - * @return int |
|
| 171 | - */ |
|
| 172 | - public function getFieldNameByPosition($position) |
|
| 173 | - { |
|
| 174 | - $fields = array_keys($this->getFields()); |
|
| 175 | - if (empty($fields[$position])) { |
|
| 176 | - throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return $fields[$position]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Returns a field name. |
|
| 184 | - * |
|
| 185 | - * @param string $fieldName |
|
| 186 | - * @return array |
|
| 187 | - * @throws InvalidKeyInArrayException |
|
| 188 | - */ |
|
| 189 | - public function getField($fieldName) |
|
| 190 | - { |
|
| 191 | - $fields = $this->getFields(); |
|
| 192 | - return $fields[$fieldName]; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Returns an array containing column names for the Grid. |
|
| 197 | - * |
|
| 198 | - * @return array |
|
| 199 | - * @throws \Exception |
|
| 200 | - */ |
|
| 201 | - public function getFields() |
|
| 202 | - { |
|
| 203 | - // Cache this operation since it can take some time. |
|
| 204 | - if (is_null($this->fields)) { |
|
| 205 | - |
|
| 206 | - // Fetch all available fields first. |
|
| 207 | - $fields = $this->getAllFields(); |
|
| 208 | - |
|
| 209 | - if ($this->isBackendMode()) { |
|
| 210 | - |
|
| 211 | - // Then remove the not allowed. |
|
| 212 | - $fields = $this->filterByIncludedFields($fields); |
|
| 213 | - $fields = $this->filterByBackendUser($fields); |
|
| 214 | - $fields = $this->filterByExcludedFields($fields); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $this->fields = $fields; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return $this->fields; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Remove fields according to Grid configuration. |
|
| 225 | - * |
|
| 226 | - * @param $fields |
|
| 227 | - * @return array |
|
| 228 | - */ |
|
| 229 | - protected function filterByIncludedFields($fields) |
|
| 230 | - { |
|
| 231 | - |
|
| 232 | - $filteredFields = $fields; |
|
| 233 | - $includedFields = $this->getIncludedFields(); |
|
| 234 | - if (count($includedFields) > 0) { |
|
| 235 | - $filteredFields = []; |
|
| 236 | - foreach ($fields as $fieldNameAndPath => $configuration) { |
|
| 237 | - if (in_array($fieldNameAndPath, $includedFields, true) || !Tca::table($this->tableName)->hasField($fieldNameAndPath)) { |
|
| 238 | - $filteredFields[$fieldNameAndPath] = $configuration; |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - } |
|
| 242 | - return $filteredFields; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Remove fields according to BE User permission. |
|
| 247 | - * |
|
| 248 | - * @param $fields |
|
| 249 | - * @return array |
|
| 250 | - * @throws \Exception |
|
| 251 | - */ |
|
| 252 | - protected function filterByBackendUser($fields) |
|
| 253 | - { |
|
| 254 | - if (!$this->getBackendUser()->isAdmin()) { |
|
| 255 | - foreach ($fields as $fieldName => $field) { |
|
| 256 | - if (Tca::table($this->tableName)->hasField($fieldName) && !Tca::table($this->tableName)->field($fieldName)->hasAccess()) { |
|
| 257 | - unset($fields[$fieldName]); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - return $fields; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Remove fields according to Grid configuration. |
|
| 266 | - * |
|
| 267 | - * @param $fields |
|
| 268 | - * @return array |
|
| 269 | - */ |
|
| 270 | - protected function filterByExcludedFields($fields) |
|
| 271 | - { |
|
| 272 | - |
|
| 273 | - // Unset excluded fields. |
|
| 274 | - foreach ($this->getExcludedFields() as $excludedField) { |
|
| 275 | - if (isset($fields[$excludedField])) { |
|
| 276 | - unset($fields[$excludedField]); |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - return $fields; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - /** |
|
| 284 | - * Returns an array containing column names for the Grid. |
|
| 285 | - * |
|
| 286 | - * @return array |
|
| 287 | - */ |
|
| 288 | - public function getAllFields() |
|
| 289 | - { |
|
| 290 | - |
|
| 291 | - // Cache this operation since it can take some time. |
|
| 292 | - if (is_null($this->allFields)) { |
|
| 293 | - |
|
| 294 | - $fields = is_array($this->tca['columns']) ? $this->tca['columns'] : []; |
|
| 295 | - $gridFieldNames = array_keys($fields); |
|
| 296 | - |
|
| 297 | - // Fetch all fields of the TCA and merge it back to the fields configured for Grid. |
|
| 298 | - $tableFieldNames = Tca::table($this->tableName)->getFields(); |
|
| 299 | - |
|
| 300 | - // Just remove system fields from the Grid. |
|
| 301 | - foreach ($tableFieldNames as $key => $fieldName) { |
|
| 302 | - if (in_array($fieldName, Tca::getSystemFields())) { |
|
| 303 | - unset($tableFieldNames[$key]); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - $additionalFields = array_diff($tableFieldNames, $gridFieldNames); |
|
| 308 | - |
|
| 309 | - if (!empty($additionalFields)) { |
|
| 310 | - |
|
| 311 | - // Pop out last element of the key |
|
| 312 | - // Idea is to place new un-configured columns in between. By default, they will be hidden. |
|
| 313 | - end($fields); |
|
| 314 | - $lastColumnKey = key($fields); |
|
| 315 | - $lastColumn = array_pop($fields); |
|
| 316 | - |
|
| 317 | - // Feed up the grid fields with un configured elements |
|
| 318 | - foreach ($additionalFields as $additionalField) { |
|
| 319 | - $fields[$additionalField] = array( |
|
| 320 | - 'visible' => false |
|
| 321 | - ); |
|
| 322 | - |
|
| 323 | - // Try to guess the format of the field. |
|
| 324 | - $fieldType = Tca::table($this->tableName)->field($additionalField)->getType(); |
|
| 325 | - if ($fieldType === FieldType::DATE) { |
|
| 326 | - $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Date'; |
|
| 327 | - } elseif ($fieldType === FieldType::DATETIME) { |
|
| 328 | - $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Datetime'; |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - $fields[$lastColumnKey] = $lastColumn; |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - $this->allFields = $fields; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - return $this->allFields; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - /** |
|
| 341 | - * Tell whether the field exists in the grid or not. |
|
| 342 | - * |
|
| 343 | - * @param string $fieldName |
|
| 344 | - * @return bool |
|
| 345 | - */ |
|
| 346 | - public function hasField($fieldName) |
|
| 347 | - { |
|
| 348 | - $fields = $this->getFields(); |
|
| 349 | - return isset($fields[$fieldName]); |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Tell whether the facet exists in the grid or not. |
|
| 354 | - * |
|
| 355 | - * @param string $facetName |
|
| 356 | - * @return bool |
|
| 357 | - */ |
|
| 358 | - public function hasFacet($facetName) |
|
| 359 | - { |
|
| 360 | - $facets = $this->getFacets(); |
|
| 361 | - return isset($facets[$facetName]); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - /** |
|
| 365 | - * Returns an array containing facets fields. |
|
| 366 | - * |
|
| 367 | - * @return FacetInterface[] |
|
| 368 | - */ |
|
| 369 | - public function getFacets() |
|
| 370 | - { |
|
| 371 | - if (is_null($this->facets)) { |
|
| 372 | - $this->facets = []; |
|
| 373 | - |
|
| 374 | - if (is_array($this->tca['facets'])) { |
|
| 375 | - foreach ($this->tca['facets'] as $facetNameOrObject) { |
|
| 376 | - if ($facetNameOrObject instanceof FacetInterface) { |
|
| 377 | - $this->facets[$facetNameOrObject->getName()] = $facetNameOrObject; |
|
| 378 | - } else { |
|
| 379 | - $this->facets[$facetNameOrObject] = $this->instantiateStandardFacet($facetNameOrObject); |
|
| 380 | - } |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - return $this->facets; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Returns the "sortable" value of the column. |
|
| 389 | - * |
|
| 390 | - * @param string $fieldName |
|
| 391 | - * @return int|string |
|
| 392 | - */ |
|
| 393 | - public function isSortable($fieldName) |
|
| 394 | - { |
|
| 395 | - $defaultValue = true; |
|
| 396 | - $hasSortableField = Tca::table($this->tableName)->hasSortableField(); |
|
| 397 | - if ($hasSortableField) { |
|
| 398 | - $isSortable = false; |
|
| 399 | - } else { |
|
| 400 | - $isSortable = $this->get($fieldName, 'sortable', $defaultValue); |
|
| 401 | - } |
|
| 402 | - return $isSortable; |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * Returns the "canBeHidden" value of the column. |
|
| 407 | - * |
|
| 408 | - * @param string $fieldName |
|
| 409 | - * @return bool |
|
| 410 | - */ |
|
| 411 | - public function canBeHidden($fieldName) |
|
| 412 | - { |
|
| 413 | - $defaultValue = true; |
|
| 414 | - return $this->get($fieldName, 'canBeHidden', $defaultValue); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Returns the "width" value of the column. |
|
| 419 | - * |
|
| 420 | - * @param string $fieldName |
|
| 421 | - * @return int|string |
|
| 422 | - */ |
|
| 423 | - public function getWidth($fieldName) |
|
| 424 | - { |
|
| 425 | - $defaultValue = 'auto'; |
|
| 426 | - return $this->get($fieldName, 'width', $defaultValue); |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Returns the "visible" value of the column. |
|
| 431 | - * |
|
| 432 | - * @param string $fieldName |
|
| 433 | - * @return bool |
|
| 434 | - */ |
|
| 435 | - public function isVisible($fieldName) |
|
| 436 | - { |
|
| 437 | - $defaultValue = true; |
|
| 438 | - return $this->get($fieldName, 'visible', $defaultValue); |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - /** |
|
| 442 | - * Returns the "editable" value of the column. |
|
| 443 | - * |
|
| 444 | - * @param string $columnName |
|
| 445 | - * @return bool |
|
| 446 | - */ |
|
| 447 | - public function isEditable($columnName) |
|
| 448 | - { |
|
| 449 | - $defaultValue = false; |
|
| 450 | - return $this->get($columnName, 'editable', $defaultValue); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Returns the "localized" value of the column. |
|
| 455 | - * |
|
| 456 | - * @param string $columnName |
|
| 457 | - * @return bool |
|
| 458 | - */ |
|
| 459 | - public function isLocalized($columnName) |
|
| 460 | - { |
|
| 461 | - $defaultValue = true; |
|
| 462 | - return $this->get($columnName, 'localized', $defaultValue); |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * |
|
| 467 | - * Returns the "html" value of the column. |
|
| 468 | - * |
|
| 469 | - * @param string $fieldName |
|
| 470 | - * @return string |
|
| 471 | - */ |
|
| 472 | - public function getHeader($fieldName) |
|
| 473 | - { |
|
| 474 | - $defaultValue = ''; |
|
| 475 | - return $this->get($fieldName, 'html', $defaultValue); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Fetch a possible from a Grid Renderer. If no value is found, returns null |
|
| 480 | - * |
|
| 481 | - * @param string $fieldName |
|
| 482 | - * @param string $key |
|
| 483 | - * @param mixed $defaultValue |
|
| 484 | - * @return null|mixed |
|
| 485 | - */ |
|
| 486 | - public function get($fieldName, $key, $defaultValue = null) |
|
| 487 | - { |
|
| 488 | - $value = $defaultValue; |
|
| 489 | - |
|
| 490 | - $field = $this->getField($fieldName); |
|
| 491 | - if (isset($field[$key])) { |
|
| 492 | - $value = $field[$key]; |
|
| 493 | - } elseif ($this->hasRenderers($fieldName)) { |
|
| 494 | - $renderers = $this->getRenderers($fieldName); |
|
| 495 | - foreach ($renderers as $rendererConfiguration) { |
|
| 496 | - if (isset($rendererConfiguration[$key])) { |
|
| 497 | - $value = $rendererConfiguration[$key]; |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - return $value; |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * Returns whether the column has a renderer. |
|
| 506 | - * |
|
| 507 | - * @param string $fieldName |
|
| 508 | - * @return bool |
|
| 509 | - */ |
|
| 510 | - public function hasRenderers($fieldName) |
|
| 511 | - { |
|
| 512 | - $field = $this->getField($fieldName); |
|
| 513 | - return empty($field['renderer']) && empty($field['renderers']) ? false : true; |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - /** |
|
| 517 | - * Returns a renderer. |
|
| 518 | - * |
|
| 519 | - * @param string $fieldName |
|
| 520 | - * @return array |
|
| 521 | - */ |
|
| 522 | - public function getRenderers($fieldName) |
|
| 523 | - { |
|
| 524 | - $field = $this->getField($fieldName); |
|
| 525 | - $renderers = []; |
|
| 526 | - if (!empty($field['renderer'])) { |
|
| 527 | - $renderers = $this->convertRendererToArray($field['renderer']); |
|
| 528 | - } elseif (!empty($field['renderers']) && is_array($field['renderers'])) { |
|
| 529 | - foreach ($field['renderers'] as $renderer) { |
|
| 530 | - $rendererNameAndConfiguration = $this->convertRendererToArray($renderer); |
|
| 531 | - $renderers = array_merge($renderers, $rendererNameAndConfiguration); |
|
| 532 | - } |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - return $renderers; |
|
| 536 | - } |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * @param string|GenericColumn $renderer |
|
| 540 | - * @return array |
|
| 541 | - */ |
|
| 542 | - public function convertRendererToArray($renderer) |
|
| 543 | - { |
|
| 544 | - $result = []; |
|
| 545 | - if (is_string($renderer)) { |
|
| 546 | - $result[$renderer] = []; |
|
| 547 | - } elseif ($renderer instanceof ColumnInterface || $renderer instanceof ColumnRendererInterface) { |
|
| 548 | - /** @var GenericColumn $renderer */ |
|
| 549 | - $result[get_class($renderer)] = $renderer->getConfiguration(); |
|
| 550 | - } |
|
| 551 | - return $result; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Returns the class names applied to a cell |
|
| 556 | - * |
|
| 557 | - * @param string $fieldName |
|
| 558 | - * @return bool |
|
| 559 | - */ |
|
| 560 | - public function getClass($fieldName) |
|
| 561 | - { |
|
| 562 | - $field = $this->getField($fieldName); |
|
| 563 | - return isset($field['class']) ? $field['class'] : ''; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Returns whether the column has a label. |
|
| 568 | - * |
|
| 569 | - * @param string $fieldNameAndPath |
|
| 570 | - * @return bool |
|
| 571 | - */ |
|
| 572 | - public function hasLabel($fieldNameAndPath) |
|
| 573 | - { |
|
| 574 | - $field = $this->getField($fieldNameAndPath); |
|
| 575 | - |
|
| 576 | - $hasLabel = empty($field['label']) ? false : true; |
|
| 577 | - |
|
| 578 | - if (!$hasLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
| 579 | - $renderers = $this->getRenderers($fieldNameAndPath); |
|
| 580 | - /** @var $renderer ColumnRendererInterface */ |
|
| 581 | - foreach ($renderers as $renderer) { |
|
| 582 | - if (isset($renderer['label'])) { |
|
| 583 | - $hasLabel = true; |
|
| 584 | - break; |
|
| 585 | - } |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - return $hasLabel; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - /** |
|
| 592 | - * @return array |
|
| 593 | - */ |
|
| 594 | - public function getTca() |
|
| 595 | - { |
|
| 596 | - return $this->tca; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * @return array |
|
| 601 | - */ |
|
| 602 | - public function getIncludedFields() |
|
| 603 | - { |
|
| 604 | - return empty($this->tca['included_fields']) ? [] : GeneralUtility::trimExplode(',', $this->tca['included_fields'], true); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * Return excluded fields from configuration + preferences. |
|
| 609 | - * |
|
| 610 | - * @return array |
|
| 611 | - */ |
|
| 612 | - public function getExcludedFields() |
|
| 613 | - { |
|
| 614 | - $configurationFields = $this->getExcludedFieldsFromConfiguration(); |
|
| 615 | - $preferencesFields = $this->getExcludedFieldsFromPreferences(); |
|
| 616 | - |
|
| 617 | - return array_merge($configurationFields, $preferencesFields); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - /** |
|
| 621 | - * Fetch excluded fields from configuration. |
|
| 622 | - * |
|
| 623 | - * @return array |
|
| 624 | - */ |
|
| 625 | - protected function getExcludedFieldsFromConfiguration() |
|
| 626 | - { |
|
| 627 | - $excludedFields = []; |
|
| 628 | - if (!empty($this->tca['excluded_fields'])) { |
|
| 629 | - $excludedFields = GeneralUtility::trimExplode(',', $this->tca['excluded_fields'], true); |
|
| 630 | - } elseif (!empty($this->tca['export']['excluded_fields'])) { // only for export for legacy reason. |
|
| 631 | - $excludedFields = GeneralUtility::trimExplode(',', $this->tca['export']['excluded_fields'], true); |
|
| 632 | - } |
|
| 633 | - return $excludedFields; |
|
| 634 | - |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - /** |
|
| 638 | - * Fetch excluded fields from preferences. |
|
| 639 | - * |
|
| 640 | - * @return array |
|
| 641 | - */ |
|
| 642 | - protected function getExcludedFieldsFromPreferences() |
|
| 643 | - { |
|
| 644 | - $excludedFields = $this->getModulePreferences()->get(ConfigurablePart::EXCLUDED_FIELDS, $this->tableName); |
|
| 645 | - return is_array($excludedFields) ? $excludedFields : []; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * @return array |
|
| 650 | - */ |
|
| 651 | - public function areFilesIncludedInExport() |
|
| 652 | - { |
|
| 653 | - $isIncluded = true; |
|
| 654 | - |
|
| 655 | - if (isset($this->tca['export']['include_files'])) { |
|
| 656 | - $isIncluded = $this->tca['export']['include_files']; |
|
| 657 | - } |
|
| 658 | - return $isIncluded; |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - /** |
|
| 662 | - * Returns a "facet" service instance. |
|
| 663 | - * |
|
| 664 | - * @param string|FacetInterface $facetName |
|
| 665 | - * @return StandardFacet |
|
| 666 | - */ |
|
| 667 | - protected function instantiateStandardFacet($facetName) |
|
| 668 | - { |
|
| 669 | - $label = $this->getLabel($facetName); |
|
| 670 | - |
|
| 671 | - /** @var StandardFacet $facetName */ |
|
| 672 | - $facet = GeneralUtility::makeInstance('Fab\Vidi\Facet\StandardFacet', $facetName, $label); |
|
| 673 | - |
|
| 674 | - if (!$facet instanceof StandardFacet) { |
|
| 675 | - throw new \RuntimeException('I could not instantiate a facet for facet name "' . (string)$facet . '""', 1445856345); |
|
| 676 | - } |
|
| 677 | - return $facet; |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * Returns a "facet" service instance. |
|
| 682 | - * |
|
| 683 | - * @param string|FacetInterface $facetName |
|
| 684 | - * @return FacetInterface |
|
| 685 | - */ |
|
| 686 | - public function facet($facetName = '') |
|
| 687 | - { |
|
| 688 | - $facets = $this->getFacets(); |
|
| 689 | - return $facets[$facetName]; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - /** |
|
| 693 | - * @return \Fab\Vidi\Resolver\FieldPathResolver |
|
| 694 | - */ |
|
| 695 | - protected function getFieldPathResolver() |
|
| 696 | - { |
|
| 697 | - return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver'); |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - /** |
|
| 701 | - * @return ModulePreferences |
|
| 702 | - */ |
|
| 703 | - protected function getModulePreferences() |
|
| 704 | - { |
|
| 705 | - return GeneralUtility::makeInstance('Fab\Vidi\Module\ModulePreferences'); |
|
| 706 | - } |
|
| 28 | + /** |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $tca; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + protected $tableName; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * All fields available in the Grid. |
|
| 40 | + * |
|
| 41 | + * @var array |
|
| 42 | + */ |
|
| 43 | + protected $fields; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * All fields regardless whether they have been excluded or not. |
|
| 47 | + * |
|
| 48 | + * @var array |
|
| 49 | + */ |
|
| 50 | + protected $allFields; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + protected $instances; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var array |
|
| 59 | + */ |
|
| 60 | + protected $facets; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * __construct |
|
| 64 | + * |
|
| 65 | + * @throws InvalidKeyInArrayException |
|
| 66 | + * @param string $tableName |
|
| 67 | + * @return \Fab\Vidi\Tca\GridService |
|
| 68 | + */ |
|
| 69 | + public function __construct($tableName) |
|
| 70 | + { |
|
| 71 | + |
|
| 72 | + $this->tableName = $tableName; |
|
| 73 | + |
|
| 74 | + if (empty($GLOBALS['TCA'][$this->tableName])) { |
|
| 75 | + throw new InvalidKeyInArrayException('No TCA existence for table name: ' . $this->tableName, 1356945108); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $this->tca = $GLOBALS['TCA'][$this->tableName]['grid']; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Returns an array containing column names. |
|
| 83 | + * |
|
| 84 | + * @return array |
|
| 85 | + */ |
|
| 86 | + public function getFieldNames() |
|
| 87 | + { |
|
| 88 | + $fields = $this->getFields(); |
|
| 89 | + return array_keys($fields); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Returns an array containing column names. |
|
| 94 | + * |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + public function getAllFieldNames() |
|
| 98 | + { |
|
| 99 | + $allFields = $this->getAllFields(); |
|
| 100 | + return array_keys($allFields); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Get the label key. |
|
| 105 | + * |
|
| 106 | + * @param string $fieldNameAndPath |
|
| 107 | + * @return string |
|
| 108 | + * @throws \Fab\Vidi\Exception\InvalidKeyInArrayException |
|
| 109 | + */ |
|
| 110 | + public function getLabelKey($fieldNameAndPath) |
|
| 111 | + { |
|
| 112 | + |
|
| 113 | + $field = $this->getField($fieldNameAndPath); |
|
| 114 | + |
|
| 115 | + // First option is to get the label from the Grid TCA. |
|
| 116 | + $rawLabel = ''; |
|
| 117 | + if (isset($field['label'])) { |
|
| 118 | + $rawLabel = $field['label']; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // Second option is to fetch the label from the Column Renderer object. |
|
| 122 | + if (!$rawLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
| 123 | + $renderers = $this->getRenderers($fieldNameAndPath); |
|
| 124 | + /** @var $renderer ColumnRendererInterface */ |
|
| 125 | + foreach ($renderers as $renderer) { |
|
| 126 | + if (isset($renderer['label'])) { |
|
| 127 | + $rawLabel = $renderer['label']; |
|
| 128 | + break; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + return $rawLabel; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Get the translation of a label given a column name. |
|
| 137 | + * |
|
| 138 | + * @param string $fieldNameAndPath |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + public function getLabel($fieldNameAndPath) |
|
| 142 | + { |
|
| 143 | + $label = ''; |
|
| 144 | + if ($this->hasLabel($fieldNameAndPath)) { |
|
| 145 | + $labelKey = $this->getLabelKey($fieldNameAndPath); |
|
| 146 | + $label = LocalizationUtility::translate($labelKey, ''); |
|
| 147 | + if (is_null($label)) { |
|
| 148 | + $label = $labelKey; |
|
| 149 | + } |
|
| 150 | + } else { |
|
| 151 | + |
|
| 152 | + // Important to notice the label can contains a path, e.g. metadata.categories and must be resolved. |
|
| 153 | + $dataType = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->tableName); |
|
| 154 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $this->tableName); |
|
| 155 | + $table = Tca::table($dataType); |
|
| 156 | + |
|
| 157 | + if ($table->hasField($fieldName) && $table->field($fieldName)->hasLabel()) { |
|
| 158 | + $label = $table->field($fieldName)->getLabel(); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + return $label; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Returns the field name given its position. |
|
| 167 | + * |
|
| 168 | + * @param string $position the position of the field in the grid |
|
| 169 | + * @throws InvalidKeyInArrayException |
|
| 170 | + * @return int |
|
| 171 | + */ |
|
| 172 | + public function getFieldNameByPosition($position) |
|
| 173 | + { |
|
| 174 | + $fields = array_keys($this->getFields()); |
|
| 175 | + if (empty($fields[$position])) { |
|
| 176 | + throw new InvalidKeyInArrayException('No field exist for position: ' . $position, 1356945119); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return $fields[$position]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Returns a field name. |
|
| 184 | + * |
|
| 185 | + * @param string $fieldName |
|
| 186 | + * @return array |
|
| 187 | + * @throws InvalidKeyInArrayException |
|
| 188 | + */ |
|
| 189 | + public function getField($fieldName) |
|
| 190 | + { |
|
| 191 | + $fields = $this->getFields(); |
|
| 192 | + return $fields[$fieldName]; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Returns an array containing column names for the Grid. |
|
| 197 | + * |
|
| 198 | + * @return array |
|
| 199 | + * @throws \Exception |
|
| 200 | + */ |
|
| 201 | + public function getFields() |
|
| 202 | + { |
|
| 203 | + // Cache this operation since it can take some time. |
|
| 204 | + if (is_null($this->fields)) { |
|
| 205 | + |
|
| 206 | + // Fetch all available fields first. |
|
| 207 | + $fields = $this->getAllFields(); |
|
| 208 | + |
|
| 209 | + if ($this->isBackendMode()) { |
|
| 210 | + |
|
| 211 | + // Then remove the not allowed. |
|
| 212 | + $fields = $this->filterByIncludedFields($fields); |
|
| 213 | + $fields = $this->filterByBackendUser($fields); |
|
| 214 | + $fields = $this->filterByExcludedFields($fields); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $this->fields = $fields; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return $this->fields; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Remove fields according to Grid configuration. |
|
| 225 | + * |
|
| 226 | + * @param $fields |
|
| 227 | + * @return array |
|
| 228 | + */ |
|
| 229 | + protected function filterByIncludedFields($fields) |
|
| 230 | + { |
|
| 231 | + |
|
| 232 | + $filteredFields = $fields; |
|
| 233 | + $includedFields = $this->getIncludedFields(); |
|
| 234 | + if (count($includedFields) > 0) { |
|
| 235 | + $filteredFields = []; |
|
| 236 | + foreach ($fields as $fieldNameAndPath => $configuration) { |
|
| 237 | + if (in_array($fieldNameAndPath, $includedFields, true) || !Tca::table($this->tableName)->hasField($fieldNameAndPath)) { |
|
| 238 | + $filteredFields[$fieldNameAndPath] = $configuration; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | + return $filteredFields; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Remove fields according to BE User permission. |
|
| 247 | + * |
|
| 248 | + * @param $fields |
|
| 249 | + * @return array |
|
| 250 | + * @throws \Exception |
|
| 251 | + */ |
|
| 252 | + protected function filterByBackendUser($fields) |
|
| 253 | + { |
|
| 254 | + if (!$this->getBackendUser()->isAdmin()) { |
|
| 255 | + foreach ($fields as $fieldName => $field) { |
|
| 256 | + if (Tca::table($this->tableName)->hasField($fieldName) && !Tca::table($this->tableName)->field($fieldName)->hasAccess()) { |
|
| 257 | + unset($fields[$fieldName]); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + return $fields; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Remove fields according to Grid configuration. |
|
| 266 | + * |
|
| 267 | + * @param $fields |
|
| 268 | + * @return array |
|
| 269 | + */ |
|
| 270 | + protected function filterByExcludedFields($fields) |
|
| 271 | + { |
|
| 272 | + |
|
| 273 | + // Unset excluded fields. |
|
| 274 | + foreach ($this->getExcludedFields() as $excludedField) { |
|
| 275 | + if (isset($fields[$excludedField])) { |
|
| 276 | + unset($fields[$excludedField]); |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + return $fields; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + /** |
|
| 284 | + * Returns an array containing column names for the Grid. |
|
| 285 | + * |
|
| 286 | + * @return array |
|
| 287 | + */ |
|
| 288 | + public function getAllFields() |
|
| 289 | + { |
|
| 290 | + |
|
| 291 | + // Cache this operation since it can take some time. |
|
| 292 | + if (is_null($this->allFields)) { |
|
| 293 | + |
|
| 294 | + $fields = is_array($this->tca['columns']) ? $this->tca['columns'] : []; |
|
| 295 | + $gridFieldNames = array_keys($fields); |
|
| 296 | + |
|
| 297 | + // Fetch all fields of the TCA and merge it back to the fields configured for Grid. |
|
| 298 | + $tableFieldNames = Tca::table($this->tableName)->getFields(); |
|
| 299 | + |
|
| 300 | + // Just remove system fields from the Grid. |
|
| 301 | + foreach ($tableFieldNames as $key => $fieldName) { |
|
| 302 | + if (in_array($fieldName, Tca::getSystemFields())) { |
|
| 303 | + unset($tableFieldNames[$key]); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + $additionalFields = array_diff($tableFieldNames, $gridFieldNames); |
|
| 308 | + |
|
| 309 | + if (!empty($additionalFields)) { |
|
| 310 | + |
|
| 311 | + // Pop out last element of the key |
|
| 312 | + // Idea is to place new un-configured columns in between. By default, they will be hidden. |
|
| 313 | + end($fields); |
|
| 314 | + $lastColumnKey = key($fields); |
|
| 315 | + $lastColumn = array_pop($fields); |
|
| 316 | + |
|
| 317 | + // Feed up the grid fields with un configured elements |
|
| 318 | + foreach ($additionalFields as $additionalField) { |
|
| 319 | + $fields[$additionalField] = array( |
|
| 320 | + 'visible' => false |
|
| 321 | + ); |
|
| 322 | + |
|
| 323 | + // Try to guess the format of the field. |
|
| 324 | + $fieldType = Tca::table($this->tableName)->field($additionalField)->getType(); |
|
| 325 | + if ($fieldType === FieldType::DATE) { |
|
| 326 | + $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Date'; |
|
| 327 | + } elseif ($fieldType === FieldType::DATETIME) { |
|
| 328 | + $fields[$additionalField]['format'] = 'Fab\Vidi\Formatter\Datetime'; |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + $fields[$lastColumnKey] = $lastColumn; |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + $this->allFields = $fields; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + return $this->allFields; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + /** |
|
| 341 | + * Tell whether the field exists in the grid or not. |
|
| 342 | + * |
|
| 343 | + * @param string $fieldName |
|
| 344 | + * @return bool |
|
| 345 | + */ |
|
| 346 | + public function hasField($fieldName) |
|
| 347 | + { |
|
| 348 | + $fields = $this->getFields(); |
|
| 349 | + return isset($fields[$fieldName]); |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Tell whether the facet exists in the grid or not. |
|
| 354 | + * |
|
| 355 | + * @param string $facetName |
|
| 356 | + * @return bool |
|
| 357 | + */ |
|
| 358 | + public function hasFacet($facetName) |
|
| 359 | + { |
|
| 360 | + $facets = $this->getFacets(); |
|
| 361 | + return isset($facets[$facetName]); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + /** |
|
| 365 | + * Returns an array containing facets fields. |
|
| 366 | + * |
|
| 367 | + * @return FacetInterface[] |
|
| 368 | + */ |
|
| 369 | + public function getFacets() |
|
| 370 | + { |
|
| 371 | + if (is_null($this->facets)) { |
|
| 372 | + $this->facets = []; |
|
| 373 | + |
|
| 374 | + if (is_array($this->tca['facets'])) { |
|
| 375 | + foreach ($this->tca['facets'] as $facetNameOrObject) { |
|
| 376 | + if ($facetNameOrObject instanceof FacetInterface) { |
|
| 377 | + $this->facets[$facetNameOrObject->getName()] = $facetNameOrObject; |
|
| 378 | + } else { |
|
| 379 | + $this->facets[$facetNameOrObject] = $this->instantiateStandardFacet($facetNameOrObject); |
|
| 380 | + } |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + return $this->facets; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Returns the "sortable" value of the column. |
|
| 389 | + * |
|
| 390 | + * @param string $fieldName |
|
| 391 | + * @return int|string |
|
| 392 | + */ |
|
| 393 | + public function isSortable($fieldName) |
|
| 394 | + { |
|
| 395 | + $defaultValue = true; |
|
| 396 | + $hasSortableField = Tca::table($this->tableName)->hasSortableField(); |
|
| 397 | + if ($hasSortableField) { |
|
| 398 | + $isSortable = false; |
|
| 399 | + } else { |
|
| 400 | + $isSortable = $this->get($fieldName, 'sortable', $defaultValue); |
|
| 401 | + } |
|
| 402 | + return $isSortable; |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * Returns the "canBeHidden" value of the column. |
|
| 407 | + * |
|
| 408 | + * @param string $fieldName |
|
| 409 | + * @return bool |
|
| 410 | + */ |
|
| 411 | + public function canBeHidden($fieldName) |
|
| 412 | + { |
|
| 413 | + $defaultValue = true; |
|
| 414 | + return $this->get($fieldName, 'canBeHidden', $defaultValue); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Returns the "width" value of the column. |
|
| 419 | + * |
|
| 420 | + * @param string $fieldName |
|
| 421 | + * @return int|string |
|
| 422 | + */ |
|
| 423 | + public function getWidth($fieldName) |
|
| 424 | + { |
|
| 425 | + $defaultValue = 'auto'; |
|
| 426 | + return $this->get($fieldName, 'width', $defaultValue); |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Returns the "visible" value of the column. |
|
| 431 | + * |
|
| 432 | + * @param string $fieldName |
|
| 433 | + * @return bool |
|
| 434 | + */ |
|
| 435 | + public function isVisible($fieldName) |
|
| 436 | + { |
|
| 437 | + $defaultValue = true; |
|
| 438 | + return $this->get($fieldName, 'visible', $defaultValue); |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + /** |
|
| 442 | + * Returns the "editable" value of the column. |
|
| 443 | + * |
|
| 444 | + * @param string $columnName |
|
| 445 | + * @return bool |
|
| 446 | + */ |
|
| 447 | + public function isEditable($columnName) |
|
| 448 | + { |
|
| 449 | + $defaultValue = false; |
|
| 450 | + return $this->get($columnName, 'editable', $defaultValue); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Returns the "localized" value of the column. |
|
| 455 | + * |
|
| 456 | + * @param string $columnName |
|
| 457 | + * @return bool |
|
| 458 | + */ |
|
| 459 | + public function isLocalized($columnName) |
|
| 460 | + { |
|
| 461 | + $defaultValue = true; |
|
| 462 | + return $this->get($columnName, 'localized', $defaultValue); |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * |
|
| 467 | + * Returns the "html" value of the column. |
|
| 468 | + * |
|
| 469 | + * @param string $fieldName |
|
| 470 | + * @return string |
|
| 471 | + */ |
|
| 472 | + public function getHeader($fieldName) |
|
| 473 | + { |
|
| 474 | + $defaultValue = ''; |
|
| 475 | + return $this->get($fieldName, 'html', $defaultValue); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Fetch a possible from a Grid Renderer. If no value is found, returns null |
|
| 480 | + * |
|
| 481 | + * @param string $fieldName |
|
| 482 | + * @param string $key |
|
| 483 | + * @param mixed $defaultValue |
|
| 484 | + * @return null|mixed |
|
| 485 | + */ |
|
| 486 | + public function get($fieldName, $key, $defaultValue = null) |
|
| 487 | + { |
|
| 488 | + $value = $defaultValue; |
|
| 489 | + |
|
| 490 | + $field = $this->getField($fieldName); |
|
| 491 | + if (isset($field[$key])) { |
|
| 492 | + $value = $field[$key]; |
|
| 493 | + } elseif ($this->hasRenderers($fieldName)) { |
|
| 494 | + $renderers = $this->getRenderers($fieldName); |
|
| 495 | + foreach ($renderers as $rendererConfiguration) { |
|
| 496 | + if (isset($rendererConfiguration[$key])) { |
|
| 497 | + $value = $rendererConfiguration[$key]; |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + return $value; |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * Returns whether the column has a renderer. |
|
| 506 | + * |
|
| 507 | + * @param string $fieldName |
|
| 508 | + * @return bool |
|
| 509 | + */ |
|
| 510 | + public function hasRenderers($fieldName) |
|
| 511 | + { |
|
| 512 | + $field = $this->getField($fieldName); |
|
| 513 | + return empty($field['renderer']) && empty($field['renderers']) ? false : true; |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + /** |
|
| 517 | + * Returns a renderer. |
|
| 518 | + * |
|
| 519 | + * @param string $fieldName |
|
| 520 | + * @return array |
|
| 521 | + */ |
|
| 522 | + public function getRenderers($fieldName) |
|
| 523 | + { |
|
| 524 | + $field = $this->getField($fieldName); |
|
| 525 | + $renderers = []; |
|
| 526 | + if (!empty($field['renderer'])) { |
|
| 527 | + $renderers = $this->convertRendererToArray($field['renderer']); |
|
| 528 | + } elseif (!empty($field['renderers']) && is_array($field['renderers'])) { |
|
| 529 | + foreach ($field['renderers'] as $renderer) { |
|
| 530 | + $rendererNameAndConfiguration = $this->convertRendererToArray($renderer); |
|
| 531 | + $renderers = array_merge($renderers, $rendererNameAndConfiguration); |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + return $renderers; |
|
| 536 | + } |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * @param string|GenericColumn $renderer |
|
| 540 | + * @return array |
|
| 541 | + */ |
|
| 542 | + public function convertRendererToArray($renderer) |
|
| 543 | + { |
|
| 544 | + $result = []; |
|
| 545 | + if (is_string($renderer)) { |
|
| 546 | + $result[$renderer] = []; |
|
| 547 | + } elseif ($renderer instanceof ColumnInterface || $renderer instanceof ColumnRendererInterface) { |
|
| 548 | + /** @var GenericColumn $renderer */ |
|
| 549 | + $result[get_class($renderer)] = $renderer->getConfiguration(); |
|
| 550 | + } |
|
| 551 | + return $result; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Returns the class names applied to a cell |
|
| 556 | + * |
|
| 557 | + * @param string $fieldName |
|
| 558 | + * @return bool |
|
| 559 | + */ |
|
| 560 | + public function getClass($fieldName) |
|
| 561 | + { |
|
| 562 | + $field = $this->getField($fieldName); |
|
| 563 | + return isset($field['class']) ? $field['class'] : ''; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Returns whether the column has a label. |
|
| 568 | + * |
|
| 569 | + * @param string $fieldNameAndPath |
|
| 570 | + * @return bool |
|
| 571 | + */ |
|
| 572 | + public function hasLabel($fieldNameAndPath) |
|
| 573 | + { |
|
| 574 | + $field = $this->getField($fieldNameAndPath); |
|
| 575 | + |
|
| 576 | + $hasLabel = empty($field['label']) ? false : true; |
|
| 577 | + |
|
| 578 | + if (!$hasLabel && $this->hasRenderers($fieldNameAndPath)) { |
|
| 579 | + $renderers = $this->getRenderers($fieldNameAndPath); |
|
| 580 | + /** @var $renderer ColumnRendererInterface */ |
|
| 581 | + foreach ($renderers as $renderer) { |
|
| 582 | + if (isset($renderer['label'])) { |
|
| 583 | + $hasLabel = true; |
|
| 584 | + break; |
|
| 585 | + } |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + return $hasLabel; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + /** |
|
| 592 | + * @return array |
|
| 593 | + */ |
|
| 594 | + public function getTca() |
|
| 595 | + { |
|
| 596 | + return $this->tca; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * @return array |
|
| 601 | + */ |
|
| 602 | + public function getIncludedFields() |
|
| 603 | + { |
|
| 604 | + return empty($this->tca['included_fields']) ? [] : GeneralUtility::trimExplode(',', $this->tca['included_fields'], true); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * Return excluded fields from configuration + preferences. |
|
| 609 | + * |
|
| 610 | + * @return array |
|
| 611 | + */ |
|
| 612 | + public function getExcludedFields() |
|
| 613 | + { |
|
| 614 | + $configurationFields = $this->getExcludedFieldsFromConfiguration(); |
|
| 615 | + $preferencesFields = $this->getExcludedFieldsFromPreferences(); |
|
| 616 | + |
|
| 617 | + return array_merge($configurationFields, $preferencesFields); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + /** |
|
| 621 | + * Fetch excluded fields from configuration. |
|
| 622 | + * |
|
| 623 | + * @return array |
|
| 624 | + */ |
|
| 625 | + protected function getExcludedFieldsFromConfiguration() |
|
| 626 | + { |
|
| 627 | + $excludedFields = []; |
|
| 628 | + if (!empty($this->tca['excluded_fields'])) { |
|
| 629 | + $excludedFields = GeneralUtility::trimExplode(',', $this->tca['excluded_fields'], true); |
|
| 630 | + } elseif (!empty($this->tca['export']['excluded_fields'])) { // only for export for legacy reason. |
|
| 631 | + $excludedFields = GeneralUtility::trimExplode(',', $this->tca['export']['excluded_fields'], true); |
|
| 632 | + } |
|
| 633 | + return $excludedFields; |
|
| 634 | + |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + /** |
|
| 638 | + * Fetch excluded fields from preferences. |
|
| 639 | + * |
|
| 640 | + * @return array |
|
| 641 | + */ |
|
| 642 | + protected function getExcludedFieldsFromPreferences() |
|
| 643 | + { |
|
| 644 | + $excludedFields = $this->getModulePreferences()->get(ConfigurablePart::EXCLUDED_FIELDS, $this->tableName); |
|
| 645 | + return is_array($excludedFields) ? $excludedFields : []; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * @return array |
|
| 650 | + */ |
|
| 651 | + public function areFilesIncludedInExport() |
|
| 652 | + { |
|
| 653 | + $isIncluded = true; |
|
| 654 | + |
|
| 655 | + if (isset($this->tca['export']['include_files'])) { |
|
| 656 | + $isIncluded = $this->tca['export']['include_files']; |
|
| 657 | + } |
|
| 658 | + return $isIncluded; |
|
| 659 | + } |
|
| 660 | + |
|
| 661 | + /** |
|
| 662 | + * Returns a "facet" service instance. |
|
| 663 | + * |
|
| 664 | + * @param string|FacetInterface $facetName |
|
| 665 | + * @return StandardFacet |
|
| 666 | + */ |
|
| 667 | + protected function instantiateStandardFacet($facetName) |
|
| 668 | + { |
|
| 669 | + $label = $this->getLabel($facetName); |
|
| 670 | + |
|
| 671 | + /** @var StandardFacet $facetName */ |
|
| 672 | + $facet = GeneralUtility::makeInstance('Fab\Vidi\Facet\StandardFacet', $facetName, $label); |
|
| 673 | + |
|
| 674 | + if (!$facet instanceof StandardFacet) { |
|
| 675 | + throw new \RuntimeException('I could not instantiate a facet for facet name "' . (string)$facet . '""', 1445856345); |
|
| 676 | + } |
|
| 677 | + return $facet; |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * Returns a "facet" service instance. |
|
| 682 | + * |
|
| 683 | + * @param string|FacetInterface $facetName |
|
| 684 | + * @return FacetInterface |
|
| 685 | + */ |
|
| 686 | + public function facet($facetName = '') |
|
| 687 | + { |
|
| 688 | + $facets = $this->getFacets(); |
|
| 689 | + return $facets[$facetName]; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + /** |
|
| 693 | + * @return \Fab\Vidi\Resolver\FieldPathResolver |
|
| 694 | + */ |
|
| 695 | + protected function getFieldPathResolver() |
|
| 696 | + { |
|
| 697 | + return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver'); |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + /** |
|
| 701 | + * @return ModulePreferences |
|
| 702 | + */ |
|
| 703 | + protected function getModulePreferences() |
|
| 704 | + { |
|
| 705 | + return GeneralUtility::makeInstance('Fab\Vidi\Module\ModulePreferences'); |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | 708 | } |
@@ -17,753 +17,753 @@ |
||
| 17 | 17 | class FieldService extends AbstractTca |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - protected $fieldName; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - protected $compositeField; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var string |
|
| 32 | - */ |
|
| 33 | - protected $tableName; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var array |
|
| 37 | - */ |
|
| 38 | - protected $tca; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @param string $fieldName |
|
| 42 | - * @param array $tca |
|
| 43 | - * @param string $tableName |
|
| 44 | - * @param string $compositeField |
|
| 45 | - * @return \Fab\Vidi\Tca\FieldService |
|
| 46 | - */ |
|
| 47 | - public function __construct($fieldName, array $tca, $tableName, $compositeField = '') |
|
| 48 | - { |
|
| 49 | - $this->fieldName = $fieldName; |
|
| 50 | - $this->tca = $tca; |
|
| 51 | - $this->tableName = $tableName; |
|
| 52 | - $this->compositeField = $compositeField; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Tells whether the field is considered as system field, e.g. uid, crdate, tstamp, etc... |
|
| 57 | - * |
|
| 58 | - * @return bool |
|
| 59 | - */ |
|
| 60 | - public function isSystem() |
|
| 61 | - { |
|
| 62 | - return in_array($this->fieldName, Tca::getSystemFields()); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Tells the opposition of isSystem() |
|
| 67 | - * |
|
| 68 | - * @return bool |
|
| 69 | - */ |
|
| 70 | - public function isNotSystem() |
|
| 71 | - { |
|
| 72 | - return !$this->isSystem(); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Returns the configuration for a $field |
|
| 77 | - * |
|
| 78 | - * @throws \Exception |
|
| 79 | - * @return array |
|
| 80 | - */ |
|
| 81 | - public function getConfiguration() |
|
| 82 | - { |
|
| 83 | - return empty($this->tca['config']) ? [] : $this->tca['config']; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Returns a key of the configuration. |
|
| 88 | - * If the key can not to be found, returns null. |
|
| 89 | - * |
|
| 90 | - * @param string $key |
|
| 91 | - * @return mixed |
|
| 92 | - */ |
|
| 93 | - public function get($key) |
|
| 94 | - { |
|
| 95 | - $configuration = $this->getConfiguration(); |
|
| 96 | - return empty($configuration[$key]) ? null : $configuration[$key]; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Returns the foreign field of a given field (opposite relational field). |
|
| 101 | - * If no relation exists, returns null. |
|
| 102 | - * |
|
| 103 | - * @return string|null |
|
| 104 | - */ |
|
| 105 | - public function getForeignField() |
|
| 106 | - { |
|
| 107 | - $result = null; |
|
| 108 | - $configuration = $this->getConfiguration(); |
|
| 109 | - |
|
| 110 | - if (!empty($configuration['foreign_field'])) { |
|
| 111 | - $result = $configuration['foreign_field']; |
|
| 112 | - } elseif ($this->hasRelationManyToMany()) { |
|
| 113 | - |
|
| 114 | - $foreignTable = $this->getForeignTable(); |
|
| 115 | - $manyToManyTable = $this->getManyToManyTable(); |
|
| 116 | - |
|
| 117 | - // Load TCA service of foreign field. |
|
| 118 | - $tcaForeignTableService = Tca::table($foreignTable); |
|
| 119 | - |
|
| 120 | - // Look into the MM relations checking for the opposite field |
|
| 121 | - foreach ($tcaForeignTableService->getFields() as $fieldName) { |
|
| 122 | - if ($manyToManyTable == $tcaForeignTableService->field($fieldName)->getManyToManyTable()) { |
|
| 123 | - $result = $fieldName; |
|
| 124 | - break; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - return $result; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Returns the foreign table of a given field (opposite relational table). |
|
| 133 | - * If no relation exists, returns null. |
|
| 134 | - * |
|
| 135 | - * @return string|null |
|
| 136 | - */ |
|
| 137 | - public function getForeignTable() |
|
| 138 | - { |
|
| 139 | - $result = null; |
|
| 140 | - $configuration = $this->getConfiguration(); |
|
| 141 | - |
|
| 142 | - if (!empty($configuration['foreign_table'])) { |
|
| 143 | - $result = $configuration['foreign_table']; |
|
| 144 | - } elseif ($this->isGroup()) { |
|
| 145 | - $fieldParts = explode('.', $this->compositeField, 2); |
|
| 146 | - $result = $fieldParts[1]; |
|
| 147 | - } |
|
| 148 | - return $result; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Returns the foreign clause. |
|
| 153 | - * If no foreign order exists, returns empty string. |
|
| 154 | - * |
|
| 155 | - * @return string |
|
| 156 | - */ |
|
| 157 | - public function getForeignClause() |
|
| 158 | - { |
|
| 159 | - $result = ''; |
|
| 160 | - $configuration = $this->getConfiguration(); |
|
| 161 | - |
|
| 162 | - if (!empty($configuration['foreign_table_where'])) { |
|
| 163 | - $parts = explode('ORDER BY', $configuration['foreign_table_where']); |
|
| 164 | - if (!empty($parts[0])) { |
|
| 165 | - $result = $parts[0]; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // Substitute some variables |
|
| 170 | - return $this->substituteKnownMarkers($result); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Substitute some known markers from the where clause in the Frontend Context. |
|
| 175 | - * |
|
| 176 | - * @param string $clause |
|
| 177 | - * @return string |
|
| 178 | - */ |
|
| 179 | - protected function substituteKnownMarkers($clause) |
|
| 180 | - { |
|
| 181 | - if ($clause && $this->isFrontendMode()) { |
|
| 182 | - |
|
| 183 | - $searches = array( |
|
| 184 | - '###CURRENT_PID###', |
|
| 185 | - '###REC_FIELD_sys_language_uid###' |
|
| 186 | - ); |
|
| 187 | - |
|
| 188 | - $replaces = array( |
|
| 189 | - $this->getFrontendObject()->id, |
|
| 190 | - $this->getFrontendObject()->sys_language_uid, |
|
| 191 | - ); |
|
| 192 | - |
|
| 193 | - $clause = str_replace($searches, $replaces, $clause); |
|
| 194 | - } |
|
| 195 | - return $clause; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Returns the foreign order of the current field. |
|
| 200 | - * If no foreign order exists, returns empty string. |
|
| 201 | - * |
|
| 202 | - * @return string |
|
| 203 | - */ |
|
| 204 | - public function getForeignOrder() |
|
| 205 | - { |
|
| 206 | - $result = ''; |
|
| 207 | - $configuration = $this->getConfiguration(); |
|
| 208 | - |
|
| 209 | - if (!empty($configuration['foreign_table_where'])) { |
|
| 210 | - $parts = explode('ORDER BY', $configuration['foreign_table_where']); |
|
| 211 | - if (!empty($parts[1])) { |
|
| 212 | - $result = $parts[1]; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - return $result; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Returns the MM table of a field. |
|
| 220 | - * If no relation exists, returns null. |
|
| 221 | - * |
|
| 222 | - * @return string|null |
|
| 223 | - */ |
|
| 224 | - public function getManyToManyTable() |
|
| 225 | - { |
|
| 226 | - $configuration = $this->getConfiguration(); |
|
| 227 | - return empty($configuration['MM']) ? null : $configuration['MM']; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * Returns a possible additional table name used in MM relations. |
|
| 232 | - * If no table name exists, returns null. |
|
| 233 | - * |
|
| 234 | - * @return string|null |
|
| 235 | - */ |
|
| 236 | - public function getAdditionalTableNameCondition() |
|
| 237 | - { |
|
| 238 | - $result = null; |
|
| 239 | - $configuration = $this->getConfiguration(); |
|
| 240 | - |
|
| 241 | - if (!empty($configuration['MM_match_fields']['tablenames'])) { |
|
| 242 | - $result = $configuration['MM_match_fields']['tablenames']; |
|
| 243 | - } elseif ($this->isGroup()) { |
|
| 244 | - |
|
| 245 | - // @todo check if $this->fieldName could be simply used as $result |
|
| 246 | - $fieldParts = explode('.', $this->compositeField, 2); |
|
| 247 | - $result = $fieldParts[1]; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - return $result; |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Returns a possible additional conditions for MM tables such as "tablenames", "fieldname", etc... |
|
| 255 | - * |
|
| 256 | - * @return array |
|
| 257 | - */ |
|
| 258 | - public function getAdditionalMMCondition() |
|
| 259 | - { |
|
| 260 | - $additionalMMConditions = []; |
|
| 261 | - $configuration = $this->getConfiguration(); |
|
| 262 | - |
|
| 263 | - if (!empty($configuration['MM_match_fields'])) { |
|
| 264 | - $additionalMMConditions = $configuration['MM_match_fields']; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - // Add in any case a table name for "group" |
|
| 268 | - if ($this->isGroup()) { |
|
| 269 | - |
|
| 270 | - // @todo check if $this->fieldName could be simply used as $result |
|
| 271 | - $fieldParts = explode('.', $this->compositeField, 2); |
|
| 272 | - $additionalMMConditions = array( |
|
| 273 | - 'tablenames' => $fieldParts[1], |
|
| 274 | - ); |
|
| 275 | - } |
|
| 276 | - return $additionalMMConditions; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Returns whether the field name is the opposite in MM relation. |
|
| 281 | - * |
|
| 282 | - * @return bool |
|
| 283 | - */ |
|
| 284 | - public function isOppositeRelation() |
|
| 285 | - { |
|
| 286 | - $configuration = $this->getConfiguration(); |
|
| 287 | - return isset($configuration['MM_opposite_field']); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Returns the configuration for a $field. |
|
| 292 | - * |
|
| 293 | - * @throws \Exception |
|
| 294 | - * @return string |
|
| 295 | - */ |
|
| 296 | - public function getType() |
|
| 297 | - { |
|
| 298 | - |
|
| 299 | - if ($this->isSystem()) { |
|
| 300 | - $fieldType = FieldType::NUMBER; |
|
| 301 | - } else { |
|
| 302 | - $configuration = $this->getConfiguration(); |
|
| 303 | - |
|
| 304 | - if (empty($configuration['type'])) { |
|
| 305 | - throw new \Exception(sprintf('No field type found for "%s" in table "%s"', $this->fieldName, $this->tableName), 1385556627); |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - $fieldType = $configuration['type']; |
|
| 309 | - |
|
| 310 | - if ($configuration['type'] === FieldType::SELECT && !empty($configuration['size']) && $configuration['size'] > 1) { |
|
| 311 | - $fieldType = FieldType::MULTISELECT; |
|
| 312 | - } elseif (!empty($configuration['foreign_table']) |
|
| 313 | - && ($configuration['foreign_table'] == 'sys_file_reference' || $configuration['foreign_table'] == 'sys_file') |
|
| 314 | - ) { |
|
| 315 | - $fieldType = FieldType::FILE; |
|
| 316 | - } elseif (!empty($configuration['eval'])) { |
|
| 317 | - $parts = GeneralUtility::trimExplode(',', $configuration['eval']); |
|
| 318 | - if (in_array('datetime', $parts)) { |
|
| 319 | - $fieldType = FieldType::DATETIME; |
|
| 320 | - } elseif (in_array('date', $parts)) { |
|
| 321 | - $fieldType = FieldType::DATE; |
|
| 322 | - } elseif (in_array('email', $parts)) { |
|
| 323 | - $fieldType = FieldType::EMAIL; |
|
| 324 | - } elseif (in_array('int', $parts) || in_array('double2', $parts)) { |
|
| 325 | - $fieldType = FieldType::NUMBER; |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - // Do some legacy conversion |
|
| 330 | - if ($fieldType === 'input') { |
|
| 331 | - $fieldType = FieldType::TEXT; |
|
| 332 | - } elseif ($fieldType === 'text') { |
|
| 333 | - $fieldType = FieldType::TEXTAREA; |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - return $fieldType; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Return the default value. |
|
| 341 | - * |
|
| 342 | - * @return bool |
|
| 343 | - */ |
|
| 344 | - public function getDefaultValue() |
|
| 345 | - { |
|
| 346 | - $configuration = $this->getConfiguration(); |
|
| 347 | - return isset($configuration['default']) ? $configuration['default'] : null; |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - /** |
|
| 351 | - * Get the translation of a label given a column. |
|
| 352 | - * |
|
| 353 | - * @return string |
|
| 354 | - */ |
|
| 355 | - public function getLabel() |
|
| 356 | - { |
|
| 357 | - $result = ''; |
|
| 358 | - if ($this->hasLabel()) { |
|
| 359 | - $result = LocalizationUtility::translate($this->tca['label'], ''); |
|
| 360 | - |
|
| 361 | - if (empty($result)) { |
|
| 362 | - $result = $this->tca['label']; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - return $result; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * Get the translation of a label given a column. |
|
| 370 | - * |
|
| 371 | - * @param string $itemValue the item value to search for. |
|
| 372 | - * @return string |
|
| 373 | - */ |
|
| 374 | - public function getLabelForItem($itemValue) |
|
| 375 | - { |
|
| 376 | - |
|
| 377 | - // Early return whether there is nothing to be translated as label. |
|
| 378 | - if (is_null($itemValue)) { |
|
| 379 | - return ''; |
|
| 380 | - } elseif (is_string($itemValue) && $itemValue === '') { |
|
| 381 | - return $itemValue; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - $configuration = $this->getConfiguration(); |
|
| 385 | - if (!empty($configuration['items']) && is_array($configuration['items'])) { |
|
| 386 | - foreach ($configuration['items'] as $item) { |
|
| 387 | - if ($item[1] == $itemValue) { |
|
| 388 | - $label = LocalizationUtility::translate($item[0], ''); |
|
| 389 | - if (empty($label)) { |
|
| 390 | - $label = $item[0]; |
|
| 391 | - } |
|
| 392 | - break; |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - // Try fetching a label from a possible itemsProcFunc |
|
| 398 | - if (!isset($label) && is_scalar($itemValue)) { |
|
| 399 | - $items = $this->fetchItemsFromUserFunction(); |
|
| 400 | - if (!empty($items[$itemValue])) { |
|
| 401 | - $label = $items[$itemValue]; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - // Returns a label if it has been found, otherwise returns the item value as fallback. |
|
| 406 | - return isset($label) ? $label : $itemValue; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - /** |
|
| 410 | - * Retrieve items from User Function. |
|
| 411 | - * |
|
| 412 | - * @return array |
|
| 413 | - */ |
|
| 414 | - protected function fetchItemsFromUserFunction() |
|
| 415 | - { |
|
| 416 | - $values = []; |
|
| 417 | - |
|
| 418 | - $configuration = $this->getConfiguration(); |
|
| 419 | - if (!empty($configuration['itemsProcFunc'])) { |
|
| 420 | - $parts = explode('php:', $configuration['itemsProcFunc']); |
|
| 421 | - if (!empty($parts[1])) { |
|
| 422 | - |
|
| 423 | - list($class, $method) = explode('->', $parts[1]); |
|
| 424 | - |
|
| 425 | - $parameters['items'] = []; |
|
| 426 | - $object = GeneralUtility::makeInstance($class); |
|
| 427 | - $object->$method($parameters); |
|
| 428 | - |
|
| 429 | - foreach ($parameters['items'] as $items) { |
|
| 430 | - $values[$items[1]] = $items[0]; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - return $values; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Get a possible icon given a field name an an item. |
|
| 439 | - * |
|
| 440 | - * @param string $itemValue the item value to search for. |
|
| 441 | - * @return string |
|
| 442 | - */ |
|
| 443 | - public function getIconForItem($itemValue) |
|
| 444 | - { |
|
| 445 | - $result = ''; |
|
| 446 | - $configuration = $this->getConfiguration(); |
|
| 447 | - if (!empty($configuration['items']) && is_array($configuration['items'])) { |
|
| 448 | - foreach ($configuration['items'] as $item) { |
|
| 449 | - if ($item[1] == $itemValue) { |
|
| 450 | - $result = empty($item[2]) ? '' : $item[2]; |
|
| 451 | - break; |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - return $result; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Returns whether the field has a label. |
|
| 460 | - * |
|
| 461 | - * @return bool |
|
| 462 | - */ |
|
| 463 | - public function hasLabel() |
|
| 464 | - { |
|
| 465 | - return empty($this->tca['label']) ? false : true; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * Tell whether the current BE User has access to this field. |
|
| 470 | - * |
|
| 471 | - * @return bool |
|
| 472 | - */ |
|
| 473 | - public function hasAccess() |
|
| 474 | - { |
|
| 475 | - $hasAccess = true; |
|
| 476 | - if ($this->isBackendMode() |
|
| 477 | - && Tca::table($this->tableName)->hasAccess() |
|
| 478 | - && isset($this->tca['exclude']) |
|
| 479 | - && $this->tca['exclude'] |
|
| 480 | - ) { |
|
| 481 | - $hasAccess = $this->getBackendUser()->check('non_exclude_fields', $this->tableName . ':' . $this->fieldName); |
|
| 482 | - } |
|
| 483 | - return $hasAccess; |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - /** |
|
| 487 | - * Returns whether the field is numerical. |
|
| 488 | - * |
|
| 489 | - * @return bool |
|
| 490 | - */ |
|
| 491 | - public function isNumerical() |
|
| 492 | - { |
|
| 493 | - $result = $this->isSystem(); |
|
| 494 | - if ($result === false) { |
|
| 495 | - $configuration = $this->getConfiguration(); |
|
| 496 | - $parts = []; |
|
| 497 | - if (!empty($configuration['eval'])) { |
|
| 498 | - $parts = GeneralUtility::trimExplode(',', $configuration['eval']); |
|
| 499 | - } |
|
| 500 | - $result = in_array('int', $parts) || in_array('float', $parts); |
|
| 501 | - } |
|
| 502 | - return $result; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Returns whether the field is of type text area. |
|
| 507 | - * |
|
| 508 | - * @return bool |
|
| 509 | - */ |
|
| 510 | - public function isTextArea() |
|
| 511 | - { |
|
| 512 | - return $this->getType() === FieldType::TEXTAREA; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * Returns whether the field is displayed as a tree. |
|
| 517 | - * |
|
| 518 | - * @return bool |
|
| 519 | - */ |
|
| 520 | - public function isRenderModeTree() |
|
| 521 | - { |
|
| 522 | - $configuration = $this->getConfiguration(); |
|
| 523 | - return isset($configuration['renderMode']) && $configuration['renderMode'] == FieldType::TREE; |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - /** |
|
| 527 | - * Returns whether the field is of type select. |
|
| 528 | - * |
|
| 529 | - * @return bool |
|
| 530 | - */ |
|
| 531 | - public function isSelect() |
|
| 532 | - { |
|
| 533 | - return $this->getType() === FieldType::SELECT; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Returns whether the field is of type select. |
|
| 538 | - * |
|
| 539 | - * @return bool |
|
| 540 | - */ |
|
| 541 | - public function isCheckBox() |
|
| 542 | - { |
|
| 543 | - return $this->getType() === FieldType::CHECKBOX; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Returns whether the field is of type db. |
|
| 548 | - * |
|
| 549 | - * @return bool |
|
| 550 | - */ |
|
| 551 | - public function isGroup() |
|
| 552 | - { |
|
| 553 | - return $this->getType() === 'group'; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Returns whether the field is language aware. |
|
| 558 | - * |
|
| 559 | - * @return bool |
|
| 560 | - */ |
|
| 561 | - public function isLocalized() |
|
| 562 | - { |
|
| 563 | - $isLocalized = false; |
|
| 564 | - if (isset($this->tca['l10n_mode'])) { |
|
| 565 | - |
|
| 566 | - if ($this->tca['l10n_mode'] == 'prefixLangTitle' || $this->tca['l10n_mode'] == 'mergeIfNotBlank') { |
|
| 567 | - $isLocalized = true; |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - return $isLocalized; |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * Returns whether the field is required. |
|
| 575 | - * |
|
| 576 | - * @return bool |
|
| 577 | - */ |
|
| 578 | - public function isRequired() |
|
| 579 | - { |
|
| 580 | - $configuration = $this->getConfiguration(); |
|
| 581 | - |
|
| 582 | - $isRequired = false; |
|
| 583 | - if (isset($configuration['minitems'])) { |
|
| 584 | - // is required of a select? |
|
| 585 | - $isRequired = $configuration['minitems'] == 1 ? true : false; |
|
| 586 | - } elseif (isset($configuration['eval'])) { |
|
| 587 | - $parts = GeneralUtility::trimExplode(',', $configuration['eval'], true); |
|
| 588 | - $isRequired = in_array('required', $parts); |
|
| 589 | - } |
|
| 590 | - return $isRequired; |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * Returns an array containing the configuration of a column. |
|
| 595 | - * |
|
| 596 | - * @return array |
|
| 597 | - */ |
|
| 598 | - public function getField() |
|
| 599 | - { |
|
| 600 | - return $this->tca; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - /** |
|
| 604 | - * Returns the relation type |
|
| 605 | - * |
|
| 606 | - * @return string |
|
| 607 | - */ |
|
| 608 | - public function relationDataType() |
|
| 609 | - { |
|
| 610 | - $configuration = $this->getConfiguration(); |
|
| 611 | - return empty($configuration['foreign_table']) ? '' : $configuration['foreign_table']; |
|
| 612 | - } |
|
| 613 | - |
|
| 614 | - /** |
|
| 615 | - * Returns whether the field has relation (one to many, many to many) |
|
| 616 | - * |
|
| 617 | - * @return bool |
|
| 618 | - */ |
|
| 619 | - public function hasRelation() |
|
| 620 | - { |
|
| 621 | - return null !== $this->getForeignTable(); |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - /** |
|
| 625 | - * Returns whether the field has no relation (one to many, many to many) |
|
| 626 | - * |
|
| 627 | - * @return bool |
|
| 628 | - */ |
|
| 629 | - public function hasNoRelation() |
|
| 630 | - { |
|
| 631 | - return !$this->hasRelation(); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - /** |
|
| 635 | - * Returns whether the field has a "many" objects connected including "many-to-many" or "one-to-many". |
|
| 636 | - * |
|
| 637 | - * @return bool |
|
| 638 | - */ |
|
| 639 | - public function hasMany() |
|
| 640 | - { |
|
| 641 | - $configuration = $this->getConfiguration(); |
|
| 642 | - return $this->hasRelation() && ($configuration['maxitems'] > 1 || isset($configuration['foreign_table_field'])); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * Returns whether the field has relation "one" object connected including of "one-to-one" or "many-to-one". |
|
| 647 | - * |
|
| 648 | - * @return bool |
|
| 649 | - */ |
|
| 650 | - public function hasOne() |
|
| 651 | - { |
|
| 652 | - $configuration = $this->getConfiguration(); |
|
| 653 | - return !isset($configuration['MM']) && $this->hasRelation() && ($configuration['maxitems'] == 1 || !isset($configuration['maxitems'])); |
|
| 654 | - } |
|
| 655 | - |
|
| 656 | - /** |
|
| 657 | - * Returns whether the field has many-to-one relation. |
|
| 658 | - * |
|
| 659 | - * @return bool |
|
| 660 | - */ |
|
| 661 | - public function hasRelationManyToOne() |
|
| 662 | - { |
|
| 663 | - $result = false; |
|
| 664 | - |
|
| 665 | - $foreignField = $this->getForeignField(); |
|
| 666 | - if (!empty($foreignField)) { |
|
| 667 | - |
|
| 668 | - // Load TCA service of the foreign field. |
|
| 669 | - $foreignTable = $this->getForeignTable(); |
|
| 670 | - $result = $this->hasOne() && Tca::table($foreignTable)->field($foreignField)->hasMany(); |
|
| 671 | - } |
|
| 672 | - return $result; |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - /** |
|
| 676 | - * Returns whether the field has one-to-many relation. |
|
| 677 | - * |
|
| 678 | - * @return bool |
|
| 679 | - */ |
|
| 680 | - public function hasRelationOneToMany() |
|
| 681 | - { |
|
| 682 | - $result = false; |
|
| 683 | - |
|
| 684 | - $foreignField = $this->getForeignField(); |
|
| 685 | - if (!empty($foreignField)) { |
|
| 686 | - |
|
| 687 | - // Load TCA service of the foreign field. |
|
| 688 | - $foreignTable = $this->getForeignTable(); |
|
| 689 | - $result = $this->hasMany() && Tca::table($foreignTable)->field($foreignField)->hasOne(); |
|
| 690 | - } |
|
| 691 | - return $result; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - /** |
|
| 695 | - * Returns whether the field has one-to-one relation. |
|
| 696 | - * |
|
| 697 | - * @return bool |
|
| 698 | - */ |
|
| 699 | - public function hasRelationOneToOne() |
|
| 700 | - { |
|
| 701 | - $result = false; |
|
| 702 | - |
|
| 703 | - $foreignField = $this->getForeignField(); |
|
| 704 | - if (!empty($foreignField)) { |
|
| 705 | - |
|
| 706 | - // Load TCA service of foreign field. |
|
| 707 | - $foreignTable = $this->getForeignTable(); |
|
| 708 | - $result = $this->hasOne() && Tca::table($foreignTable)->field($foreignField)->hasOne(); |
|
| 709 | - } |
|
| 710 | - return $result; |
|
| 711 | - } |
|
| 712 | - |
|
| 713 | - /** |
|
| 714 | - * Returns whether the field has many to many relation. |
|
| 715 | - * |
|
| 716 | - * @return bool |
|
| 717 | - */ |
|
| 718 | - public function hasRelationManyToMany() |
|
| 719 | - { |
|
| 720 | - $configuration = $this->getConfiguration(); |
|
| 721 | - return $this->hasRelation() && (isset($configuration['MM']) || isset($configuration['foreign_table_field'])); |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * Returns whether the field has many to many relation using comma separated values (legacy). |
|
| 726 | - * |
|
| 727 | - * @return bool |
|
| 728 | - */ |
|
| 729 | - public function hasRelationWithCommaSeparatedValues() |
|
| 730 | - { |
|
| 731 | - $configuration = $this->getConfiguration(); |
|
| 732 | - return $this->hasRelation() && !isset($configuration['MM']) && !isset($configuration['foreign_field']) && $configuration['maxitems'] > 1; |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - /** |
|
| 736 | - * @return array |
|
| 737 | - */ |
|
| 738 | - public function getTca() |
|
| 739 | - { |
|
| 740 | - return $this->tca['columns']; |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - /** |
|
| 744 | - * @return string |
|
| 745 | - */ |
|
| 746 | - public function getCompositeField() |
|
| 747 | - { |
|
| 748 | - return $this->compositeField; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - /** |
|
| 752 | - * @param string $compositeField |
|
| 753 | - */ |
|
| 754 | - public function setCompositeField($compositeField) |
|
| 755 | - { |
|
| 756 | - $this->compositeField = $compositeField; |
|
| 757 | - } |
|
| 758 | - |
|
| 759 | - /** |
|
| 760 | - * Returns an instance of the Frontend object. |
|
| 761 | - * |
|
| 762 | - * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController |
|
| 763 | - */ |
|
| 764 | - protected function getFrontendObject() |
|
| 765 | - { |
|
| 766 | - return $GLOBALS['TSFE']; |
|
| 767 | - } |
|
| 20 | + /** |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + protected $fieldName; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + protected $compositeField; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var string |
|
| 32 | + */ |
|
| 33 | + protected $tableName; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var array |
|
| 37 | + */ |
|
| 38 | + protected $tca; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @param string $fieldName |
|
| 42 | + * @param array $tca |
|
| 43 | + * @param string $tableName |
|
| 44 | + * @param string $compositeField |
|
| 45 | + * @return \Fab\Vidi\Tca\FieldService |
|
| 46 | + */ |
|
| 47 | + public function __construct($fieldName, array $tca, $tableName, $compositeField = '') |
|
| 48 | + { |
|
| 49 | + $this->fieldName = $fieldName; |
|
| 50 | + $this->tca = $tca; |
|
| 51 | + $this->tableName = $tableName; |
|
| 52 | + $this->compositeField = $compositeField; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Tells whether the field is considered as system field, e.g. uid, crdate, tstamp, etc... |
|
| 57 | + * |
|
| 58 | + * @return bool |
|
| 59 | + */ |
|
| 60 | + public function isSystem() |
|
| 61 | + { |
|
| 62 | + return in_array($this->fieldName, Tca::getSystemFields()); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Tells the opposition of isSystem() |
|
| 67 | + * |
|
| 68 | + * @return bool |
|
| 69 | + */ |
|
| 70 | + public function isNotSystem() |
|
| 71 | + { |
|
| 72 | + return !$this->isSystem(); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Returns the configuration for a $field |
|
| 77 | + * |
|
| 78 | + * @throws \Exception |
|
| 79 | + * @return array |
|
| 80 | + */ |
|
| 81 | + public function getConfiguration() |
|
| 82 | + { |
|
| 83 | + return empty($this->tca['config']) ? [] : $this->tca['config']; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Returns a key of the configuration. |
|
| 88 | + * If the key can not to be found, returns null. |
|
| 89 | + * |
|
| 90 | + * @param string $key |
|
| 91 | + * @return mixed |
|
| 92 | + */ |
|
| 93 | + public function get($key) |
|
| 94 | + { |
|
| 95 | + $configuration = $this->getConfiguration(); |
|
| 96 | + return empty($configuration[$key]) ? null : $configuration[$key]; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Returns the foreign field of a given field (opposite relational field). |
|
| 101 | + * If no relation exists, returns null. |
|
| 102 | + * |
|
| 103 | + * @return string|null |
|
| 104 | + */ |
|
| 105 | + public function getForeignField() |
|
| 106 | + { |
|
| 107 | + $result = null; |
|
| 108 | + $configuration = $this->getConfiguration(); |
|
| 109 | + |
|
| 110 | + if (!empty($configuration['foreign_field'])) { |
|
| 111 | + $result = $configuration['foreign_field']; |
|
| 112 | + } elseif ($this->hasRelationManyToMany()) { |
|
| 113 | + |
|
| 114 | + $foreignTable = $this->getForeignTable(); |
|
| 115 | + $manyToManyTable = $this->getManyToManyTable(); |
|
| 116 | + |
|
| 117 | + // Load TCA service of foreign field. |
|
| 118 | + $tcaForeignTableService = Tca::table($foreignTable); |
|
| 119 | + |
|
| 120 | + // Look into the MM relations checking for the opposite field |
|
| 121 | + foreach ($tcaForeignTableService->getFields() as $fieldName) { |
|
| 122 | + if ($manyToManyTable == $tcaForeignTableService->field($fieldName)->getManyToManyTable()) { |
|
| 123 | + $result = $fieldName; |
|
| 124 | + break; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + return $result; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Returns the foreign table of a given field (opposite relational table). |
|
| 133 | + * If no relation exists, returns null. |
|
| 134 | + * |
|
| 135 | + * @return string|null |
|
| 136 | + */ |
|
| 137 | + public function getForeignTable() |
|
| 138 | + { |
|
| 139 | + $result = null; |
|
| 140 | + $configuration = $this->getConfiguration(); |
|
| 141 | + |
|
| 142 | + if (!empty($configuration['foreign_table'])) { |
|
| 143 | + $result = $configuration['foreign_table']; |
|
| 144 | + } elseif ($this->isGroup()) { |
|
| 145 | + $fieldParts = explode('.', $this->compositeField, 2); |
|
| 146 | + $result = $fieldParts[1]; |
|
| 147 | + } |
|
| 148 | + return $result; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Returns the foreign clause. |
|
| 153 | + * If no foreign order exists, returns empty string. |
|
| 154 | + * |
|
| 155 | + * @return string |
|
| 156 | + */ |
|
| 157 | + public function getForeignClause() |
|
| 158 | + { |
|
| 159 | + $result = ''; |
|
| 160 | + $configuration = $this->getConfiguration(); |
|
| 161 | + |
|
| 162 | + if (!empty($configuration['foreign_table_where'])) { |
|
| 163 | + $parts = explode('ORDER BY', $configuration['foreign_table_where']); |
|
| 164 | + if (!empty($parts[0])) { |
|
| 165 | + $result = $parts[0]; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // Substitute some variables |
|
| 170 | + return $this->substituteKnownMarkers($result); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Substitute some known markers from the where clause in the Frontend Context. |
|
| 175 | + * |
|
| 176 | + * @param string $clause |
|
| 177 | + * @return string |
|
| 178 | + */ |
|
| 179 | + protected function substituteKnownMarkers($clause) |
|
| 180 | + { |
|
| 181 | + if ($clause && $this->isFrontendMode()) { |
|
| 182 | + |
|
| 183 | + $searches = array( |
|
| 184 | + '###CURRENT_PID###', |
|
| 185 | + '###REC_FIELD_sys_language_uid###' |
|
| 186 | + ); |
|
| 187 | + |
|
| 188 | + $replaces = array( |
|
| 189 | + $this->getFrontendObject()->id, |
|
| 190 | + $this->getFrontendObject()->sys_language_uid, |
|
| 191 | + ); |
|
| 192 | + |
|
| 193 | + $clause = str_replace($searches, $replaces, $clause); |
|
| 194 | + } |
|
| 195 | + return $clause; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Returns the foreign order of the current field. |
|
| 200 | + * If no foreign order exists, returns empty string. |
|
| 201 | + * |
|
| 202 | + * @return string |
|
| 203 | + */ |
|
| 204 | + public function getForeignOrder() |
|
| 205 | + { |
|
| 206 | + $result = ''; |
|
| 207 | + $configuration = $this->getConfiguration(); |
|
| 208 | + |
|
| 209 | + if (!empty($configuration['foreign_table_where'])) { |
|
| 210 | + $parts = explode('ORDER BY', $configuration['foreign_table_where']); |
|
| 211 | + if (!empty($parts[1])) { |
|
| 212 | + $result = $parts[1]; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + return $result; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Returns the MM table of a field. |
|
| 220 | + * If no relation exists, returns null. |
|
| 221 | + * |
|
| 222 | + * @return string|null |
|
| 223 | + */ |
|
| 224 | + public function getManyToManyTable() |
|
| 225 | + { |
|
| 226 | + $configuration = $this->getConfiguration(); |
|
| 227 | + return empty($configuration['MM']) ? null : $configuration['MM']; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * Returns a possible additional table name used in MM relations. |
|
| 232 | + * If no table name exists, returns null. |
|
| 233 | + * |
|
| 234 | + * @return string|null |
|
| 235 | + */ |
|
| 236 | + public function getAdditionalTableNameCondition() |
|
| 237 | + { |
|
| 238 | + $result = null; |
|
| 239 | + $configuration = $this->getConfiguration(); |
|
| 240 | + |
|
| 241 | + if (!empty($configuration['MM_match_fields']['tablenames'])) { |
|
| 242 | + $result = $configuration['MM_match_fields']['tablenames']; |
|
| 243 | + } elseif ($this->isGroup()) { |
|
| 244 | + |
|
| 245 | + // @todo check if $this->fieldName could be simply used as $result |
|
| 246 | + $fieldParts = explode('.', $this->compositeField, 2); |
|
| 247 | + $result = $fieldParts[1]; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return $result; |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Returns a possible additional conditions for MM tables such as "tablenames", "fieldname", etc... |
|
| 255 | + * |
|
| 256 | + * @return array |
|
| 257 | + */ |
|
| 258 | + public function getAdditionalMMCondition() |
|
| 259 | + { |
|
| 260 | + $additionalMMConditions = []; |
|
| 261 | + $configuration = $this->getConfiguration(); |
|
| 262 | + |
|
| 263 | + if (!empty($configuration['MM_match_fields'])) { |
|
| 264 | + $additionalMMConditions = $configuration['MM_match_fields']; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + // Add in any case a table name for "group" |
|
| 268 | + if ($this->isGroup()) { |
|
| 269 | + |
|
| 270 | + // @todo check if $this->fieldName could be simply used as $result |
|
| 271 | + $fieldParts = explode('.', $this->compositeField, 2); |
|
| 272 | + $additionalMMConditions = array( |
|
| 273 | + 'tablenames' => $fieldParts[1], |
|
| 274 | + ); |
|
| 275 | + } |
|
| 276 | + return $additionalMMConditions; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Returns whether the field name is the opposite in MM relation. |
|
| 281 | + * |
|
| 282 | + * @return bool |
|
| 283 | + */ |
|
| 284 | + public function isOppositeRelation() |
|
| 285 | + { |
|
| 286 | + $configuration = $this->getConfiguration(); |
|
| 287 | + return isset($configuration['MM_opposite_field']); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Returns the configuration for a $field. |
|
| 292 | + * |
|
| 293 | + * @throws \Exception |
|
| 294 | + * @return string |
|
| 295 | + */ |
|
| 296 | + public function getType() |
|
| 297 | + { |
|
| 298 | + |
|
| 299 | + if ($this->isSystem()) { |
|
| 300 | + $fieldType = FieldType::NUMBER; |
|
| 301 | + } else { |
|
| 302 | + $configuration = $this->getConfiguration(); |
|
| 303 | + |
|
| 304 | + if (empty($configuration['type'])) { |
|
| 305 | + throw new \Exception(sprintf('No field type found for "%s" in table "%s"', $this->fieldName, $this->tableName), 1385556627); |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + $fieldType = $configuration['type']; |
|
| 309 | + |
|
| 310 | + if ($configuration['type'] === FieldType::SELECT && !empty($configuration['size']) && $configuration['size'] > 1) { |
|
| 311 | + $fieldType = FieldType::MULTISELECT; |
|
| 312 | + } elseif (!empty($configuration['foreign_table']) |
|
| 313 | + && ($configuration['foreign_table'] == 'sys_file_reference' || $configuration['foreign_table'] == 'sys_file') |
|
| 314 | + ) { |
|
| 315 | + $fieldType = FieldType::FILE; |
|
| 316 | + } elseif (!empty($configuration['eval'])) { |
|
| 317 | + $parts = GeneralUtility::trimExplode(',', $configuration['eval']); |
|
| 318 | + if (in_array('datetime', $parts)) { |
|
| 319 | + $fieldType = FieldType::DATETIME; |
|
| 320 | + } elseif (in_array('date', $parts)) { |
|
| 321 | + $fieldType = FieldType::DATE; |
|
| 322 | + } elseif (in_array('email', $parts)) { |
|
| 323 | + $fieldType = FieldType::EMAIL; |
|
| 324 | + } elseif (in_array('int', $parts) || in_array('double2', $parts)) { |
|
| 325 | + $fieldType = FieldType::NUMBER; |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + // Do some legacy conversion |
|
| 330 | + if ($fieldType === 'input') { |
|
| 331 | + $fieldType = FieldType::TEXT; |
|
| 332 | + } elseif ($fieldType === 'text') { |
|
| 333 | + $fieldType = FieldType::TEXTAREA; |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + return $fieldType; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Return the default value. |
|
| 341 | + * |
|
| 342 | + * @return bool |
|
| 343 | + */ |
|
| 344 | + public function getDefaultValue() |
|
| 345 | + { |
|
| 346 | + $configuration = $this->getConfiguration(); |
|
| 347 | + return isset($configuration['default']) ? $configuration['default'] : null; |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + /** |
|
| 351 | + * Get the translation of a label given a column. |
|
| 352 | + * |
|
| 353 | + * @return string |
|
| 354 | + */ |
|
| 355 | + public function getLabel() |
|
| 356 | + { |
|
| 357 | + $result = ''; |
|
| 358 | + if ($this->hasLabel()) { |
|
| 359 | + $result = LocalizationUtility::translate($this->tca['label'], ''); |
|
| 360 | + |
|
| 361 | + if (empty($result)) { |
|
| 362 | + $result = $this->tca['label']; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + return $result; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * Get the translation of a label given a column. |
|
| 370 | + * |
|
| 371 | + * @param string $itemValue the item value to search for. |
|
| 372 | + * @return string |
|
| 373 | + */ |
|
| 374 | + public function getLabelForItem($itemValue) |
|
| 375 | + { |
|
| 376 | + |
|
| 377 | + // Early return whether there is nothing to be translated as label. |
|
| 378 | + if (is_null($itemValue)) { |
|
| 379 | + return ''; |
|
| 380 | + } elseif (is_string($itemValue) && $itemValue === '') { |
|
| 381 | + return $itemValue; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + $configuration = $this->getConfiguration(); |
|
| 385 | + if (!empty($configuration['items']) && is_array($configuration['items'])) { |
|
| 386 | + foreach ($configuration['items'] as $item) { |
|
| 387 | + if ($item[1] == $itemValue) { |
|
| 388 | + $label = LocalizationUtility::translate($item[0], ''); |
|
| 389 | + if (empty($label)) { |
|
| 390 | + $label = $item[0]; |
|
| 391 | + } |
|
| 392 | + break; |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + // Try fetching a label from a possible itemsProcFunc |
|
| 398 | + if (!isset($label) && is_scalar($itemValue)) { |
|
| 399 | + $items = $this->fetchItemsFromUserFunction(); |
|
| 400 | + if (!empty($items[$itemValue])) { |
|
| 401 | + $label = $items[$itemValue]; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + // Returns a label if it has been found, otherwise returns the item value as fallback. |
|
| 406 | + return isset($label) ? $label : $itemValue; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + /** |
|
| 410 | + * Retrieve items from User Function. |
|
| 411 | + * |
|
| 412 | + * @return array |
|
| 413 | + */ |
|
| 414 | + protected function fetchItemsFromUserFunction() |
|
| 415 | + { |
|
| 416 | + $values = []; |
|
| 417 | + |
|
| 418 | + $configuration = $this->getConfiguration(); |
|
| 419 | + if (!empty($configuration['itemsProcFunc'])) { |
|
| 420 | + $parts = explode('php:', $configuration['itemsProcFunc']); |
|
| 421 | + if (!empty($parts[1])) { |
|
| 422 | + |
|
| 423 | + list($class, $method) = explode('->', $parts[1]); |
|
| 424 | + |
|
| 425 | + $parameters['items'] = []; |
|
| 426 | + $object = GeneralUtility::makeInstance($class); |
|
| 427 | + $object->$method($parameters); |
|
| 428 | + |
|
| 429 | + foreach ($parameters['items'] as $items) { |
|
| 430 | + $values[$items[1]] = $items[0]; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + return $values; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Get a possible icon given a field name an an item. |
|
| 439 | + * |
|
| 440 | + * @param string $itemValue the item value to search for. |
|
| 441 | + * @return string |
|
| 442 | + */ |
|
| 443 | + public function getIconForItem($itemValue) |
|
| 444 | + { |
|
| 445 | + $result = ''; |
|
| 446 | + $configuration = $this->getConfiguration(); |
|
| 447 | + if (!empty($configuration['items']) && is_array($configuration['items'])) { |
|
| 448 | + foreach ($configuration['items'] as $item) { |
|
| 449 | + if ($item[1] == $itemValue) { |
|
| 450 | + $result = empty($item[2]) ? '' : $item[2]; |
|
| 451 | + break; |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + return $result; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Returns whether the field has a label. |
|
| 460 | + * |
|
| 461 | + * @return bool |
|
| 462 | + */ |
|
| 463 | + public function hasLabel() |
|
| 464 | + { |
|
| 465 | + return empty($this->tca['label']) ? false : true; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * Tell whether the current BE User has access to this field. |
|
| 470 | + * |
|
| 471 | + * @return bool |
|
| 472 | + */ |
|
| 473 | + public function hasAccess() |
|
| 474 | + { |
|
| 475 | + $hasAccess = true; |
|
| 476 | + if ($this->isBackendMode() |
|
| 477 | + && Tca::table($this->tableName)->hasAccess() |
|
| 478 | + && isset($this->tca['exclude']) |
|
| 479 | + && $this->tca['exclude'] |
|
| 480 | + ) { |
|
| 481 | + $hasAccess = $this->getBackendUser()->check('non_exclude_fields', $this->tableName . ':' . $this->fieldName); |
|
| 482 | + } |
|
| 483 | + return $hasAccess; |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + /** |
|
| 487 | + * Returns whether the field is numerical. |
|
| 488 | + * |
|
| 489 | + * @return bool |
|
| 490 | + */ |
|
| 491 | + public function isNumerical() |
|
| 492 | + { |
|
| 493 | + $result = $this->isSystem(); |
|
| 494 | + if ($result === false) { |
|
| 495 | + $configuration = $this->getConfiguration(); |
|
| 496 | + $parts = []; |
|
| 497 | + if (!empty($configuration['eval'])) { |
|
| 498 | + $parts = GeneralUtility::trimExplode(',', $configuration['eval']); |
|
| 499 | + } |
|
| 500 | + $result = in_array('int', $parts) || in_array('float', $parts); |
|
| 501 | + } |
|
| 502 | + return $result; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Returns whether the field is of type text area. |
|
| 507 | + * |
|
| 508 | + * @return bool |
|
| 509 | + */ |
|
| 510 | + public function isTextArea() |
|
| 511 | + { |
|
| 512 | + return $this->getType() === FieldType::TEXTAREA; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * Returns whether the field is displayed as a tree. |
|
| 517 | + * |
|
| 518 | + * @return bool |
|
| 519 | + */ |
|
| 520 | + public function isRenderModeTree() |
|
| 521 | + { |
|
| 522 | + $configuration = $this->getConfiguration(); |
|
| 523 | + return isset($configuration['renderMode']) && $configuration['renderMode'] == FieldType::TREE; |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + /** |
|
| 527 | + * Returns whether the field is of type select. |
|
| 528 | + * |
|
| 529 | + * @return bool |
|
| 530 | + */ |
|
| 531 | + public function isSelect() |
|
| 532 | + { |
|
| 533 | + return $this->getType() === FieldType::SELECT; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Returns whether the field is of type select. |
|
| 538 | + * |
|
| 539 | + * @return bool |
|
| 540 | + */ |
|
| 541 | + public function isCheckBox() |
|
| 542 | + { |
|
| 543 | + return $this->getType() === FieldType::CHECKBOX; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Returns whether the field is of type db. |
|
| 548 | + * |
|
| 549 | + * @return bool |
|
| 550 | + */ |
|
| 551 | + public function isGroup() |
|
| 552 | + { |
|
| 553 | + return $this->getType() === 'group'; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Returns whether the field is language aware. |
|
| 558 | + * |
|
| 559 | + * @return bool |
|
| 560 | + */ |
|
| 561 | + public function isLocalized() |
|
| 562 | + { |
|
| 563 | + $isLocalized = false; |
|
| 564 | + if (isset($this->tca['l10n_mode'])) { |
|
| 565 | + |
|
| 566 | + if ($this->tca['l10n_mode'] == 'prefixLangTitle' || $this->tca['l10n_mode'] == 'mergeIfNotBlank') { |
|
| 567 | + $isLocalized = true; |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + return $isLocalized; |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Returns whether the field is required. |
|
| 575 | + * |
|
| 576 | + * @return bool |
|
| 577 | + */ |
|
| 578 | + public function isRequired() |
|
| 579 | + { |
|
| 580 | + $configuration = $this->getConfiguration(); |
|
| 581 | + |
|
| 582 | + $isRequired = false; |
|
| 583 | + if (isset($configuration['minitems'])) { |
|
| 584 | + // is required of a select? |
|
| 585 | + $isRequired = $configuration['minitems'] == 1 ? true : false; |
|
| 586 | + } elseif (isset($configuration['eval'])) { |
|
| 587 | + $parts = GeneralUtility::trimExplode(',', $configuration['eval'], true); |
|
| 588 | + $isRequired = in_array('required', $parts); |
|
| 589 | + } |
|
| 590 | + return $isRequired; |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * Returns an array containing the configuration of a column. |
|
| 595 | + * |
|
| 596 | + * @return array |
|
| 597 | + */ |
|
| 598 | + public function getField() |
|
| 599 | + { |
|
| 600 | + return $this->tca; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + /** |
|
| 604 | + * Returns the relation type |
|
| 605 | + * |
|
| 606 | + * @return string |
|
| 607 | + */ |
|
| 608 | + public function relationDataType() |
|
| 609 | + { |
|
| 610 | + $configuration = $this->getConfiguration(); |
|
| 611 | + return empty($configuration['foreign_table']) ? '' : $configuration['foreign_table']; |
|
| 612 | + } |
|
| 613 | + |
|
| 614 | + /** |
|
| 615 | + * Returns whether the field has relation (one to many, many to many) |
|
| 616 | + * |
|
| 617 | + * @return bool |
|
| 618 | + */ |
|
| 619 | + public function hasRelation() |
|
| 620 | + { |
|
| 621 | + return null !== $this->getForeignTable(); |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + /** |
|
| 625 | + * Returns whether the field has no relation (one to many, many to many) |
|
| 626 | + * |
|
| 627 | + * @return bool |
|
| 628 | + */ |
|
| 629 | + public function hasNoRelation() |
|
| 630 | + { |
|
| 631 | + return !$this->hasRelation(); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + /** |
|
| 635 | + * Returns whether the field has a "many" objects connected including "many-to-many" or "one-to-many". |
|
| 636 | + * |
|
| 637 | + * @return bool |
|
| 638 | + */ |
|
| 639 | + public function hasMany() |
|
| 640 | + { |
|
| 641 | + $configuration = $this->getConfiguration(); |
|
| 642 | + return $this->hasRelation() && ($configuration['maxitems'] > 1 || isset($configuration['foreign_table_field'])); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * Returns whether the field has relation "one" object connected including of "one-to-one" or "many-to-one". |
|
| 647 | + * |
|
| 648 | + * @return bool |
|
| 649 | + */ |
|
| 650 | + public function hasOne() |
|
| 651 | + { |
|
| 652 | + $configuration = $this->getConfiguration(); |
|
| 653 | + return !isset($configuration['MM']) && $this->hasRelation() && ($configuration['maxitems'] == 1 || !isset($configuration['maxitems'])); |
|
| 654 | + } |
|
| 655 | + |
|
| 656 | + /** |
|
| 657 | + * Returns whether the field has many-to-one relation. |
|
| 658 | + * |
|
| 659 | + * @return bool |
|
| 660 | + */ |
|
| 661 | + public function hasRelationManyToOne() |
|
| 662 | + { |
|
| 663 | + $result = false; |
|
| 664 | + |
|
| 665 | + $foreignField = $this->getForeignField(); |
|
| 666 | + if (!empty($foreignField)) { |
|
| 667 | + |
|
| 668 | + // Load TCA service of the foreign field. |
|
| 669 | + $foreignTable = $this->getForeignTable(); |
|
| 670 | + $result = $this->hasOne() && Tca::table($foreignTable)->field($foreignField)->hasMany(); |
|
| 671 | + } |
|
| 672 | + return $result; |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + /** |
|
| 676 | + * Returns whether the field has one-to-many relation. |
|
| 677 | + * |
|
| 678 | + * @return bool |
|
| 679 | + */ |
|
| 680 | + public function hasRelationOneToMany() |
|
| 681 | + { |
|
| 682 | + $result = false; |
|
| 683 | + |
|
| 684 | + $foreignField = $this->getForeignField(); |
|
| 685 | + if (!empty($foreignField)) { |
|
| 686 | + |
|
| 687 | + // Load TCA service of the foreign field. |
|
| 688 | + $foreignTable = $this->getForeignTable(); |
|
| 689 | + $result = $this->hasMany() && Tca::table($foreignTable)->field($foreignField)->hasOne(); |
|
| 690 | + } |
|
| 691 | + return $result; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + /** |
|
| 695 | + * Returns whether the field has one-to-one relation. |
|
| 696 | + * |
|
| 697 | + * @return bool |
|
| 698 | + */ |
|
| 699 | + public function hasRelationOneToOne() |
|
| 700 | + { |
|
| 701 | + $result = false; |
|
| 702 | + |
|
| 703 | + $foreignField = $this->getForeignField(); |
|
| 704 | + if (!empty($foreignField)) { |
|
| 705 | + |
|
| 706 | + // Load TCA service of foreign field. |
|
| 707 | + $foreignTable = $this->getForeignTable(); |
|
| 708 | + $result = $this->hasOne() && Tca::table($foreignTable)->field($foreignField)->hasOne(); |
|
| 709 | + } |
|
| 710 | + return $result; |
|
| 711 | + } |
|
| 712 | + |
|
| 713 | + /** |
|
| 714 | + * Returns whether the field has many to many relation. |
|
| 715 | + * |
|
| 716 | + * @return bool |
|
| 717 | + */ |
|
| 718 | + public function hasRelationManyToMany() |
|
| 719 | + { |
|
| 720 | + $configuration = $this->getConfiguration(); |
|
| 721 | + return $this->hasRelation() && (isset($configuration['MM']) || isset($configuration['foreign_table_field'])); |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * Returns whether the field has many to many relation using comma separated values (legacy). |
|
| 726 | + * |
|
| 727 | + * @return bool |
|
| 728 | + */ |
|
| 729 | + public function hasRelationWithCommaSeparatedValues() |
|
| 730 | + { |
|
| 731 | + $configuration = $this->getConfiguration(); |
|
| 732 | + return $this->hasRelation() && !isset($configuration['MM']) && !isset($configuration['foreign_field']) && $configuration['maxitems'] > 1; |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + /** |
|
| 736 | + * @return array |
|
| 737 | + */ |
|
| 738 | + public function getTca() |
|
| 739 | + { |
|
| 740 | + return $this->tca['columns']; |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + /** |
|
| 744 | + * @return string |
|
| 745 | + */ |
|
| 746 | + public function getCompositeField() |
|
| 747 | + { |
|
| 748 | + return $this->compositeField; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + /** |
|
| 752 | + * @param string $compositeField |
|
| 753 | + */ |
|
| 754 | + public function setCompositeField($compositeField) |
|
| 755 | + { |
|
| 756 | + $this->compositeField = $compositeField; |
|
| 757 | + } |
|
| 758 | + |
|
| 759 | + /** |
|
| 760 | + * Returns an instance of the Frontend object. |
|
| 761 | + * |
|
| 762 | + * @return \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController |
|
| 763 | + */ |
|
| 764 | + protected function getFrontendObject() |
|
| 765 | + { |
|
| 766 | + return $GLOBALS['TSFE']; |
|
| 767 | + } |
|
| 768 | 768 | |
| 769 | 769 | } |