Score:0

Are extra fields added with hook_entity_extra_field_info(). not available on product variation pages?

cn flag

Is it generally impossible to render an extra field on product variation pages, because of how the variant fields are injected into product pages?

I added an extra field to the product variations with hook_entity_extra_field_info(). and I see it in the "Manage Display" Tab like it would appear on any other entity. But I can't output it. It is simply not available in the theme. If I do a {{ dump() }} in the product variation template it is not listed at all.

Score:1
cn flag

In general, this hook only adds metadata to the entity view mode. You have to add the output in a different hook if the view mode has this field configured:

/**
 * Implements hook_ENTITY_TYPE_view().
 */
function mymodule_product_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  if ($display->getComponent('my_extra_field')) {
    $build['my_extra_field'] = [
      '#markup' => 'Extra field content.', 
    ];
  }
}

Then it will end up in the content variable of your theme.

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.