You are here

public function MessageUIFieldDisplayManagerService::setFieldsDisplay in Message UI 8

Setting the fields to display.

Parameters

string $template: The message template.

Overrides MessageUIFieldDisplayManagerServiceInterface::setFieldsDisplay

File

src/MessageUIFieldDisplayManagerService.php, line 34

Class

MessageUIFieldDisplayManagerService
Class MessageUIFieldDisplayManagerService.

Namespace

Drupal\message_ui

Code

public function setFieldsDisplay($template) {
  $this->entityTypeManager
    ->getStorage('entity_form_display')
    ->resetCache();

  /** @var \Drupal\Core\Entity\Display\EntityDisplayInterface $form_display */
  $form_display = $this->entityTypeManager
    ->getStorage('entity_form_display')
    ->load("message.{$template}.default");
  if (!$form_display) {
    $form_display = \Drupal::entityTypeManager()
      ->getStorage('entity_form_display')
      ->create([
      'targetEntityType' => 'message',
      'bundle' => $template,
      'mode' => 'default',
      'status' => TRUE,
    ]);
    foreach (array_keys($form_display
      ->get('hidden')) as $hidden) {
      $form_display
        ->setComponent($hidden, [
        'field_name' => $hidden,
      ]);
      $form_display
        ->save();
    }
  }
}