You are here

public function FormBuilder::renderPlaceholderFormAction in Secure Pages 8

Renders a form action URL. It's a #lazy_builder callback.

Return value

array A renderable array representing the form action.

Overrides FormBuilder::renderPlaceholderFormAction

File

src/FormBuilder.php, line 51
Contains \Drupal\securepages\FormBuilder.

Class

FormBuilder
FormBuilder decorator for the core formbuilder.

Namespace

Drupal\securepages

Code

public function renderPlaceholderFormAction($form_id = '') {

  // This duplicates the logic of the parent method. We need to duplicate it
  // because we need to pass an additional argument to ::buildFormAction().
  $form_action = [
    '#type' => 'markup',
    '#markup' => $this
      ->buildFormAction($form_id),
    '#cache' => [
      'contexts' => [
        'url.path',
        'url.query_args',
      ],
    ],
  ];

  // Due to dependency on Request::isSecure().
  $form_action['#cache']['contexts'][] = 'url.site';

  // Due to dependency on \Drupal\securepages\Securepages::matchCurrentUser().
  $form_action['#cache']['contexts'][] = 'user.roles';

  // The generated form action depends on the Secure Pages configuration.
  $cacheability = new CacheableMetadata();
  $cacheability
    ->addCacheableDependency(\Drupal::config('securepages.settings'));
  $cacheability
    ->applyTo($form_action);
  return $form_action;
}