- 🇫🇷France hassebasse
I manged to upgrade to 9, but now when going to 10 the problem is back. Fortunatly it is just a test site, but it is annoying, really. The core.extension file is gone in 9 and everything is in the DB, and it iis deeply hidden in a some BLOB file as it seems, so it is to start editing BLOB files! Cool.
For you jdcllns, can't you set up a new site with all modules buy copying the exisiting composer.json and then you import everyting from the old site. It will be quite a jog but it should be doable, I think. Maybe it is possible by using Feeds?
- 🇫🇷France hassebasse
I solved it by using the advice from #21, making a custom module. I did like this, and it should work for you as well.
Create a new directory in your Drupal site's modules directory. The directory name should match your module name, so in this case it should be named computed_field_php_formatter.
Create a new file inside your module directory named computed_field_php_formatter.info.yml. This file contains metadata about your module. Here's an example content for this file:
name: Computed Field PHP Formatter type: module description: Adds a new formatter for computed fields that allows you to use PHP code to format the field value. package: Custom core_version_requirement: ^8.0 || ^9.0 || ^10.0
Create another file in your module directory named computed_field_php_formatter.module. This is where you'll write the PHP code for your module. Here's an example content for this file that defines a new formatter:
<?php use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FormatterBase; /** * Plugin implementation of the 'computed_field_php' formatter. * * @FieldFormatter( * id = "computed_field_php", * label = @Translation("Computed Field (PHP)"), * field_types = { * "computed" * } * ) */ class ComputedFieldPhpFormatter extends FormatterBase { /** * {@inheritdoc} */ public function viewElements(FieldItemListInterface $items, $langcode) { $elements = []; foreach ($items as $delta => $item) { // Get the computed value and format it using the PHP code provided by the field configuration. $value = $item->computed_value; $format_code = $item->getSetting('format_code'); $formatted_value = eval($format_code); // Add the formatted value to the output array. $elements[$delta] = [ '#markup' => $formatted_value, ]; } return $elements; } }
This code defines a new formatter for computed fields that allows you to use PHP code to format the field value.
Enable your new module in the Drupal admin interface by going to the Extend page (/admin/modules) and checking the box next to your module name. You should now be able to use your new formatter on computed fields.
- 🇮🇩Indonesia drupalnesia
Just experience this issue, thanks #21 and #26, here are the 2 files you need to upload under /modules/contrib/computer_field/.
- 🇬🇧United Kingdom joachim
The PHP module was removed for security reasons. It's really not a good idea to restore it. If you're adding custom code anyway, then use version 4 and add the PHP code you want into a plugin class.
- 🇹🇭Thailand Nick Hope
This happened to me when I ran database updates while upgrading 8.x-2.x-dev to 3.0.0-alpha3 (while upgrading D9 to D10).
#25/#26 worked for me. Thank you. I made a new folder 'computed_field_php_formatter' in my modules/custom folder, and put the 2 files from #26 in it. Then I could run
drush updb
without errors.Part of the problem for me is that it's a complex development site that I'm returning to and I can't remember if/where I've used Computed Field. Once I've found that code, if there is any, I'll try and move it to version 4.