andy-blum / drupal-smart-snippets

This extension adds rich language support for Drupal Hooks, Services, and Render Elements to VS Code.
https://marketplace.visualstudio.com/items?itemName=andrewdavidblum.drupal-smart-snippets
MIT License
21 stars 4 forks source link

Snippets use legacy `t()` calls as default #24

Closed tyler36 closed 1 year ago

tyler36 commented 1 year ago

I recently discovered this great extension has Smart Element Replacement. (I've only been used the smart hook replacement).

One thing thing I noticed is that it use t() for the translatable values. I try to follow Drupal best practises and my IDE gives me a warnings about these.

t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
(DrupalPractice.Objects.GlobalFunction.GlobalFunction)phpcs

Would it be possible to update the extension to use "$this->t('')" as the default?

Test

  1. Generate a form button by typing: @FormElement ('Button')
    [
      '#type' => 'button',
      '#title' => t(''),
      '#title_display' => 'before',
      '#description' => t(''),
      '#required' => TRUE,
      '#limit_validation_errors' => '',
      '#value' => '',
    ],