[1.0.x] Personality Test

Created on 14 May 2024, 7 months ago

This module helps you figure out what kind of person you are. It usually has a bunch of questions for you to answer. After you finish, it gives you a report that explains your personality traits, like if you're outgoing or shy, organized or laid-back, and so on.

Project link

https://www.drupal.org/project/personality_assessment_test

📌 Task
Status

Needs review

Component

module

Created by

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

Comments & Activities

  • Issue created by @Harwinder
  • 🇮🇳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 7 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Usually, after reviewing a project, we allow the developer to opt projects into security advisory coverage. This project is too small for us and it doesn't contain enough PHP code to really assess your skills as developer.

    Have you created any other project on drupal.org (module, theme, distribution) we could instead review? The project needs to have most of the commits (preferable all the commits) done by you.

    Actually, I do not even see the code that should handle the features described in the issue summary.

  • Status changed to Needs review 7 months ago
  • Hi @all

    I modified my PHP code in my module according to your suggestion. Could you please take a look and review it?

  • Status changed to Active 7 months ago
  • 🇮🇳India rushiraval

    Please refer comment #4

  • Status changed to Needs work 7 months ago
  • Status changed to Needs review 7 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Now the project has PHP code. There is something that needs to be changed in the code, but at least there is PHP code, now.

  • Status changed to Needs work 7 months ago
  • 🇮🇳India vishal.kadam Mumbai

    1. Fix phpcs issues.

    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml personality_assessment_test/
    
    FILE: personality_assessment_test/personality_test.install
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     149 | ERROR | The array declaration extends to column 89 (the limit is 80). The array content should be split up over multiple lines
    --------------------------------------------------------------------------------
    
    FILE: personality_assessment_test/src/Plugin/Block/PersonalityTestQuizBlock.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     20 | WARNING | @author tags are not usually used in Drupal, because over time multiple contributors will touch the code anyway
    --------------------------------------------------------------------------------
    
    FILE: personality_assessment_test/src/Options.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     113 | ERROR | The array declaration extends to column 83 (the limit is 80). The array content should be split up over multiple lines
    --------------------------------------------------------------------------------
    
    FILE: personality_assessment_test/src/Controller/PersonalityTestController.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
    --------------------------------------------------------------------------------
     16 | WARNING | @author tags are not usually used in Drupal, because over time multiple contributors will touch the code anyway
     38 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     59 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    --------------------------------------------------------------------------------

    2. FILE: personality_test.module

    /**
     * @file
     * Primary module hooks for personality_test module.
     */

    The usual description for a .module file is Hook implementations for the [module name] module. where [module name] is the module name given in the .info.yml file.

    3. FILE: templates/personality-test-quiz.html.twig

    Move all scripts (JavaScript) and styles (CSS) into a library and attach them. See the process here .

  • 🇮🇹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 does not correctly use the Drupal API; the single points are not ordered, not even by importance

    personality_test.info.yml

    name: Personality Test
    type: module
    description: A Drupal module for integrating personality assessment functionality.
    package: Assessment
    core_version_requirement: ^9 || ^10
    

    There is no need to say Drupal module, since all the modules hosted on drupal.org are for Drupal.

    personality_test.install

    /**
     * Helper function to create a field.
     */
    function create_field($field_name, $label, $description, $required, $type, $target_type, $bundle, $target_vocabulary, $max_length = NULL, $default_checked = FALSE) {
    

    Every function must be a name that is prefixed by the module machine name, to avoid conflicts with other modules.

    /**
     * Implements hook_uninstall().
     */
    function personality_test_uninstall() {
    
      // Delete content type.
      $node_type = NodeType::load('personality_assessment_test');
      if ($node_type) {
        $node_type->delete();
      }
      // Delete fields associated with the content type.
      $fields_to_delete = ['field_personality-test_user_id', 'field_personality_test_result'];
      foreach ($fields_to_delete as $field_name) {
        $field_storage = FieldStorageConfig::loadByName('node', $field_name);
        if ($field_storage) {
          $field_storage->delete();
        }
      }
    
      // Delete all nodes of type 'personality_assessment_test'.
      $nodes = \Drupal::entityTypeManager()->getStorage('node')->loadByProperties(['type' => 'personality_assessment_test']);
      foreach ($nodes as $node) {
        $node->delete();
      }
    }
    

    In Drupal, modules that define a new content type do not delete the nodes of that content type, nor the content type.

    personality_test.module

    /**
     * @file
     * Primary module hooks for personality_test module.
     */
    
    

    Drupal does not have primary and secondary hooks. Instead of that, it is preferable to use the usual description: Hook implementations for the [module name] module. where [module name] is the name of the module given in its .info.yml file.

    /**
     * Implements hook_help().
     */
    function personality_test_help($route_name, RouteMatchInterface $route_match) {
      switch ($route_name) {
        case 'help.page.personality_test':
          // Return the help text for your module.
          $output = '<h3>' . t('About Personality Test Module') . '</h3>';
          $output .= '<p>' . t('The Personality Test module provides custom error display functionality.') . '</p>';
          return $output;
      }
    }
    

    The description is not for this module, since it does not provide any custom error display functionality.

    src/Controller/PersonalityTestController.php

     * @category CategoryName
     * @package YourPackageName
     * @author Your Name <your_email@example.com>
     * @license https://www.example.com/license YourLicenseName
     * @link https://www.example.com
     * @since PHP 7.4.0
    

    Those tags are not used in Drupal, and their content is placeholder content. @since is not correct, since that class is not a PHP class and it cannot be said to exist starting from PHP 7.4.

          $block_content = \Drupal::service('plugin.manager.block')
            ->createInstance('personality_test_quiz_block')
            ->build();
    

    Drupal controller classes do not add blocks to the page.

    if ($request->getMethod() === 'POST') {

    The controller renders a template file, which cannot be used to POST data. to gather information from users, a form must be used. (Drupal is not WordPress; it has a form API which must be used to gather information.)

            $node = Node::create(
                  [
                    'type' => 'personality_assessment_test',
                    'title' => 'Personality Assessment Result',
                    'field_personality_test_user_id' => $user_id,
                    'field_personality_test_result' => [
                      'value' => $content,
                      'format' => 'full_html',
                    ],
                  ]
              );
            $node->save();
    

    It is not clear why the controller creates a new node (without checking it already exists), which not even shown in someway to the users.

    src/Plugin/Block/PersonalityTestQuizBlock.php

       * @return \
       *   Response JSON or renderable array.
    

    \ is not a correct return type. Furthermore, it is not necessary to use @return, with {@inheritdoc}.

    src/Options.php

    Instead of using a class with a static method, which is used from a single class, it would be better to incorporate that method in the class using it.

    templates/personality-test-quiz.html.twig

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>

    Drupal already comes with the jQuery library. That is not the correct way to use the jQuery library in a page or a template file.

    I do not see any code that helps figure out what kind of person you are. It seems this module is "work in progress."

  • Hi @all

    I've made changes to my module based on your suggestions. I've included the link to my repository below. Could you please review it?

    Repository Link:-

    git@git.drupal.org:project/personality_assessment_test.git

    Branch Name:-

    1.0.x

    Commit Link

    https://git.drupalcode.org/project/personality_assessment_test/-/commit/...

    Previous Issue Comment

    #. It is not clear why the controller creates a new node (without checking it already exists), which is not even shown in some way to the users.

    Comment:: I did not delete the previous node because I needed to back up the previous user results. Therefore, after completing the assessment, a new node is created.

    #. I do not see any code that helps figure out what kind of person you are. It seems this module is a "work in progress."

    Comment:: It helps figure out to users understand their personality traits. This assessment evaluates various aspects of a user's personality and provides a detailed report based on the results.

  • Status changed to Needs review 7 months ago
  • Status changed to Needs work 7 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    The description of the module given in its README.md file is the following. (Emphasis is mine.)

    > This module helps figure out what kind of person you are. It usually has a bunch of questions for you to answer. After you finish, it gives you a report that explains your personality traits, like if you're outgoing or shy, organized or laid-back, and so on.

    In Drupal, the correct way to ask for information to users is via a form. The module does not implement any form.
    The correct way to show information based on what entered in a form is via the form submission handler. The module does not have any form submission handler. Furthermore, I do not see any code that would tell the users they are shy, laid-back, etc.

    A controller does not need any block to show information via a template file. a Controller class can output directly a render array, which (via #theme) can also use a template file.

  • Status changed to Needs review 7 months ago
  • Hi @all

    Previous Issue Comment

    #. The description of the module given in its README.md file is the following. (Emphasis is mine.)

    > This module helps figure out what kind of person you are. It usually has a bunch of questions for you to answer. After you finish, it gives you a report that explains your personality traits, like if you're outgoing or shy, organized or laid-back, and so on.

    Furthermore, I do not see any code that would tell the users they are shy, laid-back, etc.

    Comment::
    This module is currently designed to help users gain insight into their personality traits. Through a series of questions, users can complete a test that assesses their Dominance (D), Influence (I), Steadiness (S), and Conscientiousness (C) traits. Once the test is completed, users receive a detailed report indicating the percentage of each trait they possess. This information is then saved in their node with the content type "Personality Assessment Test," allowing them to reference and track their results over time.

    I've made changes to my README.md & controller file. I will update the description of README.md as my module will work currently. Could you please review it?

    #. In Drupal, the correct way to ask for information from users is via a form. The module does not implement any form.
    The correct way to show information based on what is entered in a form is via the form submission handler. The module does not have any form submission handler.

    Comment:: This module does not include any form because JavaScript is used to display questions on the page through a block. As a result, there's no need for a form in this module.

    Repository Link:-

    git@git.drupal.org:project/personality_assessment_test.git

    Branch Name:-

    1.0.x

    Commit Link

    https://git.drupalcode.org/project/personality_assessment_test/-/commit/...

  • Status changed to Needs work 7 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    In Drupal, the correct way to ask information to users is using the form API, and the correct way to store the entered information is using the database API, not creating a new node every time a user visit the controller page. A controller shows its output directly, not via a block, since in Drupal which blocks are rendered in a page, in which pages they are rendered, and in which position, is decided from the site settings, not from modules.

  • 🇮🇳India vishal.kadam Mumbai

    I am changing priority as per Issue priorities .

  • Status changed to Closed: won't fix 3 months 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, 🇮🇹
Production build 0.71.5 2024