I am not able to set an item definition class for a configuration field.

I tried implementing hook_entity_bundle_field_info_alter() , but it doesn't work.

function hook_entity_bundle_field_info_alter(&$fields, \Drupal\Core\Entity\EntityTypeInterface $entity_type, $bundle) {
  if ($entity_type->id() === 'my_entity_type_id') {
    foreach ($fields as $field) {
      if ($field->getType() === 'file') {

It seems Drupal is ignoring it and constructs item using the base class.

My file item class:

use Drupal\file\Plugin\Field\FieldType\FileItem;

class AnswerFileItem extends FileItem {

   * {@inheritDoc}
  public function getUploadLocation($data = []) {
    $data += ['my_entity_type_id' => $this->getEntity()];
    return parent::getUploadLocation($data);


Basically I want to add additional token data to all configuration fields on given entity_type_id.

Entity class is not important, it could be node.

I think problem is in FieldItemList because it uses wrong field item class.

  • Could you provide the original code you actually use. You can debug and find out where the control flow goes in and where not. Especially: is there any field in Entity my_entity_type_d? Is AnswerFileItem visible/imported? Jul 19 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.