Defaults for extraAdvancedFormFields (text manipulation and find similar tags)

Created on 3 October 2024, about 2 months ago

I setup the automator on a tags field. I selected First character uppercase and checked the find similar tags box on the settings under the Provider configuration.

This saved correctly to the ai_automators.ai_automator.node.article.field_tags.default.yml.

automator_clean_up: first_char
automator_search_similar_tags: 1

When I returned to the edit form for the same tags field on my article content type, the form did not remember my selection.

πŸ› Bug report
Status

Active

Version

1.0

Component

AI Automators

Created by

πŸ‡ΊπŸ‡ΈUnited States keiserjb

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @keiserjb
  • πŸ‡ΊπŸ‡ΈUnited States keiserjb
  • Merge request !134Update Taxonomy.php β†’ (Closed) created by keiserjb
  • πŸ‡ΊπŸ‡ΈUnited States keiserjb

    This version of the form works for me.

    public function extraAdvancedFormFields(ContentEntityInterface $entity, FieldDefinitionInterface $fieldDefinition, FormStateInterface $formState, array $defaultValues = []) {
        $form = parent::extraAdvancedFormFields($entity, $fieldDefinition, $formState, $defaultValues);
        $settings = $fieldDefinition->getConfig($entity->bundle())->getSettings();
    
        $form['automator_clean_up'] = [
          '#type' => 'select',
          '#title' => $this->t('Text Manipulation'),
          '#description' => $this->t('These are possible text manipulations to run on each created tag.'),
          '#options' => [
            '' => $this->t('None'),
            'lowercase' => $this->t('lowercase'),
            'uppercase' => $this->t('UPPERCASE'),
            'first_char' => $this->t('First character uppercase'),
          ],
          // Use the default value from the third-party settings or fallback to a default.
          '#default_value' => $fieldDefinition->getConfig($entity->bundle())
            ->getThirdPartySetting('ai_automators', 'automator_clean_up', 'first_char'), // Ensure fallback here
          '#weight' => 23,
        ];
    
        $form['automator_clean_up'] = [
          '#type' => 'select',
          '#title' => $this->t('Text Manipulation'),
          '#description' => $this->t('These are possible text manipulations to run on each created tag.'),
          '#options' => [
            '' => $this->t('None'),
            'lowercase' => $this->t('lowercase'),
            'uppercase' => $this->t('UPPERCASE'),
            'first_char' => $this->t('First character uppercase'),
          ],
          // Use the default value from the third-party settings or fallback to a default.
          '#default_value' => $fieldDefinition->getConfig($entity->bundle())
            ->getThirdPartySetting('ai_automators', 'automator_clean_up', 'first_char'), // Ensure fallback here
          '#weight' => 23,
        ];
    
        if ($settings['handler_settings']['auto_create']) {
          $form['automator_search_similar_tags'] = [
            '#type' => 'checkbox',
            '#title' => 'Find similar tags',
            '#description' => $this->t('This will use GPT-4 to find similar tags. Meaning if the tag "Jesus Christ" exists and the system wants to store "Jesus" it will store it as "Jesus Christ". This uses extra calls and is slower and more costly.'),
            '#default_value' => $fieldDefinition->getConfig($entity->bundle())
              ->getThirdPartySetting('ai_automators', 'automator_search_similar_tags', 1), // Ensure fallback here
            '#weight' => 23,
          ];
        }
    
        return $form;
      }
  • πŸ‡ΊπŸ‡ΈUnited States keiserjb
  • Pipeline finished with Failed
    about 2 months ago
    Total: 171s
    #299978
  • πŸ‡ΊπŸ‡ΈUnited States keiserjb
  • πŸ‡©πŸ‡ͺGermany marcus_johansson

    Thank you @keiserjb! Actually that wont work either, we moved from thirdpartysettings to configuration entities, so the way would be to look in the $defaultValues array.

    If you want to add a MR, feel free to do so. If not I'll try to fix it during the weekend. I'll credit you anyway for finding the bug. If you do add a MR, look at the pipeline to make sure it passes all the tests.

  • πŸ‡©πŸ‡ͺGermany marcus_johansson

    I fixed this, it merged and can be tested on the dev branch.

  • πŸ‡ΊπŸ‡ΈUnited States keiserjb

    Thank you, I didn't turn on my work computer over the weekend.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024