protected function configureViewMode(FormStateInterface $form_state) {
    $view_mode = $this->postViewDefault;
    if ($this->entity->hasField('field_recipient_user') && !$this->entity->get('field_recipient_user')->isEmpty()) {
      $view_mode = $this->postViewProfile;
    }
    elseif ($this->entity->hasField('field_recipient_group') && !$this->entity->get('field_recipient_group')->isEmpty()) {
      $view_mode = $this->postViewGroup;
    }

    $display = EntityFormDisplay::load($view_mode);
    $this->setFormDisplay($display, $form_state);
  }
protected function configureViewMode(FormStateInterface $form_state) {
    $view_mode = $this->postViewDefault;
    if ($this->entity->hasField('field_recipient_user') && !$this->entity->get('field_recipient_user')->isEmpty()) {
      $view_mode = $this->postViewProfile;
    }
    elseif ($this->entity->hasField('field_recipient_group') && !$this->entity->get('field_recipient_group')->isEmpty()) {
      $view_mode = $this->postViewGroup;
    }

    $display = EntityFormDisplay::load($view_mode);
    $this->setFormDisplay($display, $form_state);
  }
protected function configureViewMode ( FormStateInterface $ form_state ) { $ view_mode = $ this -> postViewDefault ; if ( $ this -> entity -> hasField ( 'field_recipient_user' ) && ! $ this -> entity -> get ( 'field_recipient_user' ) -> isEmpty ( ) ) { $ view_mode = $ this -> postViewProfile ; } elseif ( $ this -> entity -> hasField ( 'field_recipient_group' ) && ! $ this -> entity -> get ( 'field_recipient_group' ) -> isEmpty ( ) ) { $ view_mode = $ this -> postViewGroup ; } $ display = EntityFormDisplay :: load ( $ view_mode ) ; $ this -> setFormDisplay ( $ display , $ form_state ) ; }
Configures the view mode when an existing entity is being edited.

Uses the default view mode for community posts, the group view mode for
posts placed in a group and the profile view mode for posts placed on
someone's profile.

@param \Drupal\Core\Form\FormStateInterface $form_state
The form state used to render this form.
Configures the view mode when an existing entity is being edited .