You are here

public function Utility::faqAskAnswerlink in FAQ_Ask 8

Helper function to create a link to unanswered nodes.

It generates by using the token verification.

1 call to Utility::faqAskAnswerlink()
Utility::faqAskUnansweredBlockBuild in src/Utility.php
Helper function to get Build block.

File

src/Utility.php, line 392
Contains \Drupal\faq_ask\Utility.

Class

Utility
Contains static helper functions for FAQ module.

Namespace

Drupal\faq_ask

Code

public function faqAskAnswerlink($node, $mode) {
  if (!is_object($node)) {
    $node = node_load($node);
  }
  $nid = $node
    ->id();

  // Create token to enable instant answering of unanswered questions.
  $token = Utility::faq_ask_get_token('faq_ask/answer/' . $nid);
  $item_return = array();

  // Allow for edit mode in link to the unanswered questions if in edit mode.
  if ($mode == 'edit') {
    $item_return['title'] = $node
      ->get('title')->value;
    $item_return['href'] = Url::fromUserInput("/faq_ask/edit/" . $node
      ->id(), array(
      "query" => array(
        'ask' => TRUE,
      ),
    ))
      ->toString();
  }
  elseif ($mode == 'answer') {
    $item_return['title'] = $node
      ->get('title')->value;
    $item_return['href'] = Url::fromUserInput("/faq_ask/answer/" . $node
      ->id(), array(
      "query" => array(
        'token' => $token,
      ),
    ))
      ->toString();
  }
  return $item_return;
}