You are here

protected function YoastSeoWidget::getJavaScriptConfiguration in Real-time SEO for Drupal 8.2

Returns the JavaScript configuration for this widget.

Return value

array The configuration that should be attached for the module to work.

1 call to YoastSeoWidget::getJavaScriptConfiguration()
YoastSeoWidget::formElement in src/Plugin/Field/FieldWidget/YoastSeoWidget.php
Returns the form for a single field widget.

File

src/Plugin/Field/FieldWidget/YoastSeoWidget.php, line 238

Class

YoastSeoWidget
Advanced widget for yoast_seo field.

Namespace

Drupal\yoast_seo\Plugin\Field\FieldWidget

Code

protected function getJavaScriptConfiguration() {
  global $base_root;
  $score_rules = $this->seoManager
    ->getScoreRules();

  // @todo Use dependency injection for language manager.
  // @todo Translate to something usable by YoastSEO.js.
  $language = \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId();
  $configuration = [
    // Set localization within the YoastSEO.js library.
    'language' => $language,
    // Set the base for URL analysis.
    'base_root' => $base_root,
    // Set up score to indicator word rules.
    'score_rules' => $score_rules,
    // Possibly allow properties to be editable.
    'enable_editing' => [],
  ];
  foreach ([
    'title',
    'description',
  ] as $property) {
    $configuration['enable_editing'][$property] = $this
      ->getSetting('edit_' . $property);
  }

  // Set up the names of the text outputs.
  foreach (self::$jsTargets as $js_target_name => $js_target_id) {
    $configuration['targets'][$js_target_name] = $js_target_id;
  }
  return $configuration;
}