You are here

public function AnalysisFormHandler::addAnalysisSubmit in Real-time SEO for Drupal 8.2

Adds yoast_seo_preview submit.

Parameters

array $element: The form element to process.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

File

src/Form/AnalysisFormHandler.php, line 109

Class

AnalysisFormHandler
Base class for yoast_seo_preview form handlers.

Namespace

Drupal\yoast_seo\Form

Code

public function addAnalysisSubmit(array &$element, FormStateInterface $form_state) {

  // Tell the form API not to change the build id as this causes issues with
  // other modules like paragraphs due to the form cache. See
  // https://www.drupal.org/project/yoast_seo/issues/2992284#comment-13134728
  // This must be called here because in `analysisSubmitAjax` it would be too
  // late.
  $triggeringElement = $form_state
    ->getTriggeringElement();
  if ($triggeringElement !== NULL && end($triggeringElement['#parents']) === 'yoast_seo_preview_button') {
    $form_state
      ->addRebuildInfo('copy', [
      '#build_id' => TRUE,
      '#action' => TRUE,
    ]);
  }
  $element['yoast_seo_preview_button'] = [
    '#type' => 'button',
    '#value' => t('Seo preview'),
    '#attributes' => [
      'class' => [
        'yoast-seo-preview-submit-button',
      ],
      // Inline styles are bad but we can't reliably use class order here.
      'style' => 'display: none',
    ],
    '#ajax' => [
      'callback' => [
        $this,
        'analysisSubmitAjax',
      ],
    ],
  ];
}