[2.0.x] Custom Field

Created on 31 July 2023, about 1 year ago
Updated 27 September 2023, about 1 year ago

This module provides a user interface to create "custom" fields. The intent of this module is to substantially enhance performance by encouraging flat table architecture where feasible and eliminate unnecessary table joins and use of entity reference fields for simple data structures. Drupal's field api while flexible and generally user friendly to create content models is often misused in large applications. Consider a scenario of a nutrition app where a "food" entity has several nutrient columns to store data in. There are over a 100 different nutrients for example in the publicly available USDA food database. If we were to model that with standard field api fields for every column, the amount of table joins alone for CRUD actions would be a huge performance bottleneck. Also consider the configuration storage, caching considerations and integrations with search api, etc... This type of model should be avoided. Seasoned developers would ideally opt in to creating their own custom field to store this data in single table. The challenge with this however is it can be quite cumbersome to create all of the form structure, formatters, etc. with the flexibility to customize and scale when simple changes are needed. This module provides a widget plugin architecture to do just that, provide flexible and scalable content modeling out of the box which ultimately saves developers a substantial amount of time.

Notably, an additional benefit of this module is that the extensive widget options already provided by this module may eliminate the need for various core and contrib modules. Reducing module overhead is always a great thing and because these widgets are plugins, they can easily be extended and customized further by other developers while having a reliable starting base.

Similar modules

https://www.drupal.org/project/flexfield → - This module has fewer widgets and stores everything as varchar. There are various unresolved bugs and no path forward to add/remove columns. My module is actively maintained and in much more stable position.

https://www.drupal.org/project/datafield → - This module was created after mine. It's marked as stable release yet has no unit testing. My module differs considerably in the architecture since the widgets are plugins which makes it extendable by design. Data field like flexfield has no path forward as far as I know to handle add/remove columns.

Manual review of other applications

https://www.drupal.org/project/projectapplications/issues/3376027#commen... →

Project link

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

📌 Task
Status

Fixed

Component

module

Created by

🇺🇸United States apmsooner

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

