<?php

/**
 * @file
 * Accessibility Indicator for Title Length module.
 *
 * This file perform a hook to show the progress bar for nodes.
 */

/**
 * Implements hook_form_FORM_ID_alter().
 */
function title_a11y_form_node_form_alter(&$form) {

  // Add custom HTML to the title field.
  if (isset($form['title']['widget'][0])) {
    // Add template for the progress bar.
    $form['title']['widget'][0]['value']['#prefix'] = file_get_contents(\Drupal::service('extension.list.module')->getPath('title_a11y') . '/templates/progress-bar.html');

    // Get config.
    $config = \Drupal::config('title_a11y.settings');

    // Attach the library.
    $form['#attached']['library'][] = 'title_a11y/title_a11y';
    $form['#attached']['drupalSettings']['title_a11y'] = [
      'val0' => $config->get('val0'),
      'val1' => $config->get('val1'),
      'val2' => $config->get('val2'),
      'val3' => $config->get('val3'),
      'val4' => $config->get('val4'),
    ];
  }
}
