You are here

public function OpignoMessageThread::getThreadActions in Opigno messaging 3.x

Prepare the render array to display the thread actions.

Parameters

\Drupal\private_message\Entity\PrivateMessageThreadInterface $thread: The PM thread to get actions for.

Return value

array Render array to display the thread actions.

File

src/Services/OpignoMessageThread.php, line 421

Class

OpignoMessageThread
The private messages manager service.

Namespace

Drupal\opigno_messaging\Services

Code

public function getThreadActions(PrivateMessageThreadInterface $thread) : array {
  $actions = [];
  $tid = (int) $thread
    ->id();
  $links = [
    'opigno_messaging.confirm_delete_form' => $this
      ->t('Delete'),
    'opigno_messaging.get_edit_thread_form' => $this
      ->t('Edit'),
  ];
  $params = [
    'private_message_thread' => $tid,
  ];
  $options = [
    'attributes' => [
      'class' => [
        'dropdown-item-text',
        'use-ajax',
      ],
    ],
  ];

  // Generate the list of actions available for the given user.
  foreach ($links as $route => $title) {
    $url = Url::fromRoute($route, $params, $options);
    if ($url
      ->access()) {
      $actions[] = Link::fromTextAndUrl($title, $url);
    }
  }
  return [
    '#theme' => 'opigno_pm_thread_actions',
    '#actions' => $actions,
    '#cache' => [
      'contexts' => Cache::mergeContexts($thread
        ->getCacheContexts(), [
        'user',
      ]),
      'tags' => $thread
        ->getCacheTags(),
    ],
  ];
}