Created on 20 June 2023, over 1 year ago
Updated 27 September 2023, about 1 year ago

The main purpose of this module is that you can read the content of the image and assign it to the title, alt, description of the image, or a specified text field.
If you use file field, the module also extends to read the contents of the input file images, PDF, Office (doc, docx, xls, xlsx, ...).

Project link

https://www.drupal.org/project/ocr_image →

📌 Task
Status

Fixed

Component

module

Created by

🇫🇷France lazzyvn paris

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

Comments & Activities

  • Issue created by @lazzyvn
  • 🇮🇳India shashank5563 New Delhi

    Thank you for applying! Reviewers will review the project files, describing what needs to be changed.

    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.

    To reviewers: Please read How to review security advisory coverage applications → , What to cover in an application review → , and Drupal.org security advisory coverage application workflow → .

    While this application is open, only the user who opened the application can make commits to the project used for the application.

    Reviewers only describe what needs to be changed; they don't provide patches to fix what reported in a review.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇮🇳India vinaymahale

    Ran PHPCS tests. No issues were found. Let's wait for other reviewers

  • 🇮🇳India shashank5563 New Delhi

    @lazzyvn , I have reviewed the changes, and they look fine to me.

    Let’s wait for other reviewers to take a look and if everything goes fine, you will get the role.

  • 🇫🇷France lazzyvn paris

    thanks

  • 🇮🇳India vinaymahale

    I am changing priority as per Issue priorities.

  • 🇲🇩Moldova andrei.vesterli Chisinau

    Hi @lazzyvn

    First of all, good job, and thx for the contribution to Drupal community! Here you can find some issues to fix:

    • File: js/ocr-image.js
      Line 10:
      let editorId = $("textarea[name*='" + field + "[0][value]']").prop("id");
      if(typeof CKEDITOR !== 'undefined' && CKEDITOR.instances[editorId] != undefined){
        let editor = CKEDITOR.instances[editorId].setData(ocr);
      }
      if(typeof CKEditor5 !== 'undefined'){
        editorId = $("textarea[name*='" + field + "[0][value]']").data("ckeditor5-id");
        let editor = Drupal.CKEditor5Instances.get(editorId).setData(ocr);
      }
      I don't see any purpose of these lines. You can simply remove them.
      
    • File: js/orc-image.js
      Line: 1 (function ($, Drupal, drupalSettings, once) {...
      one > is not used, so, remove that from init.
    • File: composer.json
      Line: 6 "license": "GPL-2.0+",
      Use "license": "GPL-2.0-or-later", instead. Check this → documentation for more information about composer.json configuration.
    • File: src/Plugin/Field/TesseractLanguages.php
      Class: TesseractLanguages
      • Missing return type for the defined methods for ex: tesseractConvertLang: string { ... }
      • Usage of `t()` function is not correct. Just add the translation trait instead Drupal\Core\StringTranslation\StringTranslationTrait.
    • Files: src/Plugin/Field/FieldWidget/OcrImageWidget.php, src/Plugin/Field/FieldWidget/OcrFileWidget.php
      Comments: Check the return type for getLinesText, getPowerpointType
    • Code:
      if (!empty($field_text_name = $this->getSetting('text_field'))) {
        $fid = $form_state->getValue($field_name);
        if (!empty($fid)) {
          if (is_array($fid)) {
            $fid = end($fid);
            if (is_array($fid) && !empty($fid["fids"])) {
              $fid = end($fid["fids"]);
            }
          }
          $file = File::load($fid);
          $uri = $file->getFileUri();
          $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager')
            ->getViaUri($uri);
          $file_path = $stream_wrapper_manager->realpath();
          $language = $this->getSetting('language');
          if (empty($language)) {
            $language = TesseractLanguages::tesseractConvertLang();
          }
          $line_datas = $this->getLinesText($file_path, $language, $this->getSetting('limit'));
          if (!empty($line_datas)) {
            $ocr = implode(PHP_EOL, $line_datas);
            $form_state->setValue($field_text_name, $ocr);
            $element["#default_value"]["description"] = $ocr;
            $element['#attached']['drupalSettings']['ocr_field_widget'] = [
              'field_name' => $field_name,
              'field' => $field_text_name,
              'ocr' => $ocr,
            ];
            $element['#attached']['library'][] = 'ocr_image/ocr_image';
          }
        }
      }
      

      can be converted to something like:

      if (!empty($field_text_name = $this->getSetting('text_field')) && $fid = $form_state->getValue($field_name) && !empty($fid)) {
        if (is_array($fid)) {
          $fid = end($fid);
          if (is_array($fid) && !empty($fid["fids"])) {
            $fid = end($fid["fids"]);
          }
        }
        $file = File::load($fid);
        $uri = $file->getFileUri();
        $stream_wrapper_manager = \Drupal::service('stream_wrapper_manager')->getViaUri($uri);
        $file_path = $stream_wrapper_manager->realpath();
        $language = $this->getSetting('language');
        if (empty($language)) {
          $language = TesseractLanguages::tesseractConvertLang();
        }
        $line_datas = $this->getLinesText($file_path, $language, $this->getSetting('limit'));
        if (!empty($line_datas)) {
          $ocr = implode(PHP_EOL, $line_datas);
          $form_state->setValue($field_text_name, $ocr);
          $element["#default_value"]["description"] = $ocr;
          $element['#attached']['drupalSettings']['ocr_field_widget'] = [
            'field_name' => $field_name,
            'field' => $field_text_name,
            'ocr' => $ocr,
          ];
         $element['#attached']['library'][] = 'ocr_image/ocr_image';
        }
      }
      
    • Convert file Readme.md into the REAMDE.md. Provide proper basic module documentation. See this → example.
  • Status changed to Needs work about 1 year ago
  • 🇲🇩Moldova andrei.vesterli Chisinau
  • 🇫🇷France lazzyvn paris

    @andrei.vesterli
    thank you for your correction.
    but i don't know how to fix this

    Using the t() function is not correct. Just add the translation trait instead Drupal\Core\StringTranslation\StringTranslationTrait.

    This is a static method (public static function), so I think we cann't use StringTranslationTrait and replace t() with $this->t(), right?
    another point is fixed in branch dev

  • 🇲🇩Moldova andrei.vesterli Chisinau

    As a variant:

    use Drupal\Core\StringTranslation\TranslatableMarkup;
    
    // Usage
    new TranslatableMarkup('Some string');
    
  • 🇫🇷France lazzyvn paris

    @andrei.vesterli

    I tested the code in Drupal 9.5 and 10.1.2, it doesn't work when uploading a pdf, image, docx file. revert to old code, it works fine
    I don't know why it can't get fid as number after upload.

    
    if (!empty($field_text_name = $this->getSetting('text_field')) && $fid = $form_state->getValue($field_name) && !empty($fid)) {
    
  • 🇲🇩Moldova andrei.vesterli Chisinau

    Hi @lazzyvn

    No worries. Leave as you did then. I have no other comments for now. Let's see someone else to review your module. Cheers man!

    Regards,
    Andrei

  • Status changed to Needs review about 1 year ago
  • 🇲🇩Moldova andrei.vesterli Chisinau
  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    Thank you for your contribution! I am going to update your account.

    These are some recommended readings to help with excellent maintainership:

    You can find more contributors chatting on the Slack → #contribute channel. So, come hang out and stay involved → .
    Thank you, also, for your patience with the review process.
    Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review → . I encourage you to learn more about that process and join the group of reviewers.

    I thank all the reviewers.

  • Assigned to apaderno
  • Status changed to Fixed about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024