What does 2.0 to 3.0 migration involve?

Created on 26 February 2025, about 1 month ago

I have Drupal 8 sites that need to be upgraded to D9/D10. I've updated most modules to D9 compatible versions, but Computed Field seems like it may pose a problem since PHP snippets are no longer stored in the database (what I'm currently doing). I read the initial thread #3143854: Stop allowing PHP from being entered on the Web UI β†’ that laid out this decision and it looks like this update process has been considered, but will I lose my code snippets if I update? What's the process for updating from 8.x-2.0 to 3.0.0 in such a situation?

Do I just update to v3 and the files are magically created out of my existing PHP code snippets?
Do I need to install a sub module and then take some action?
Do I need to install Module Builder tool before updating to v3?

I've found no documentation or guides on how to move from 2 to 3 and I'd love some clarity on this journey to a more secure and modern Drupal experience. Thanks in advance!

πŸ’¬ Support request
Status

Active

Version

3.0

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States nodecode

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

Comments & Activities

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

    For each PHP snippet, you need to create a Computed Field plugin. You can use Module Builder to generate the scaffold for the plugin classes, and then you'll need to copy the PHP manually and tweak it a little for the incoming variables.

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

    That makes sense. In such case, do I...

    A) Install Module Builder and implement the above steps while still in Computed Field 2, and test that my code in file format works before upgrading (I assume cleanly) to Computed Field 3?
    or
    B) Upgrade from Computed Field 2 to 3 first, and then install Module Builder and take the steps above (i.e. would my database-stored PHP code still be available upon upgrade)?

    Assuming A is what you mean, what do I need to put in the required Code (PHP) value field? Just a php comment or something else?

    Thanks

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

    To document the process, I'm attempting Joachim's instructions in Computed Field 2 (option A above) and I've installed Module Builder 8.x-3.34.

    @joachim I found your YouTube video on Module Builder workflow. Thanks for that, though as a relatively inexperienced module developer (I've only made a few D7 modules) it doesn't get me close to actually testing module code with Computed Field. I see that a hook is provided in each Computed Field's help text, but I'm not sure how that translates for use in a module. Even a single example of the "Computed Field using code stored in database" ---> "Computed Field using custom module code" pipeline might be enough to get me going.

    Is there such an sample of before and after code, or perhaps a guide for translating Computed Field php code into module format? For example, I'd want to know if there are required hooks for Computed Field that must be included with every module translated to the new format.

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

    It seems I got lucky on my first try. Here are the steps I took.

    1. Open Module Builder
    2. [Analyse Code]
    3. [Add Module] (Readable name = Anything; Module dependencies = computed_field)
    4. [Save and go to next page] (Hooks)
    5. Add any hook you like (doesn't matter because you'll overwrite this code later). I didn't find a better way to generate the necessary .module file
    6. [Save and generate code]
    7. In the Generate Code tab > [Write all files]
    8. Now find the module's folder on your server
    9. Edit the .module file
    10. Replace all code with the "hook implementation function signature" generated in the Computed Field's help text area. And inside that function, copy/paste your code from the "Code (PHP)..." text area of your Computed Field. Your module code should look like this:
      <?php
      function computed_field_field_your_field_name_compute($entity_type_manager, $entity, $fields, $delta) {
        // Paste code from the Computed Field here
      }
      
    11. Save changes to the .module file
    12. Optionally comment out the code in the Computed Field to ensure the module is overriding the Computed Field
    13. Enable the module
    14. Test that your computed field works

    I realize certain situations may require the original PHP code to be edited, this was not the case for me.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Oh I've just realised you're talking about migrating to version 3. I got the version numbers mixed up -- I was thinking of version 4.

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

    Correct. I'd go right to version 4 but I can't do that while still in D8, and since modules have to be upgraded before Core can be upgraded, it's a chicken and egg situation.

Production build 0.71.5 2024