hook_field_widget_WIDGET_TYPE_form_alter needs to be updated

Created on 26 July 2023, over 1 year ago
Updated 18 August 2023, over 1 year ago

Problem/Motivation

hook_field_widget_WIDGET_TYPE_form_alter is deprecated in drupal 9.2.x and removed in drupal 10

/**
 * Implements hook_field_widget_WIDGET_TYPE_form_alter().
 */
function tablefield_required_field_widget_tablefield_form_alter(&$element, &$form_state, $context) {
  $config = $context['items']->getFieldDefinition()->getThirdPartySettings('tablefield_required');
  if (!empty($config)) {
    $element['#tablefield_required'] = $config;
  }
}

See this - https://www.drupal.org/node/3180429

Steps to reproduce

The hook does not get triggered with drupal 10

Proposed resolution

Update the hook to be

hook_field_widget_single_element_WIDGET_TYPE_form_alter

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Needs review

Version

2.0

Component

Submodule TableField required

Created by

🇦🇺Australia Nadim Hossain

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

Comments & Activities

  • Issue created by @Nadim Hossain
  • 🇦🇺Australia Nadim Hossain

    This is the patch.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    2 pass
  • 🇺🇸United States Kristen Pol Santa Cruz, CA, USA

    We were discussing this on a call and I saw that the info file will need to be changed to 9.2 and later because that's when the new code was introduced. I didn't test anything though as someone else on the team is going to do that.

  • 🇦🇺Australia Nadim Hossain

    Thanks @Kristen. I have updated the patch according to the comment you made and it is ready for testing now.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    2 pass
  • 🇦🇺Australia danielgry

    Testing was a pass.

    Notes:
    - Tested latest patch on 10.1.x using DrupalPod.
    - had to "drush uli" to login as admin since admin credentials dont work.

    Steps:
    1. Launched environment with DrupalPod
    2. Ensured TableField module and TableField required was enabled in Extend
    4. Edited basic page in Structure
    5. Clicked Manage Fields and added new field with label
    6. Configured the required settings for TableField
    7. Created Basic Page and confirmed that TableField is a required field in backend (see Screenshot 1)
    8. Visually verified that page was successfully created and displayed the table (see Screenshot 2)

  • Status changed to Needs review over 1 year ago
Production build 0.71.5 2024