- π¨π΄Colombia camilo.escobar
Patch applied correctly in Drupal 10.2.2. Thank you!
When creating a custom bundle computed field, "Content language" configuration page (/admin/config/regional/content-language) throws an exception on save: Error: Call to a member function isTranslatable() on null in Drupal\Core\Field\FieldConfigBase->isTranslatable()
The website encountered an unexpected error. Please try again later.
Error: Call to a member function isTranslatable() on null in Drupal\Core\Field\FieldConfigBase->isTranslatable() (line 336 of core/lib/Drupal/Core/Field/FieldConfigBase.php).
Drupal\Core\Field\FieldConfigBase->isTranslatable() (Line: 369)
content_translation_form_language_content_settings_submit(Array, Object)
call_user_func_array('content_translation_form_language_content_settings_submit', Array) (Line: 113)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('language_content_settings_form', Array, Object) (Line: 321)
...
1. Declare a computed bundle field in a custom module:
/web/modules/custom/my_module/my_module.module
...
function my_module_entity_bundle_field_info(EntityTypeInterface $entity_type, string $bundle, array $base_field_definitions): array {
$fields = [];
$fields['my_computed_field'] = BaseFieldDefinition::create('string')
->setName('my_computed_field')
->setLabel(t('My computed field'))
->setComputed(TRUE)
->setClass('\Drupal\my_module\MyComputedFieldFieldItemList')
->setTranslatable(TRUE)
return $fields;
/web/modules/custom/my_module/src/MyComputedFieldFieldItemList.php
<?php
namespace Drupal\my_module;
use Drupal\Core\Field\FieldItemList;
use Drupal\Core\TypedData\ComputedItemListTrait;
class MyComputedFieldFieldItemList extends FieldItemList {
use ComputedItemListTrait;
/**
* {@inheritdoc}
*/
protected function computeValue() {
$computedValue = "Foo";
$this->list[0] = $this->createItem(0, $computedValue);
}
}
2. Go to content language config page (/admin/config/regional/content-language) and save the form
Don't assume that a field has always a storage definition when checking its translatability.
Active
11.0 π₯
Last updated
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
Patch applied correctly in Drupal 10.2.2. Thank you!