aggrid-8.x-1.x-dev/aggrid.module

aggrid.module
<?php

/**
 * @file
 * Contains aggrid.module.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Add aggrid settings to jquery variable
 * @param $variables
 */
function aggrid_preprocess_html(&$variables) {
  // Get config for aggrid.
  $config = \Drupal::config('aggrid.general');

  // Set the aggrid setting variable
  $variables['#attached']['drupalSettings']['aggrid']['settings']['license_key'] = $config->get('license_key');
  $variables['#attached']['drupalSettings']['aggrid']['settings']['aggridgsjson'] = $config->get('aggridgsjson');
  $variables['#attached']['drupalSettings']['aggrid']['settings']['aggridexcelstyles'] = $config->get('aggridexcelstyles');
  $variables['#attached']['drupalSettings']['aggrid']['settings']['aggridoptions'] = $config->get('aggridoptions');
  
}

/**
 * Implements hook_help().
 */
function aggrid_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the aggrid module.
    case 'help.page.aggrid':
      $output = '';
      $output .= '<h3>' . t('About the ag-Grid (aggrid) module and library') . '</h3>';
      $output .= '<p>' . t('Adds ag-Grid JSON field and widget to Drupal 8 Form API. For more help and information on the ag-Grid module, please see <a href=":url">the documentation online</a>. For information, support, and license information for the ag-Grid library, please go to <a href=":url2" target="_blank">http://www.ag-grid.com</a>.', [
        ':url' => 'https://www.drupal.org/docs/8/modules/aggrid',
        ':url2' => 'http://www.ag-grid.com',
      ]) . '</p>';
      return $output;

    default:
  }
}

/**
 * Implements hook_theme().
 */
function aggrid_theme() {
  return [
    'aggrid_table' => [
      'variables' => [
        'headers' => NULL,
        'rowSettings' => NULL, 
        'rowSuppression' => NULL, 
        'rowData' => NULL, 
        'attributes' => []
      ],
    ],
  ];
}

/**
 * Implements hook_libraries_info().
 */
function aggrid_libraries_info() {
  $libraries = [
    'ag-grid' => [
      'name' => 'ag-Grid',
      'vendor url' => 'http://www.ag-grid.com',
      'download url' => 'https://github.com/ag-grid/ag-grid/raw/master/packages/',
      'files' => [
        'js' => [
          'ag-grid-community.min.noStyle.js' => [],
          'ag-grid-enterprise.min.noStyle.js' => [],
        ],
      ],
    ],
  ];
  return $libraries;
}

/**
 * Check ag-Grid Library in local area
 */
function aggrid_library_local_check() {
  // Verify the library is installed.
  $aggrid_library_community = \Drupal::service('library.discovery')->getLibraryByName('aggrid', 'ag-grid-community');
  $install_path_community = $aggrid_library_community['js'][0]['data'];
  $aggrid_library_enterprise = \Drupal::service('library.discovery')->getLibraryByName('aggrid', 'ag-grid-enterprise');
  $install_path_enterprise = $aggrid_library_enterprise['js'][0]['data'];

  if (file_exists(DRUPAL_ROOT . '/' . $install_path_community) && file_exists(DRUPAL_ROOT . '/' . $install_path_enterprise)) {
    return true;
  }
  else {
    return false;
  }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc