- Issue created by @Anybody
- Assigned to Anybody
- First commit to issue fork.
- 🇩🇪Germany Grevil
Not as simple as it seems first...
It seems, that we need to hook into the view, instead of using "hook_entity_field_access" as we do not have access to the entity through the field definition or any other parameter provided.
- 🇩🇪Germany Anybody Porta Westfalica
@grevil yes I know. Please wait with the implementation here, we first have to discuss if and how we can solve this best.
For that reason, it's assigned to me. - Issue was unassigned.
- Status changed to Postponed
8 months ago 2:08pm 19 August 2024 - 🇩🇪Germany Anybody Porta Westfalica
Update: For now we won't need it, as I now solved it differently (apart from this module) by hiding the price, if it's empty:
/** * Implements hook_entity_field_access(). */ function drowl_customer_entity_field_access($operation, \Drupal\Core\Field\FieldDefinitionInterface $field_definition, \Drupal\Core\Session\AccountInterface $account, ?\Drupal\Core\Field\FieldItemListInterface $items = NULL) { // Hide the price fields displays: if ($operation === 'view') { if (in_array($field_definition->getName(), ['price', 'list_price', 'unit_price', 'total_price'])) { $priceValue = $items->getValue(); // Hide price if empty: if(isset($priceValue['number']) && empty($priceValue)){ return \Drupal\Core\Access\AccessResult::forbidden(); } } } return \Drupal\Core\Access\AccessResult::neutral(); }
Still this option may make sense for this module in the future.