Support additional field types

Created on 9 April 2023, over 1 year ago
Updated 27 August 2024, 3 months ago

This request comes up frequently - everyone wants explicit support for their own favorite field type added to the Barcodes module. But this is not a scalable or maintainable thing to do, so we will NOT be adding additional non-Core fields on an ad hoc basis.

I'm open to a general solution that allows site builders to customize the supported fields through the UI, without hacking or patching code. Merge requests with a proposed solution are welcome.

Currently, it is easy to customize your site to add Barcode support for your own field type. The standard way to customize Drupal for your site is to implement a hook. This is how you would currently add support for the 'serial' field, for example:

/**
 * Implements hook_field_formatter_info_alter().
 */
function yourmodule_field_formatter_info_alter(array &$info) {
    // Allow the barcode field formatter to be used on a new field type.
    $info['barcode']['field_types'][] = 'serial';
}

And I feel that for reference I need to add that "yourmodule" should be replaced with the name of your module that you are using to customize your site. Read the documentation on how to implement a hook for details.

Original issue summary:

Problem/Motivation

I needed barcodes for stock item stickers with automatically generated unique numbers, so I settled on this module plus the serial module β†’ .

Proposed resolution

Include 'serial' in the plugin's annotation.

✨ Feature request
Status

Active

Version

2.1

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom griz

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

Comments & Activities

  • Issue created by @griz
  • πŸ‡¬πŸ‡§United Kingdom griz

    Works for me. RTBC?

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    Well, serial isn't one of the built-in Drupal core field types. It is not a scalable solution to keep adding names of contributed field types. I would prefer a more general solution, using FormatterBase::isApplicable() and possibly removing the field_types annotation if it is no longer relevant.

  • Status changed to Needs work over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
  • πŸ‡ΊπŸ‡ΈUnited States SocialNicheGuru

    Just uploading a rerolled version for Barcodes 2.0.x.

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

    Like I said, this will not be added to the module. This issue is still active because I'm open to a solution that allows site builders to customize this without hacking or patching code.

    The standard way to customize Drupal for your site is to implement a hook. This would work for your needs, for example:

    /**
     * Implements hook_field_formatter_info_alter().
     */
    function yourmodule_field_formatter_info_alter(array &$info) {
        // Allow the barcode field formatter to be used on a new field type.
        $info['barcode']['field_types'][] = 'serial';
    }

    And I feel that for reference I need to add that "yourmodule" should be replaced with the name of your module that you are using to customize your site. Read the documentation on how to implement a hook for details.

  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
  • Status changed to Active 3 months ago
  • πŸ‡ΊπŸ‡ΈUnited States tr Cascadia
Production build 0.71.5 2024