easychart-8.x-3.5/easychart.module

easychart.module
<?php

/**
 * @file
 * Easychart module file.
 */

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\easychart\EasychartUpdate;
use Drupal\file\Entity\File;

/**
 * Implements hook_form_FORM_ID_alter().
 */
function easychart_form_field_config_edit_form_alter(&$form, FormStateInterface $form_state) {
  if ($form_state->getFormObject()->getEntity()->getType() == 'easychart') {
    $form['default_value']['#access'] = FALSE;
  }
}

/**
 * Implements hook_cron().
 */
function easychart_cron() {
  // We don't want to act every time cron runs (which could be every
  // minute) so keep a time for the next run in state..
  $interval = \Drupal::config('easychart.settings')->get('url_update_frequency');
  $next_execution = \Drupal::state()->get('easychart_cron_next_execution', 0);

  if (!empty($interval) && \Drupal::time()->getRequestTime() >= $next_execution) {
    EasychartUpdate::updateCsvFromUrl();
    \Drupal::state()->set('easychart_cron_next_execution', \Drupal::time()->getRequestTime() + $interval);
  }
}

/**
 * Implements hook_library_info_build().
 */
function easychart_library_info_build() {
  $libraries = [];

  // Used for rendering.
  $libraries['lib.easycharts.render'] = [
    'version' => 'VERSION',
    'js' => [
      base_path() . 'libraries/easychart/dist/ec.render.min.js' => [],
    ],
  ];

  // The version numbers and remote for the next two libraries are used for
  // drush integration.
  $libraries['lib.highcharts'] = [
    'version' => '10.1.0',
    'remote' => 'http://code.highcharts.com/zips/Highcharts-10.1.0.zip',
    'license' => [
      'name' => 'Creative Commons Attribution - Non Commercial 3.0 License',
      'gpl-compatible' => FALSE,
    ],
    'js' => [
      base_path() . 'libraries/highcharts/code/highcharts.js' => [],
      base_path() . 'libraries/highcharts/code/highcharts-3d.js' => [],
      base_path() . 'libraries/highcharts/code/highcharts-more.js' => [],

      base_path() . 'libraries/highcharts/code/modules/data.js' => [],
      base_path() . 'libraries/highcharts/code/modules/exporting.js' => [],
      base_path() . 'libraries/highcharts/code/modules/funnel.js' => [],
      base_path() . 'libraries/highcharts/code/modules/solid-gauge.js' => [],
      base_path() . 'libraries/highcharts/code/modules/accessibility.js' => [],
    ],
  ];

  $libraries['lib.highcharts-editor'] = [
    'version' => '0.2.2',
    'remote' => [
      'https://github.com/highcharts/highcharts-editor/releases/download/v0.2.2-rc3/highcharts-editor.standalone.0.2.2.zip',
      'https://github.com/highcharts/highcharts-editor/releases/download/v0.2.2-rc3/highcharts-editor.complete.min.zip',
    ],
    'license' => [
      'url' => 'https://github.com/highcharts/highcharts-editor/blob/master/LICENSE',
      'gpl-compatible' => TRUE,
    ],
    'js' => [
      base_path() . 'libraries/highcharts-editor/highcharts-editor.complete.js' => [],
    ],
    'css' => [
      'base' => [
        base_path() . 'libraries/highcharts-editor/highcharts-editor.min.css' => [],
      ],
    ],
  ];

  $libraries['lib.easycharts.full'] = [
    'version' => '3.1.3',
    'remote' => 'https://github.com/daemth/easychart/archive/master.zip',
    'license' => [
      'name' => 'MIT',
      'url' => 'https://github.com/daemth/easychart/blob/master/LICENSE',
      'gpl-compatible' => TRUE,
    ],
    'js' => [
      base_path() . 'libraries/easychart/dist/ec.min.js' => [],
    ],
  ];

  return $libraries;
}

/**
 * Implements hook_entity_presave().
 */
function easychart_entity_presave(EntityInterface $entity) {
  // Install the chart file.
  if ($entity->getEntityTypeId() == 'embed_button' && $entity->id() == 'chart' && $entity->isNew()) {
    /** @var \Drupal\Core\Extension\ModuleExtensionList $moduleExtensionList */
    $moduleExtensionList = \Drupal::service('extension.list.module');
    $path = $moduleExtensionList->getPath('easychart') . '/assets/chart.png';

    /** @var \Drupal\file\FileInterface $file */
    $file = File::create();
    $file->setFileUri($path);
    $file->setOwnerId(\Drupal::currentUser()->id());
    $file->setMimeType('image/' . pathinfo($path, PATHINFO_EXTENSION));
    $file->setFileName(\Drupal::service('file_system')->basename($path));

    $chart_icon = \Drupal::service('file.repository')->copy($file, 'public://embed_buttons');
    if ($chart_icon) {
      $entity->set('icon_uuid', $chart_icon->uuid());
    }
  }
}

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

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