You are here

public function FaqAskController::askAnswerViewSettings in FAQ_Ask 8

This function is called when an expert selects a question to answer.

It changes the status option to "published" then goes to the regular FAQ edit function.

1 string reference to 'FaqAskController::askAnswerViewSettings'
faq_ask.routing.yml in ./faq_ask.routing.yml
faq_ask.routing.yml

File

src/Controller/FaqAskController.php, line 43
Contains \Drupal\faq\Controller\FaqAskController.

Class

FaqAskController
Controller routines for FAQ Ask routes.

Namespace

Drupal\faq_ask\Controller

Code

public function askAnswerViewSettings($nid) {
  $faq_ask_settings = \Drupal::config('faq_ask.settings');
  $user = \Drupal::currentUser();

  // If user is not logged in.
  if ($user
    ->id() == '0') {

    // Log in first.
    $path = URL::fromUserInput('/user', array(
      'query' => drupal_get_destination(),
    ))
      ->toString();
    return new RedirectResponse($path);
  }

  // Validate the request.
  if (!isset($_REQUEST['token']) || !Utility::faqAskValidToken($_REQUEST['token'], "faq_ask/answer/" . $nid)) {
    \Drupal::logger('Faq_Ask')
      ->error("Received an invalid answer request (@query_string) from @user_ip.", array(
      '@query_string' => $_SERVER['QUERY_STRING'],
      '@user_ip' => ip_address(),
    ));
    throw new AccessDeniedHttpException();
  }
  $reassign_opt = $faq_ask_settings
    ->get('expert_own');

  // Check if we need to reassign to the expert.
  switch ($reassign_opt) {
    case 0:
      break;
    case 1:
      if ($node->uid == 0) {
        Utility::faqAskReassign($node);
      }
      break;
    case 2:
      Utility::faqAskReassign($node);
      break;
  }

  // Change the status to published.
  $node = node_load($nid);
  $node->status->value = 1;
  $node
    ->save();

  // Need to invoke node/#/edit.
  return new RedirectResponse(URL::fromUserInput('/node/' . $nid . '/edit')
    ->toString());
}