Score:0

How can I overwrite the value of a field in a bundle class?

cn flag

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?

Score:1
cn flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.