Feedback about the process and documentation

Created on 18 April 2025, about 2 months ago

Problem/Motivation

Thanks for creating this module, it could be a real game changer.

I tried to create a Field Updater, but get errors when I click Save ...

Also, it wasn't clear to me how to finally do the update, perhaps it can be added in the Quick start?

Steps to reproduce

  1. Install Drupal 11 and the module
  2. Add a new field in Article, called "Body2"
  3. Create a new field updater with target "Body2", source "Body" and click Save
  4. Get a lot of errors, and a non-functional field updater

It looks like only the "Target" value is set, and I need to set the "Field source" again, and then save.

Error message
Warning: Attempt to read property "entity_type" on null in Drupal\field_updater_service\Form\FieldUpdaterForm->save() (line 300 of modules/contrib/field_updater_service/src/Form/FieldUpdaterForm.php).
Error message
Warning: Attempt to read property "bundle" on null in Drupal\field_updater_service\Form\FieldUpdaterForm->save() (line 301 of modules/contrib/field_updater_service/src/Form/FieldUpdaterForm.php).
Error message
Warning: Attempt to read property "field_target" on null in Drupal\field_updater_service\Form\FieldUpdaterForm->save() (line 302 of modules/contrib/field_updater_service/src/Form/FieldUpdaterForm.php).
Error message
Warning: Attempt to read property "field_source" on null in Drupal\field_updater_service\Form\FieldUpdaterForm->save() (line 303 of modules/contrib/field_updater_service/src/Form/FieldUpdaterForm.php).
Error message
Warning: Attempt to read property "target_type" on null in Drupal\field_updater_service\Form\FieldUpdaterForm->save() (line 304 of modules/contrib/field_updater_service/src/Form/FieldUpdaterForm.php).
Error message
Warning: Attempt to read property "target_bundles" on null in Drupal\field_updater_service\Form\FieldUpdaterForm->save() (line 305 of modules/contrib/field_updater_service/src/Form/FieldUpdaterForm.php).
Error message
Warning: Array to string conversion in Drupal\field_updater_service\Form\FieldUpdaterForm->save() (line 310 of modules/contrib/field_updater_service/src/Form/FieldUpdaterForm.php).

Proposed resolution

1. Save values in the first go
Update the processes of the code, so the values are saved in the first go.

2. New Order: "Source" then "Target"?
Another thing: Usually the order of parameters with a source and target (for example rsync) is in that order, perhaps it could also be here, where they are reversed, which seems not intuitive to me.

Proposal: Reverse the order of "Source" and "Target" in the field updater creation form, to this order:

  • Label
  • Entity type
  • Bundle
  • Source field
  • Target field

The same could apply to the list of field updaters on the Mapping page, they could be updated to this order:

  • Source
  • Target
  • Value source

3. Clarify the process

After creating a field updater, I wasn't sure how to actually do the transfer ...

Perhaps a fifth and final step could be added on the project page?

Quick start

  1. Add a new field updater at /admin/config/field-updater
  2. Select: Entity type, Bundle, and Target field
  3. Select: Source field (optional) if you want to copy from an entity_reference_revisions field type (ie; paragraphs).
  4. Save the form and add mappings at /admin/config/field-updater/{id}/mappings
  5. Import the content (replace "ID") with drush field-updater:update ID <<< Add this?

4. Import via GUI?

Eventually, perhaps an import could be triggered as well via the GUI, by clicking a button, or maybe by selecting a new option "Import" under the individual Field updaters Operations drop-down?

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡°Denmark ressa Copenhagen

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

Comments & Activities

  • Issue created by @ressa
  • πŸ‡©πŸ‡°Denmark ressa Copenhagen
  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    Thanks @ressa,

    I'll check into the errors you're having on Drupal 11. I had only tested this on 10.4.x and didn't experience any issues like you're describing but nonetheless, i'll see if i can reproduce and patch it up quickly. Should be an easy thing to reconcile.

    I added a 5th step to quick start linking to example update hook.

    For more clarity: The module itself doesn't import anything. It uses the configuration settings including the defined mappings to copy data from 1 or more fields of same schema type to target field. The "Source field" is optional as its not needed normally unless you need to copy from a entity_reference_revisions field (ie; paragraphs) which in itself is composed of its own entity type/bundle that has its own fields. In your example, you can certainly set the other body field as a "Source field" or you can leave that field empty and that field along with any other (non entity_reference_revisions fields) would be available in the mappings. So you basically can pull data from multiple field properties to fill the target field. I will sort out this bug first and then add a video soon that covers all the steps including the update hook declaration which should hopefully simplify the explanation.

    Again, no import is happening, when the update hook runs, it's querying for all entities of the defined entity_type/bundle and does a batch update to the target field from source(s).

  • πŸ‡©πŸ‡°Denmark ressa Copenhagen

    Thanks for a fast reply, and for making the module @apmsooner. I am sorry that I collected so many, and disparate tasks in a single issue, and I have created an issue for each, to deal with them individually.

    I tried in Drupal 10 as well, and also get the errors there ...

    Thanks for explaining some more details about how the module works, like the schema thing. I did try to map and copy content from a "Body" field to a "Plain text", and got problems -- there were no fields under "Field source" in the "Mapping" page (only "None", "NULL" and "Custom value") ...

    Different types of "Source" ...

    Fundamentally, there is something about the naming of fields which seemed not intuitive to me ... A video would be all right, but I think it would be a better idea to make the elements in the GUI intuitively understandable.

    New users, like myself, who jump into using the module wonder --

    How can Source be optional? Or is the "Source" mentioned under "Add field updater" not the same "Source" as on the "Mappings" page?

    And now, I went back and actually took the time to read the Quick start, and the penny dropped, and I experimented a bit more ...

    If at all possible, I think the "Source field" should only be displayed on the "Add field updater" if it makes sense -- i.e. if the "Target field" is a Paragraph. For a "Plain text" field, it would never be relevant, I would think?

    Thinking more about this, how about flipping the order from selecting Target first, to selecting Source first? Then, the allowed Target field schema types can also be limited to only be the same schema types as the Source.

    In other words: If the user selects a "Plain text" field as Source, then only fields of type "Plain text" should be offered in the resulting Target drop-down. In the image below, the have already selected "Text1" and "Plain text" schema fields such as "Text2" were made available.

    Similarly, if the user select a Paragraph field as Source, the drop-down should only offer Paragraph type fields. Also, where it's relevant a "sub drop-down" with extra value options should be presented as well, in this case, values such as target_id.

    Would that be possible?

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    These aren't bad ideas but there's reasoning for the current setup.

    1. The source field is optional. If no source field is selected, all fields on the entity are available for mapping.
    2. The target field is required therefore logically put first.
    3. I don't really want to combine the mappings into the same form as it would require alot of additional ajax and therefore make it way more cumbersome and error prone.

    Maybe there's some opportunity for better labels and help text still. I would like to make it more intuitive, just not sure how to communicate best that the source field is really for targeting specific fields from a referenced entity (ie; paragraphs, blocks, etc...). Maybe we change the label to something like "Source from referenced entity" and limit the dropdown to those field types? The whole reasoning for the source field is basically that we have to associate the mappings to the entity with the fields. If the desire is to map from fields on a paragraphs entity, only the fields specific to the paragraph entity should be in the mappings.

  • πŸ‡ΊπŸ‡ΈUnited States apmsooner

    Let me dig back into this and try to figure out some better solutions. It's been a while as I've been heads down on updates for the custom_field module but I have time now to get back into this one and make some improvements. I appreciate the suggestions and ideas.

Production build 0.71.5 2024