You are here

public function ShareMessage::getContext in Share Message 8

Gets a context for tokenizing.

Parameters

string $view_mode: (optional) The view mode that should be used to render the item.

Return value

array An array containing the following elements:

  • sharemessage: This entity.
  • node: The node target for the current request, if any.

The array is altered by modules implementing hook_sharemessage_token_context().

Overrides ShareMessageInterface::getContext

File

src/Entity/ShareMessage.php, line 253

Class

ShareMessage
Entity class for the Share Message entity.

Namespace

Drupal\sharemessage\Entity

Code

public function getContext($view_mode = 'full') {
  $context = [
    'sharemessage' => $this,
    'view_mode' => $view_mode,
  ];

  // Add a runtime context to the context list.
  $context += $this->runtimeContext;

  // Attempt to use the current node as context if none has been set
  // explicitly as runtime context.
  $node = \Drupal::request()->attributes
    ->get('node');
  if (!isset($context['node']) && $node instanceof NodeInterface) {
    $context['node'] = $node;
  }

  // Let other modules alter the sharing context that will be used for token
  // as base for replacements.
  \Drupal::moduleHandler()
    ->alter('sharemessage_token_context', $this, $context);
  return $context;
}