[1.0.x] AI Field Module

Created on 28 December 2023, 9 months ago

Problem/Motivation

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇮🇳India abhishek.sa Indore

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

Comments & Activities

  • Issue created by @abhishek.sa
  • Status changed to Needs review 9 months ago
  • 🇮🇳India vishal.kadam Mumbai

    Thank you for applying!

    Please read Review process for security advisory coverage: What to expect for more details and Security advisory coverage application checklist to understand what reviewers look for. Tips for ensuring a smooth review gives some hints for a smoother review.

    The important notes are the following.

    • If you have not done it yet, you should run phpcs --standard=Drupal,DrupalPractice on the project, which alone fixes most of what reviewers would report.
    • For the time this application is open, only your commits are allowed.
    • The purpose of this application is giving you a new drupal.org role that allows you to opt projects into security advisory coverage, either projects you already created, or projects you will create. The project status won't be changed by this application and no other user will be able to opt projects into security advisory policy.
    • We only accept an application per user. If you change your mind about the project to use for this application, or it is necessary to use a different project for the application, please update the issue summary with the link to the correct project and the issue title with the project name and the branch to review.

    To the reviewers

    Please read How to review security advisory coverage applications , Application workflow , What to cover in an application review , and Tools to use for reviews .

    The important notes are the following.

    • It is preferable to wait for a Code Review Administrator before commenting on newly created applications. Code Review Administrators will do some preliminary checks that are necessary before any change on the project files is suggested.
    • Reviewers should show the output of a CLI tool only once per application.
    • It may be best to have the applicant fix things before further review.

    For new reviewers, I would also suggest to first read In which way the issue queue for coverage applications is different from other project queues .

  • Status changed to Needs work 9 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    • The following points are just a start and don't necessarily encompass all of the changes that may be necessary
    • A specific point may just be an example and may apply in other places
    • A review is about code that doesn't follow the coding standards, contains possible security issue, or doesn't correctly use the Drupal API; the single points aren't ordered, not even by importance

    src/Controller/AIFieldController.php

    /**
     * An example controller.
     */
    class AIFieldController extends ControllerBase {
    

    The description in that comment is not for that controller class, which is not just an example controller.

    $open_ai_key = \Drupal::config('ai_field.settings')->get('openai_api_key');

    Any dependency a controller has must be injected using the dependency injection container.

        $answer = new AIFieldController();
        $model_key = $model_value;
        $model = $answer->listModels()[$model_key];
    

    Controller instances are never created that way.
    In this case, it is not even necessary, since that code is executed by a non-static method of that controller.

    src/Form/AIFieldConfigurationForm.php

      /**
       * {@inheritdoc}
       */
      public function validateForm(array &$form, FormStateInterface $form_state) {
      }
    

    There is no need to implement an empty method.

        $this->config('ai_field.settings')
          ->set('openai_api_key', $values['openai_api_key'])
          ->save();
        \Drupal::messenger()->addMessage(t('OpenAI API Key has been saved'));
    

    The parent class already shows a message about the settings being saved. I am not sure there is the need to add a specific message.

    ai_field.module

        $open_ai_key = \Drupal::config('ai_field.settings')->get('openai_api_key');
        if (empty($open_ai_key)) {
          $form['actions']['submit']['#disabled'] = TRUE;
          \Drupal::messenger()->addError(t('Can not add AI field without setting OpenAI API Key.'));
        }
    

    That is code for a validation handler.

  • 🇮🇳India vishal.kadam Mumbai

    Fix phpcs issues.

    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml ai_field/
    
    
    FILE: ai_field/ai_field.info.yml
    ----------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------
     9 | ERROR | [x] Expected 1 newline at end of file; 0 found
    ----------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------
    
    
    FILE: ai_field/ai_field.routing.yml
    ----------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------
     7 | ERROR | [x] Expected 1 newline at end of file; 0 found
    ----------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------
    
    
    FILE: ai_field/ai_field.links.menu.yml
    ----------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------
     5 | ERROR | [x] Expected 1 newline at end of file; 0 found
    ----------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------
    
    
    FILE: ai_field/src/Plugin/Field/FieldWidget/AiFieldWidget.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------
      90 | WARNING | Unused variable $response.
     121 | WARNING | Unused variable $response.
    --------------------------------------------------------------------------------
    
    
    FILE: ai_field/src/Plugin/Field/FieldType/AiFieldType.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 10 WARNINGS AFFECTING 10 LINES
    --------------------------------------------------------------------------------
      74 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      82 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      89 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      98 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     107 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     115 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     124 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     134 | WARNING | #description values usually have to run through t() for translation
     163 | WARNING | #description values usually have to run through t() for translation
     171 | WARNING | #description values usually have to run through t() for translation
    --------------------------------------------------------------------------------
    
    
    FILE: ai_field/src/Form/AIFieldConfigurationForm.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------
     39 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     61 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     61 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    --------------------------------------------------------------------------------
    
    
    FILE: ai_field/src/Controller/AIFieldController.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------
     18 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     45 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    --------------------------------------------------------------------------------
    
  • Status changed to Needs review 9 months ago
  • 🇮🇳India abhishek.sa Indore

    Updated the code as per suggestions mentioned in #6.
    Also fix phpcs issues mentioned in #7.

  • 🇮🇳India rushiraval

    I am changing the issue priority as per issue priorities .

  • 🇮🇳India rushiraval

    I am changing the issue priority as per issue priorities .

  • There are some functions that have a blank line after the function signature. There doesn't need to be blank lines after a function's opening brace. One is in the tokens include file.

    ai_field.services.yml has an entry for a controller. Controls shouldn't have entries in the services YAML, since they aren't injected.

    For readability, I recommend that instead of using a class name like AIFieldConfigurationForm, you use AiFieldConfigurationForm, with "Ai", and do likewise for similar classes. There isn't a 100% required way to do it for acronyms, but Drupal does use StackedHttpKernel instead of StackedHTTPKernel, and I think that's good.

    This is pretty minor, but there are typos in the module description in composer.json:

    This is a AI Field for generating conetnt using OpenAI

  • Status changed to Needs work 4 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇳India vishal.kadam Mumbai

    I am changing priority as per Issue priorities .

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Actually, a page controller can also be a service method, but in that case the service does not extends ControllerBase.
    Structure of routes gives more details.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    That said, the ai_field.ai_field_services service is not used for a page controller. The only route defined in ai_field.routing.yml shows a form.

    ai_field.AIFieldConfigurationForm:
      path: '/admin/config/ai-field-form'
      defaults:
        _form: '\Drupal\ai_field\Form\AIFieldConfigurationForm'
        _title: 'AI Field'
      requirements:
        _permission: 'administer site configuration'
    
  • Status changed to Closed: won't fix 5 days ago
  • 🇮🇳India vishal.kadam Mumbai

    This thread has been idle, in the Needs work state with no activity for several months. Therefore, I am assuming that you are no longer pursuing this application, and I marked it as Closed (won't fix).

    If this is incorrect, and you are still pursuing this application, then please feel free to re-open it and set the issue status to Needs work or Needs review, depending on the current status of your code.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    This application waited four months for a review. Let's keep this application open for longer.

Production build 0.71.5 2024