A paragraph entity references a media image field, and it needs to change its display options in code.

How can I achieve this?


One option is to alter the build array using entity_view. You could then add conditional code there, to change image display settings.

 * Implements hook_entity_view().
function mymodule_entity_view(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display, $view_mode) {
  if ($entity->getEntityType()->id() == 'paragraph' && $entity->bundle() == 'my_paragraph_type') {
    if (!empty($build['field_image'][0])) {
      // $build['field_image'] = 
       // make changes to your image field here

Your Answer

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

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