<?php

/**
 * @file
 * top_bar.theme
 */

/**
 * Implements hook_preprocess_HOOK() for top_bar.
 */
function gin_preprocess_top_bar(array &$variables) {
  if (!_gin_module_is_active('navigation_top_bar')) {
    return;
  }

  // Get local actions.
  $block_manager = \Drupal::service('plugin.manager.block');
  if ($plugin_block = $block_manager->createInstance('local_actions_block', [])) {
    $block_content = $plugin_block->build();
    $variables['gin_local_actions'] = \Drupal::service('renderer')->render($block_content);
    $variables['#attached']['library'][] = 'gin/top_bar';
  }

  // Get form actions.
  if ($form_actions = _gin_form_actions()) {
    $variables['gin_form_actions'] = $form_actions;
    $variables['gin_form_actions_class'] = 'gin-sticky-form-actions--preprocessed';
    $variables['#attached']['library'][] = 'gin/top_bar';
  }
}
