Issue Task Resolved

#106584Re-add the manual argument registration for "href" and "src"

Daniel Kruse 04/17/25, 07:06 updated 08/26/26, 05:35

Description

Original Report: https://github.com/TYPO3/Fluid/issues/1043

Hello all,

my phpstorm reads the registered arguments, and gives me some errors when using some viewhelper.
Here is a brief list, may not be complete:

“f:image” doesn’t declare “alt”, but needs it
“f:asset.css” doesn’t declare “href”, but needs it
“f:asset.script” doesn’t declare “src” and “type” , but needs / uses it

would be nice to have those back :)

Have a nice day
Daniel Kruse

Reviews 1

History 810

  1. Garvin Hicking commented and changed status New Needs Feedback 04/17/25, 07:36

    Can you elaborate why PHPStorm draws this conclusion? The mentioned attributes are not mandatory; they are neither listed as ‘required’ in the VH itself, nor in the XSD definition of our viewhelpers.

    I guess that PHPStorm tries to be clever and see that a ‘script’ or ‘image’ or ‘css’ tag is used here, and tries to apply “HTML knowledge”.

    This would though be a bug in PHPStorm, not TYPO3, and would need adjustments in PHPStorm.

    Maybe if you can find out more about this we could address it, otherwise we would need to close the issue on our side…?

    Thanks for bringing this up,
    Garvin

  2. Daniel Kruse commented 04/17/25, 07:55

    Well, i give you the code for the CssViewHelper:

        public function initializeArguments(): void
        {
            parent::initializeArguments();
            $this->registerArgument('disabled', 'bool', 'Define whether or not the described stylesheet should be loaded and applied to the document.');
            $this->registerArgument('useNonce', 'bool', 'Whether to use the global nonce value', false, false);
            $this->registerArgument('identifier', 'string', 'Use this identifier within templates to only inject your CSS once, even though it is added multiple times.', true);
            $this->registerArgument('priority', 'boolean', 'Define whether the CSS should be included before other CSS. CSS will always be output in the <head> tag.', false, false);
            $this->registerArgument('inline', 'bool', 'Define whether or not the referenced file should be loaded as inline styles (Only to be used if \'href\' is set).', false, false);
        }
    
        public function render(): string
        {
            $identifier = (string)$this->arguments['identifier'];
            $attributes = $this->tag->getAttributes();
    
            // boolean attributes shall output attr="attr" if set
            if ($this->arguments['disabled'] ?? false) {
                $attributes['disabled'] = 'disabled';
            }
    
            $file = $attributes['href'] ?? null;
            unset($attributes['href']);
            $options = [
                'priority' => $this->arguments['priority'],
                'useNonce' => $this->arguments['useNonce'],
            ];
            /* shortend here */
    
            return '';
        }

    and the parent function:

        public function initializeArguments()
        {
            $this->registerArgument('additionalAttributes', 'array', 'Additional tag attributes. They will be added directly to the resulting HTML tag.');
            $this->registerArgument('data', 'array', 'Additional data-* attributes. They will each be added with a "data-" prefix.');
            $this->registerArgument('aria', 'array', 'Additional aria-* attributes. They will each be added with a "aria-" prefix.');
        }

    in this case, it would be nice to register the optional argument “href” like this again

        $this->registerArgument('href', 'string', 'The path to the css file', false, null);

    i think, this is the reason why phpStorm (with a typo3 plugin) thinks the href is not a valid argument.
    Same applies to the other issue i mentioned

    Thank you

  3. Garvin Hicking changed description 04/17/25, 08:35

  4. Simon Praetorius commented 04/17/25, 09:34

    Can you add a list here of arguments you would like to re-add? As already mentioned, this should only include arguments that have special handling in the ViewHelper and are not just passed through. Then we can discuss which ones we could add again, which would also help in the automatic ViewHelper reference.

    What we shouldn’t do is add a lot of them, which will make it harder again to find the arguments that are actually relevant for the ViewHelper’s behavior.

  5. Daniel Kruse commented 04/17/25, 09:43

    I had my list open for some weeks, and i only missed these three arguments.

    f:asset.css -> href
    f:asset.script -> src
    f:image -> alt
    (so my collegues won’t forget the alt text)

    don’t know where “type” (above) came from, but this sums it up for me

  6. Rico Sonntag commented and changed priority Should have Must have 06/13/25, 10:27

    This just caught my attention. PHPStorm is warning me that various attributes are obsolete, even though they aren’t, based on the code. What was the reason for removing the attributes from the ViewHelpers (https://github.com/TYPO3-CMS/fluid/commit/aa378389fe58edb168a3952db3ba692f1d72bf6e)? All attributes used in a ViewHelper should be listed in “initializeArguments” so that PHPStorm extensions (e.g., https://plugins.jetbrains.com/plugin/11151-typo3-fluid—enterprise) can read them and suggest them during autocompletion. How else would you know which attributes the ViewHelper supports? There’s no point in digging through all the ViewHelpers to see if there’s a hidden attribute.

  7. Simon Praetorius commented 06/13/25, 13:27

    Daniel Kruse wrote in #note-5:
    > f:asset.css -> href
    > f:asset.script -> src
    > f:image -> alt

    I think those three would be valid to add as registered arguments, since all of them are used in the PHP code of these ViewHelpers. If you’re able to, feel free to provide a patch. Also, don’t hesitate to contact me directly if there are any questions about that.

    > PHPStorm is warning me that various attributes are obsolete

    The key feature is this one: https://github.com/TYPO3/Fluid/pull/859. So the rule is now: All tag-based ViewHelpers support any attribute. That is also how we implemented it in the XSD generator that ships with TYPO3 v13 out-of-the-box: https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.2/Feature-104114-CommandToGenerateFluidSchemaFiles.html

  8. Gerrit Code Review pushed patch set 1 for main to change 95397 status Needs Feedback Under Review 08/24/26, 16:20

  9. Gerrit Code Review pushed patch set 2 for main to change 95397 08/24/26, 16:29

  10. Benjamin Kott commented and changed status Under Review Resolved done 0 % 100 % 08/26/26, 05:35

    Applied in changeset commit:1af492d7bd5978f927d37fe05a56d4aafd4055bf.