You are here

function message_ui_entity_load in Message UI 8

Implements hook_entity_load().

File

./message_ui.module, line 352
Contains Drupal\message_ui\message_ui.module.

Code

function message_ui_entity_load(array &$entities, $entity_type_id) {
  static $saved;
  if (!empty($saved)) {
    return;
  }
  if ($entity_type_id != 'view') {
    return;
  }
  foreach ($entities as &$entity) {
    if ($entity
      ->id() != 'message') {
      continue;
    }
    $display = $entity
      ->get('display');
    if (!empty($display['default']['display_options']['fields']['message_ui_contextual_links'])) {
      $saved = TRUE;
      continue;
    }
    $display['default']['display_options']['fields']['message_ui_contextual_links'] = [
      'id' => 'message_ui_contextual_links',
      'table' => 'message',
      'field' => 'message_ui_contextual_links',
      'entity_type' => 'message',
      'label' => 'Operations',
    ];
    $entity
      ->set('display', $display);

    // Mark the entity as saved.
    $saved = TRUE;
    $entity
      ->save();
  }
}