Created
December 6, 2019 16:20
-
-
Save Schweriner/ef4c32f27c131922fef7381be252766a to your computer and use it in GitHub Desktop.
TYPO3 File Reference Fields Required using a small Require JS Modul (Title, Alternative, Description...)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!defined('TYPO3_MODE')) { | |
die('Access denied.'); | |
} | |
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin( | |
'TGM.' . 'tgm_copyright', | |
'Main', | |
[ | |
'Copyright' => 'list,sitemap', | |
], | |
// non-cacheable actions | |
[ | |
'Copyright' => 'sitemap', | |
] | |
); | |
if (TYPO3_MODE === "BE" && true === version_compare(TYPO3_branch, '9.5', '>=') ) { | |
if(true === (bool) \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Configuration\ExtensionConfiguration::class) | |
->get('tgm_copyright', 'copyrightRequired')) { | |
$pageRenderer = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class); | |
$pageRenderer->loadRequireJsModule('TYPO3/CMS/TgmCopyright/RequiredFileReferenceFields'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['jquery'], function($) { | |
$(document).on('t3-formengine-postfieldvalidation',function() { | |
validateReferenceFields(); | |
}); | |
$(document).on('change','.t3js-form-field-eval-null-placeholder-checkbox input', function() { | |
validateReferenceFields(); | |
}); | |
function validateReferenceFields() { | |
var $referenceFields = $('.t3js-formengine-placeholder-formfield input[type="hidden"][name$="[copyright]"]'); | |
$referenceFields.each(function() { | |
var $parentFieldGroup = $(this).closest('.t3js-formengine-palette-field'); | |
if($(this).parents('.t3js-inline-record-deleted').length === 0) { | |
if(false === $parentFieldGroup.find('.t3js-form-field-eval-null-placeholder-checkbox input').is(':checked') | |
&& $parentFieldGroup.find('.t3js-formengine-placeholder-placeholder input').val().toString() === '') { | |
$parentFieldGroup.addClass('has-error'); | |
} else if(true === $parentFieldGroup.find('.t3js-form-field-eval-null-placeholder-checkbox input').is(':checked') | |
&& $(this).val().toString() === '') { | |
$parentFieldGroup.addClass('has-error'); | |
} else { | |
$parentFieldGroup.removeClass('has-error'); | |
} | |
} else { | |
$parentFieldGroup.removeClass('has-error'); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 12 of the JS is made to fit only with the related extensions "copyright"-field of File References. But this selector can be replaced to fit any other field of file references like the title or alternative text.