passionweb-manuel-schnabel / ai-seo-helper

Generates SEO metadata based on content using AI. Currently several metadata for pages and articles of EXT:news can be generated using an additional button next to the corresponding input fields.
9 stars 5 forks source link

Allow multiple fields for text generation #4

Closed thomasrawiel closed 1 year ago

thomasrawiel commented 1 year ago

Hi, I would like to extend the extension's functionality to other fields like og_title, og_description etc.

I added the following in my own TCA/Overrides/pages.php

if(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('ai_seo_helper')){
        $GLOBALS['TCA']['pages']['columns']['og_description']['config'] = array_merge_recursive(
            $GLOBALS['TCA']['pages']['columns']['og_description']['config'],
            [
                'fieldControl' => [
                    'importControl' => [
                        'renderType' => 'aiSeoMetaDescription'
                    ]
                ]
            ]
        );
        $GLOBALS['TCA']['pages']['columns']['twitter_description']['config'] = array_merge_recursive(
            $GLOBALS['TCA']['pages']['columns']['twitter_description']['config'],
            [
                'fieldControl' => [
                    'importControl' => [
                        'renderType' => 'aiSeoMetaDescription'
                    ]
                ]
            ]
        );

        $GLOBALS['TCA']['pages']['columns']['og_title']['config'] = array_merge_recursive(
            $GLOBALS['TCA']['pages']['columns']['og_title']['config'],
            [
                'fieldControl' => [
                    'importControl' => [
                        'renderType' => 'aiSeoPageTitle'
                    ]
                ]
            ]
        );

        $GLOBALS['TCA']['pages']['columns']['twitter_title']['config'] = array_merge_recursive(
            $GLOBALS['TCA']['pages']['columns']['twitter_title']['config'],
            [
                'fieldControl' => [
                    'importControl' => [
                        'renderType' => 'aiSeoPageTitle'
                    ]
                ]
            ]
        );
    }

The button appears next to the fields, but when clicking it doesn't do anything.

It appears that the button only works for the first field of a kind because the eventhandler is added only to the first occurence of id=generatePageTitle for example

passionweb-manuel-schnabel commented 1 year ago

Hi Thomas,

thank you for your request.

I am currently working on optimizations in general and I am trying to integrate the topic "(dynamic) expansions to other fields". However, this is currently difficult because I temporarily integrate the output of the PageTitleSuggestions, for example, directly below the field via Javascript and this is directly linked to the field.

So you are right that an extension without deeper code intervention is currently not possible.

But what I can offer you is that along with my other optimizations over the course of the week, I will also include your desired fields and build in the generation accordingly. I can't promise you whether I'll get the point mentioned above with the dynamic expansion in a timely manner (mainly due to time constraints).

I would be happy to get a little info on whether I could help you with that first?

Greetings Manu

thomasrawiel commented 1 year ago

Hey Manu, we're currently testing the extension and the quality of the AIs answers. I was just trying to expand it to other fields in case the PM asks for it.

No need to stress yourself.

As for the dynamic expansion I'm pretty sure it's just a matter of some javascript adjustments - classes instead of id's, queryselectorall instead of getelementbyid etc.

Take your time. :-)

passionweb-manuel-schnabel commented 1 year ago

Hey Thomas,

I have now made the appropriate adjustments so that the Open Graph and Twitter fields can now also be generated.

Furthermore, generated page titles and meta descriptions can also be transferred to the corresponding Open Graph and Twitter fields.

Technically, I have adapted/reduced the JavaScript files in such a way that static IDs are no longer used when generating the suggestions, but are composed of the selected field. This should also make it easier to expand to other fields in the future.

More detailed guidance for developers on this would certainly be helpful. I will add this point to the documentation as soon as possible.

I will also release the new version (0.5.0) later today and upload it to TER.