In Drupal 9 I would like to know if it is possible to overwrite the value of a field in a BundleClass. Looking at the Drupal API, I see that it is common to use either hook_entity_view_alter or hook_views_pre_render. The only way I have found is to define a new method:

public function getUpdateFieldName() {
  $value = this->get('field_name')->getValue();
  # Code here ...
  return $code

However, with this example, I have to create a pseudo-field to be able to get the value in a view. Are there any other ways?

1 Answer 1


To query field values Views operates on SQL basis, to display you can configure a Views field plugin and additionally use the Field API field formatter. These are the two classes you should consider to add PHP code, if you can't use the rewrite options Views field plugins provide out-of-the-box.

From there you can refactor the code and put the bundle specific calculations in the bundle class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.