MessageUIFieldDisplayManagerService.php in Message UI 8
File
src/MessageUIFieldDisplayManagerService.php
View source
<?php
namespace Drupal\message_ui;
use Drupal\Core\Entity\EntityTypeManagerInterface;
class MessageUIFieldDisplayManagerService implements MessageUIFieldDisplayManagerServiceInterface {
protected $entityTypeManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager) {
$this->entityTypeManager = $entity_type_manager;
}
public function setFieldsDisplay($template) {
$this->entityTypeManager
->getStorage('entity_form_display')
->resetCache();
$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();
}
}
}
}