You are here

public function MessageUIContextualLinks::render in Message UI 8

Renders the field.

Parameters

\Drupal\views\ResultRow $values: The values retrieved from a single row of a view's query result.

Return value

string|\Drupal\Component\Render\MarkupInterface The rendered output. If the output is safe it will be wrapped in an object that implements MarkupInterface. If it is empty or unsafe it will be a string.

Overrides FieldPluginBase::render

File

src/Plugin/views/field/MessageUIContextualLinks.php, line 33

Class

MessageUIContextualLinks
Presenting contextual links to the messages view.

Namespace

Drupal\message_ui\Plugin\views\field

Code

public function render(ResultRow $values) {

  /** @var \Drupal\message_ui\MessageUiViewsContextualLinksManager $contextual */
  $contextual_links = \Drupal::service('plugin.manager.message_ui_views_contextual_links');
  $links = [];

  // Iterate over the plugins.
  foreach ($contextual_links
    ->getDefinitions() as $plugin) {

    /** @var \Drupal\message_ui\MessageUiViewsContextualLinksInterface $contextual_link */
    $contextual_link = $contextual_links
      ->createInstance($plugin['id']);
    $contextual_link
      ->setMessage($values->_entity);
    if (!($link = $contextual_link
      ->getRouterInfo())) {

      // Nothing happens in the plugin. Skip.
      continue;
    }
    $link['attributes'] = [
      'class' => [
        $plugin['id'],
      ],
    ];
    $links[$plugin['id']] = $link + [
      'weight' => $plugin['weight'],
    ];
  }
  usort($links, [
    'Drupal\\Component\\Utility\\SortArray',
    'sortByWeightElement',
  ]);
  $row['operations']['data'] = [
    '#type' => 'operations',
    '#links' => $links,
  ];
  return $row;
}