You are here

public function YoastSeoManager::setGeneralConfiguration in Real-time SEO for Drupal 8

Set general configuration for yoast seo js.

Set

  • language
  • options (analyzer, snippet_preview)
  • base_root.

Parameters

array $elt: The element on which to attach the configuration.

Return value

array The same element passed, with the new configuration attached.

File

src/YoastSeoManager.php, line 224

Class

YoastSeoManager
Class YoastSeoManager.

Namespace

Drupal\yoast_seo

Code

public function setGeneralConfiguration(&$elt) {

  // Set the language code.
  $language = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  $elt['#attached']['drupalSettings']['yoast_seo']['language'] = $language;

  // General Yoast SEO js config.
  $elt['#attached']['drupalSettings']['yoast_seo']['analyzer'] = TRUE;
  $elt['#attached']['drupalSettings']['yoast_seo']['snippet_preview'] = TRUE;

  // Base root.
  global $base_root;
  $elt['#attached']['drupalSettings']['yoast_seo']['base_root'] = $base_root;

  // Cookie key where to store data.
  $elt['#attached']['drupalSettings']['yoast_seo']['cookie_data_key'] = 'yoastseo.metatags';
  return $elt;
}