On the way to a Drupal 10.2 (and above) compatible version

Created on 17 December 2023, about 1 year ago
Updated 24 January 2024, 11 months ago

Problem/Motivation

In Drupal 10.2 the following error is thrown:

TypeError: array_unshift(): Argument #1 ($array) must be of type array, null given in array_unshift() (line 100 of modules/contrib/datafield/datafield.module).

Steps to reproduce

1. Install fresh Drupal 10.2
2. Install en enable Datafield
3. Attempt to add a new datafield on any content type
4. The error above is thrown

Proposed resolution

The error is related ti this snippet of the datafield.module file:

function datafield_form_field_storage_config_edit_form_alter(&$form, FormStateInterface $form_state, $form_id) {

  if (($field_config = $form_state->get('field_config')) && $field_config->get('field_type') == 'data_field') {
    array_unshift(
      $form['actions']['submit']['#submit'],
      'Drupal\datafield\Plugin\Field\FieldType\DataField::submitStorageConfigEditForm'
    );
  }
}
🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇮🇪Ireland marksmith

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

Comments & Activities

  • Issue created by @marksmith
  • First commit to issue fork.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India viren18febS

    HI @marksmith
    I have added a patch with the fixes,
    Thanks

  • 🇫🇷France lazzyvn paris

    The problem I know before, It is not compatible with drupal 10.2. Field storage in Drupal 10.2 previously changed that when you create a field, it creates a stored field with a value, the data field base on this to hook the field storage.
    #ajax form changed wrapper to wrapper_selector
    #state change to field_storage[subform][settings][storage]
    $form_state->getValue has had major changes
    I don't have much free time to fix it rightnow, wait at least 3 months for 2.x, because my customers are still happy with 10.1. they don't want to update to version 10.2

  • 🇮🇪Ireland marksmith

    Thank you for the quick reaction. I understand the problem and I'm eagerly waiting for the fix! Drupal 10.2 introduced a few attractive user friendly updates (an also caused some technical troubles, as I see), so that it would be a pity to miss it. :) Thanks for your efforts invested in this great module!

  • Status changed to Fixed 12 months ago
  • 🇫🇷France lazzyvn paris

    Check dev version it fixed

  • 🇮🇪Ireland marksmith

    It's great you started working on this module! I checked the alpha version (dev wasn't working for me). The alpha version basically works with Drupal 10.2, with the limitations that you highlight on the module page (it's not possible to alter the schema after the field had been created).

    One thing I observed for now is that I am unable to add more than one value to a multivalue Data field. (One has to edit the content in order to add a further value).

    Another thing is that if a date field is added, and the content is edited, it throws this error: InvalidArgumentException: The date cannot be created from a format. in Drupal\Component\Datetime\DateTimePlus::createFromFormat() (line 253 of core/lib/Drupal/Component/Datetime/DateTimePlus.php).

  • 🇫🇷France lazzyvn paris

    check dev version or alpha2 it fixed almost bug

  • 🇮🇪Ireland marksmith

    Tried with alpha3 (december 31).

    I tried with the following data field setup: 1. text field, 2. date field, 3. datetime field, 4. entity reference field.

    1. Composer automatically downloads and installs beta2 (even if alpha is requested).
    2. Date field is working.
    3. Datetime field value gives this error in Reports: Warning: Undefined array key "object" in Drupal\Core\Datetime\Element\Datetime::validateDatetime() (line 365 of /var/www/html/web/core/lib/Drupal/Core/Datetime/Element/Datetime.php)
    4. Entity reference field (referencing Article from Basic page) is not working on form view, throws an AJAX error in console and this error in reports: InvalidArgumentException: The #default_value property has to be an entity object or an array of entity objects. in Drupal\Core\Entity\Element\EntityAutocomplete::valueCallback() (line 114 of core/lib/Drupal/Core/Entity/Element/EntityAutocomplete.php).

  • 🇫🇷France lazzyvn paris

    Fixed some bug in entity reference and datetime in rc version

  • 🇮🇪Ireland marksmith

    Much better with RC 5!
    A few things I noted.

    1. File - It works with the widget option file upload. However, if I select the form widget Media library I receive this error: Warning: Undefined array key "#title" in datafield_preprocess_field_multiple_value_form() (line 196 of /var/www/html/web/modules/contrib/datafield/datafield.module)
    2. Have you considered adding an option for private files?

    Aside of that:
    3. With Devel generate I receive this error: Warning: Undefined array key "date" in Drupal\datafield\Plugin\Field\FieldType\DataField::generateSampleValue() (line 698 of modules/contrib/datafield/src/Plugin/Field/FieldType/DataField.php). (with reference, etc. as well)

  • 🇫🇷France lazzyvn paris

    I added option uri schemas (private file) but I don't know if it works

  • 🇮🇪Ireland marksmith

    Private file field works, great job!

    Two further errors and suggestions:

    1. After saving content (with an entity reference and a file field), datafield throws this error:
    TypeError: Unsupported operand types: null + array in Drupal\datafield\Plugin\Field\FieldFormatter\DataFieldTable->viewElements() (line 300 of /var/www/html/web/modules/contrib/datafield/src/Plugin/Field/FieldFormatter/DataFieldTable.php).
    This line is problematic: $components[$subfield] += $components['formatter_settings'][$subfield]; does not work. Apparently we need to check whether whether $components[$subfield] is an array before combining it with another array. So this worked:

    if (!isset($components[$subfield])) $components[$subfield] = [];
    $components[$subfield] += $components['formatter_settings'][$subfield];

    This, however, also worked.
    $components[$subfield] = $components['formatter_settings'][$subfield];

    2. There was another error on saving content:
    Warning: Undefined array key "date" in Drupal\datafield\Plugin\Field\FieldFormatter\DataFieldTable->viewElements() (line 297 of modules/contrib/datafield/src/Plugin/Field/FieldFormatter/DataFieldTable.php).

    This correction worked:

    if (isset($components[$subfield]) && isset($components[$subfield]["type"])) {
      $align[$subfield] = in_array($components[$subfield]["type"], ['integer', 'numeric', 'float']) ? 'right' : '';
    }
  • 🇮🇪Ireland marksmith

    Changing issue title in accordance with further discussion.

  • 🇮🇪Ireland marksmith

    Sorry, coming back yet again with the private file issue. The file is correctly saved to the private folder, but it cannot be opened afterwards from the saved content page (Access denied error, even for admin).

  • 🇫🇷France lazzyvn paris

    Oh I knew it. you can't download private files even if you have the right link because it will check the field type and field permissions. data field is not an entity file type, it cannot load file headers without header it means access denied. That's why i don't add option private file in version 1.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024