You are here

function entity_translation_unified_form_page_attachments in Entity Translation Unified Form 8

Implements hook_page_attachments().

Adds the libraries to only the edit node and add node page.

File

./entity_translation_unified_form.module, line 56

Code

function entity_translation_unified_form_page_attachments(array &$page) {
  $current_path = \Drupal::service('path.current')
    ->getPath();
  $patterns = "/node/add/*\n/node/*/edit";
  $match = \Drupal::service('path.matcher')
    ->matchPath($current_path, $patterns);
  if (!empty($match)) {
    $bundle = '';
    if (strpos($current_path, '/edit') > 4) {

      // Get the node object.
      $node = \Drupal::routeMatch()
        ->getParameter('node');
      $bundle = $node
        ->bundle();
    }
    else {

      // Get the bundle.
      $array_of_segments = explode('/', $current_path);
      $bundle = end($array_of_segments);
    }
    if (entity_translation_unified_form_sbs_enabled('node', $bundle)) {

      // Get the CSS for the current theme
      $theme = \Drupal::service('theme.manager')
        ->getActiveTheme()
        ->getName();
      if (file_exists(drupal_get_path('module', 'entity_translation_unified_form') . "/css/etuf-side-by-side-{$theme}.css")) {
        $page['#attached']['library'][] = 'entity_translation_unified_form/etuf-' . $theme;
      }
      else {

        // Default theme
        $page['#attached']['library'][] = 'entity_translation_unified_form/etuf';
      }
      $other_languages = EtufHelper::getOtherEnabledLanguages();
      foreach ($other_languages as $other_langcode => $other_language) {
        $page['#attached']['drupalSettings']['other_langs'][] = $other_langcode;
      }
    }
    if (!entity_translation_unified_form_moderation_sync_disabled('node', $bundle)) {
      $page['#attached']['library'][] = 'entity_translation_unified_form/etuf-moderation-sync';
      $other_languages = EtufHelper::getOtherEnabledLanguages();
      foreach ($other_languages as $other_langcode => $other_language) {
        $page['#attached']['drupalSettings']['other_langs'][] = $other_langcode;
      }
    }
  }
}