Comments & Activities

  • Issue created by @apmsooner
  • 🇺🇸United States apmsooner
  • 🇮🇳India vishal.kadam Mumbai

    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.

  • Status changed to Needs work about 1 year ago
  • 🇮🇳India vinaymahale

    Please fix the below PHPCS issues:

    FILE: /custom_field/src/Plugin/Field/FieldWidget/CustomWidget.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 16 WARNINGS AFFECTING 16 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
      47 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      48 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      57 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      58 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      95 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      96 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     114 | 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
     116 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     162 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     163 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     164 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     165 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     179 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     180 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     181 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/Field/FieldWidget/CustomWidgetBase.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 9 WARNINGS AFFECTING 9 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
      85 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      90 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      93 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      94 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      95 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     105 | 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
     125 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     127 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/Field/FieldFormatter/CustomInlineFormatter.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 7 WARNINGS AFFECTING 7 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
      46 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      55 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      66 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      79 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      81 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      83 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     100 | WARNING | Unused variable $name.
    ------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/Field/FieldFormatter/CustomTableFormatter.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------------------------
     28 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    -----------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/Field/FieldFormatter/CustomListFormatter.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
    -----------------------------------------------------------------------------------------------------------------------------------------
     42 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     44 | WARNING | #options values usually have to run through t() for translation
     45 | WARNING | #options values usually have to run through t() for translation
     61 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    -----------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/Field/FieldFormatter/CustomTemplateFormatter.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
    -----------------------------------------------------------------------------------------------------------------------------------------
     51 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     52 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     64 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    -----------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/Field/FieldFormatter/CustomFormatter.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    -----------------------------------------------------------------------------------------------------------------------------------------
     53 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     72 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    -----------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/Telephone.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 12 WARNINGS AFFECTING 12 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
      98 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     105 | 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
     111 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     112 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     119 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     125 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     128 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     133 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     136 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     150 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     153 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/Email.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
    -----------------------------------------------------------------------------------------------------------------------------------------
     68 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     75 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     77 | 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
    -----------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/FloatType.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 5 WARNINGS AFFECTING 5 LINES
    -----------------------------------------------------------------------------------------------------------------------------------------
     77 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     79 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     80 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     86 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     90 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    -----------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/Text.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 11 WARNINGS AFFECTING 11 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
      97 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     104 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     106 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     110 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     111 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     118 | 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
     127 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     132 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     135 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     149 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/Decimal.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 5 WARNINGS AFFECTING 5 LINES
    -----------------------------------------------------------------------------------------------------------------------------------------
     71 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     73 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     74 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     80 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     84 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    -----------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/NumericBase.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 11 WARNINGS AFFECTING 11 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
      87 | 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
      94 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      97 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     103 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     106 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     112 | 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
     120 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     123 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     137 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/MapKeyValue.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 13 WARNINGS AFFECTING 13 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
      46 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      47 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      54 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      55 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     112 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     113 | 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
     131 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     138 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     152 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     244 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     246 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     247 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/Url.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 7 WARNINGS AFFECTING 7 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
      71 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      78 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      80 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      84 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      85 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
      92 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     105 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/Color.php
    -----------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------
     32 | WARNING | Unused variable $settings.
    -----------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/ListBase.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 14 WARNINGS AFFECTING 14 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
     109 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     110 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     117 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     119 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     120 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     129 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     159 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     166 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     180 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     200 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     202 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     203 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     204 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     258 | WARNING | Unused variable $key.
    ------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/Textarea.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 12 WARNINGS AFFECTING 12 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
     101 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     102 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     109 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     111 | 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
     120 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     131 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     140 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     145 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     150 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     151 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     157 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/Checkbox.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
    -----------------------------------------------------------------------------------------------------------------------------------------
     59 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     60 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     67 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     68 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    -----------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldType/Integer.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------------------------
     81 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    -----------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /custom_field/src/Plugin/CustomFieldTypeBase.php
    ------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 12 WARNINGS AFFECTING 12 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------
     133 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     139 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     154 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     155 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     162 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     163 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     170 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     172 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     173 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     189 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     191 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     192 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ------------------------------------------------------------------------------------------------------------------------------------------
    
  • 🇮🇳India vishal.kadam Mumbai

    Remove LICENSE.txt file. It will be added automatically by the packaging script.

  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States apmsooner

    @ vinaymahale & vishal.kadam - pushed all suggested changes.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    The LICENSE.txt file is added to the archives, not to the repository.

    Drupal Git Contributor Agreement & Repository Usage Policy → does not forbid to add a license file in a project repository; it just says that projects hosted on drupal.org are licensed under the same license used by Drupal core. As long as the license is correct, the file can stay.

  • 🇺🇸United States apmsooner

    Okay i've reverted that commit.

  • 🇺🇸United States apmsooner
  • 🇺🇸United States apmsooner
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇺🇸United States apmsooner

    Changing title to reflect the desired 2.x version for review. I can't put development on hold for this coveted role. I have gitlab pipelines running with passing tests for phpcs and have some unit testing in place to verify functionality. The module page has several screenshots to depict merit for using it and have provided documentation over and above the typical for unique features.

    https://www.drupal.org/project/custom_field/releases/2.0.x-dev →

  • 🇺🇸United States apmsooner

    I am changing priority as per Issue priorities → .

  • 🇺🇸United States apmsooner
  • Status changed to Needs work about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    • What follows is a quick review of the project; it doesn't mean to be complete
    • For each point, the review usually shows some lines that should be fixed (except in the case the point is about the full content of a file); it doesn't show all the lines that need to be changed for the same reason
    • 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/Feeds/Target/CustomField.php

          catch (TargetValidationException $e) {
            // Validation failed.
            $this->messenger()->addError($e->getMessage());
    

    The first parameter of addError() must be a translatable string.

    The annotation used for the field plugins is similar to the following one.

    /**
     * Plugin implementation of the 'Map (Key Value)' custom field type.
     *
     * @CustomFieldType(
     *   id = "map_key_value",
     *   label = @Translation("Map (Key Value)"),
     *   description = @Translation(""),
     *   category = @Translation("General"),
     *   data_types = {
     *     "map",
     *   },
     * )
     */
    

    Either the description is added, or the description line is removed. As a side note, an empty string does not need to be translated, since an empty string is still an empty string in any language.

  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States apmsooner

    Thanks @apaderno,

    1. I've removed description from all widget plugin annotations.
    2. I've made the feeds target exception message translatable.
  • Status changed to RTBC about 1 year ago
  • 🇮🇳India vinaymahale

    No issues found
    Moving to RTBC

  • Status changed to Needs work about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    $message = $this->t($e->getMessage());
    $this->messenger()->addError($message);
    

    Passing a dynamic string is considered a security issue. The first parameter passed to $this->t() must be a literal string.

    /src/Plugin/CustomField/FieldFormatter/DateTimeCustomFormatter.php

        $elements['date_format'] = [
          '#type' => 'textfield',
          '#title' => $this->t('Date/time format'),
          '#description' => $this->t('See <a href="https://www.php.net/manual/datetime.format.php#refsect1-datetime.format-parameters" target="_blank">the documentation for PHP date formats</a>.'),
          '#default_value' => $settings['date_format'],
        ];
    

    Placeholders are used for URLs. This also avoids that translators gets a part they should not touch in the string to translate.

    src/Plugin/CustomField/FieldFormatter/DateTimeDefaultFormatter.php

        $options = [];
        foreach ($format_types as $type => $type_info) {
          $format = $this->dateFormatter->format($time->getTimestamp(), $type);
          $options[$type] = $type_info->label() . ' (' . $format . ')';
        }
    
        $elements['format_type'] = [
          '#type' => 'select',
          '#title' => $this->t('Date format'),
          '#description' => $this->t("Choose a format for displaying the date. Be sure to set a format appropriate for the field, i.e. omitting time for a field that only has a date."),
          '#options' => $options,
          '#default_value' => $settings['format_type'],
        ];
    

    Option strings shown in the user interface must be translatable. It is fine for the translatable string to contain at least two placeholders, as translators are at least able to decide the order of the placeholders, which could change basing on the language.

    /src/Plugin/CustomField/FieldFormatter/MailToFormatter.php

        $build = [
          '#type' => 'link',
          '#title' => $settings['value'],
          '#url' => Url::fromUri('mailto:' . $settings['value']),
        ];
        $output = \Drupal::service('renderer')->render($build);
    
        return $output;
    

    If dependencies are required, the class must implement ContainerFactoryPluginInterface.

    /src/Plugin/CustomField/FieldType/EmailType.php

        $constraints['Length'] = [
          'max' => self::EMAIL_MAX_LENGTH,
          'maxMessage' => $this->t('%name: the email address can not be longer than @max characters.', [
            '%name' => $settings['name'],
            '%max' => self::EMAIL_MAX_LENGTH,
          ]),
    

    The placeholder used in the string is not the placeholder passed to $this->t().

    src/Plugin/CustomField/FieldWidget/FloatWidget.php

      /**
       * {@inheritdoc}
       */
      public function massageFormValue(mixed $value): mixed {
        if (!is_numeric($value)) {
          return NULL;
        }
    
        return $value;
      }
    

    I could have missed it, but I do not see any massageFormValue() method in the parent classes or the interfaces they implement.

    src/Plugin/CustomFieldTypeManager.php

        foreach ($data_types as $key => $data_type) {
          $options[$key] = $this->t('@label', ['@label' => $data_type['label']]);
        }
    

    That code does not return the translation of $data_type['label']. That code is equivalent to $options[$key] = $data_type['label'];. Either $data_type['label'] is already translated and the call to $this->t() is not necessary, or the translation of $data_type['label'] must be obtained in another way.

    src/CustomFieldUpdateManager.php

        if (!$field_storage_definition) {
          $message = $this->t('There is no field storage definition for field @field_name and entity type @type.', [
            '@field_name' => $field_name,
            '@type' => $entity_type_id,
          ]);
          throw new \Exception($message);
        }
    

    Exception messages are not translatable strings.

    'init_message' => $this->t('Starting data restoration for @count tables...', ['@count' => count($tables)]),

    For that message formatPlural() must be used.

  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States apmsooner

    @apaderno,

    I've addressed all issues you've noted. FYI, one of the issues you noted was result of copy from Core's datetime formatter: https://git.drupalcode.org/project/drupal/-/blob/11.x/core/modules/datet.... I've fixed my implementation but similar issue you noted still exists in Core for the following:

    $elements['date_format'] = [
          '#type' => 'textfield',
          '#title' => $this->t('Date/time format'),
          '#description' => $this->t('See <a href="https://www.php.net/manual/datetime.format.php#refsect1-datetime.format-parameters" target="_blank">the documentation for PHP date formats</a>.'),
          '#default_value' => $settings['date_format'],
        ];
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Assigned to apaderno
  • Status changed to RTBC about 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
        $elements['date_format'] = [
          '#type' => 'textfield',
          '#title' => $this->t('Date/time format'),
          '#description' => $this->t('See <a href="@url" target="_blank">the documentation for PHP date formats</a>.', [
            '@url' => 'https://www.php.net/manual/datetime.format.php#refsect1-datetime.format-parameters',
          ]),
          '#default_value' => $settings['date_format'],
        ];
    

    The correct placeholder for URLs is :url as described in FormattableMarkup::placeholderFormat(), which must be wrapped in quote characters.

  • 🇮🇹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.

  • 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