You are here

public static function ParserOperationForm::createOperationUrl in Markdown 8.2

Creates a URL with the appropriate CSRF token for a parser operation.

Parameters

\Drupal\markdown\Plugin\Markdown\ParserInterface $parser: The parser to perform an operation on.

string $operation: The operation to perform.

Return value

\Drupal\Core\Url A parser operation Url object.

1 call to ParserOperationForm::createOperationUrl()
ParserOperationForm::submitForm in src/Form/ParserOperationForm.php
Form submission handler.

File

src/Form/ParserOperationForm.php, line 65

Class

ParserOperationForm
Provides a confirmation form to disable a parser.

Namespace

Drupal\markdown\Form

Code

public static function createOperationUrl(ParserInterface $parser, $operation) {

  // Because this is redirecting to a CSRF access controlled route, this
  // needs the correct token added to the route's query option. Core
  // usually does this automatically, but its based on this current form
  // not the redirected route. So it must be manually set here.
  $url = Url::fromRoute('markdown.parser.operation', [
    'parser' => $parser,
    'operation' => $operation,
  ]);
  $token = \Drupal::csrfToken()
    ->get($url
    ->getInternalPath());
  $options = $url
    ->getOptions();
  $options['query']['token'] = $token;
  $url
    ->setOptions($options);
  return $url;
}