You are here

class MessageUIFieldDisplayManagerService in Message UI 8

Class MessageUIFieldDisplayManagerService.

@package Drupal\message_ui

Hierarchy

Expanded class hierarchy of MessageUIFieldDisplayManagerService

1 string reference to 'MessageUIFieldDisplayManagerService'
message_ui.services.yml in ./message_ui.services.yml
message_ui.services.yml
1 service uses MessageUIFieldDisplayManagerService
message_ui.field_display_manager in ./message_ui.services.yml
Drupal\message_ui\MessageUIFieldDisplayManagerService

File

src/MessageUIFieldDisplayManagerService.php, line 12

Namespace

Drupal\message_ui
View source
class MessageUIFieldDisplayManagerService implements MessageUIFieldDisplayManagerServiceInterface {

  /**
   * The entity storage manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager service.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritdoc}
   */
  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();
      }
    }
  }

}

Members