Project

General

Profile

Actions

Bug #90299

closed

addCssFile() for BE iframe "typo3-contentIframe"

Added by Michael Sollmann about 4 years ago. Updated about 4 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Backend User Interface
Target version:
-
Start date:
2020-02-02
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
9
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

Assigning a css file to the BE via \TYPO3\CMS\Core\Page\PageRenderer::addCssFile() injects the file only into the main BE page, but not into the iframe "typo3-contentIframe", so one cannot style the iframe content.

The assignment via $GLOBALS['TBE_STYLES']['skins'] injects the file in both, the main page and the iframe. But with that one cannot assign different files
dynamically depending e.g. on a user group.

addCssFile() should inject the css file also into the iframe, so as $GLOBALS['TBE_STYLES']['skins'] does.

Actions #1

Updated by Nikita Hovratov about 4 years ago

For me this works. I tested in v9 and v10 master.
Can you provide a specific setup where this happens to you?

Actions #2

Updated by Michael Sollmann about 4 years ago

ext_tables.php:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/backend.php']['constructPostProcess'][] = \[Vendor]\[Ext]\Hooks\BackendStyles::class.'->addCss';

typo3conf/ext/[Ext]/Classes/Hooks/BackendStyles.php:
[...]
$pageRenderer = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class);
$cssPath = ExtensionManagementUtility::extPath('[Ext]').'Resources/Public/Css/Backend/';
$pageRenderer->addCssFile($cssPath.'bv.css');
[...]

Output:
1.
/typo3/index.php?route=%2Fmain[...] (the main BE page):
[...]
<link rel="stylesheet" type="text/css" href="/typo3conf/ext/[Ext]/Resources/Public/Css/Backend/bv.css" media="all">
[...]

2.
/typo3/index.php?route=%2Fweb%2Flist%2F[...] (the list_frame/typo3-contentIframe inside the main BE page):
No bv.css!

Hard coded solution:
/typo3/sysext/backend/Classes/Template/ModuleTemplate.php:
protected function loadStylesheets() {
[...]
$cssPath = ExtensionManagementUtility::extPath('[Ext]').'Resources/Public/Css/Backend/';
$pageRenderer->addCssFile($cssPath.'bv.css');
[...]
}

Output:
1.
/typo3/index.php?route=%2Fmain[...] (the main BE page):
No bv.css!

2.
/typo3/index.php?route=%2Fweb%2Flist%2F[...] (the list_frame/typo3-contentIframe inside the main BE page):
[...]
<link rel="stylesheet" type="text/css" href="/typo3conf/ext/[Ext]/Resources/Public/Css/Backend/bv.css" media="all">
[...]

Actions #3

Updated by Nikita Hovratov about 4 years ago

Hello,

thank you for your code example!
The hook you used is only executed in the main function of the BackendController. Once The PageRenderer renders the final html he resets all added Css.
After that the current submodule starts the rendering again without your css.
This means you need to register your css globally.
Typo3 Backend uses this global array to register its backend.css:

$GLOBALS['TBE_STYLES']['skins'][] = [
    'stylesheetDirectories' => [
       'EXT:your_ext/Resources/Public/Css/Backend/'
    ]
];

Putting this in your ext_tables.php should do the trick!

Actions #4

Updated by Michael Sollmann about 4 years ago

Yes, this would do the trick, but not for different user groups, as I think. In my first statement I wrote:

The assignment via $GLOBALS['TBE_STYLES']['skins'] injects the file in both, the main page and the iframe. But with that one cannot assign different files
dynamically depending e.g. on a user group.

Or is that possible via an alternative way?

Actions #5

Updated by Nikita Hovratov about 4 years ago

This does the trick:

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_pagerenderer.php']['render-preProcess'][] = \VENDOR\NAME\Hooks\BackendStyles::class . '->addCss';

Your BackendStyles Class:

<?php

namespace VENDOR\NAME\Hooks;

use TYPO3\CMS\Core\Utility\GeneralUtility;

class BackendStyles
{
    public function addCss($params, $ref)
    {
        // The global BE_USERS array is available here and you can add your additional conditions.
        if (TYPO3_MODE == 'BE') {
            $ref->addCssFile(GeneralUtility::getFileAbsFileName('EXT:your_ext/Resources/Public/Css/Backend/bv.css'));
        }
    }
}

I hope this helps!

Actions #6

Updated by Michael Sollmann about 4 years ago

Yes, it works, great!
Thank you very much!

Actions #7

Updated by Georg Ringer about 4 years ago

  • Status changed from New to Resolved
Actions #8

Updated by Benni Mack about 4 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF