simplytest-8.x-4.x-dev/modules/simplytest_import/simplytest_import.module

modules/simplytest_import/simplytest_import.module
<?php

/**
 * @file
 * Contains simplytest_import.module.
 */

use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\simplytest_projects\Entity\SimplytestProject;

/**
 * Implements hook_help().
 */
function simplytest_import_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the simplytest_import module.
    case 'help.page.simplytest_import':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Fetching data from drupal.org and importing the project automatically.') . '</p>';
      return $output;

    default:
  }
}

/**
 * Fetch and import batch process.
 */
function simplytest_import_batch_process($index, $type, &$context) {
  $importService = \Drupal::service('simplytest_import.service');
  $items = $importService->dataProvider($type, $index);
  $data = $importService->getCleanData($items['list']);
  foreach ($data as $datum) {
    $project = SimplytestProject::create($datum);
    $project->save();
  }
  $context['results']['processed'] += count($data);
  $context['results']['type'] = $type;
}

/**
 * Batch finished method.
 */
function simplytest_import_batch_finished($success, $results, $operations) {
  $messenger = \Drupal::messenger();
  if ($success) {
    $messenger->addMessage(t('Total @count @type imported.',
      [
        '@count' => $results['processed'] + 1,
        '@type' => str_replace('project_', '', $results['type']),
      ]));
  }
  else {
    $error_operation = reset($operations);
    $messenger->addMessage(
      t('An error occurred while processing @operation with arguments : @args',
        [
          '@operation' => $error_operation[0],
          '@args' => print_r($error_operation[0], TRUE),
        ]
      )
    );
  }
}

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

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