devel_generate.batch.inc

Same filename in other branches
  1. 4.x devel_generate/devel_generate.batch.inc

Provides common batch functions for every DevelGeneratePlugin.

File

devel_generate/devel_generate.batch.inc

View source
<?php


/**
 * @file
 * Provides common batch functions for every DevelGeneratePlugin.
 */
use Drupal\devel_generate\DevelGenerateBaseInterface;

/**
 * Calls the correct method responsible for handling a given batch operation.
 */
function devel_generate_operation(DevelGenerateBaseInterface $class, $method, $vars, &$context) {
    return $class->{$method}($vars, $context);
}

/**
 * Standard finish batch function.
 */
function devel_generate_batch_finished($success, $results, $operations) {
    if ($success) {
        if (!empty($results['num_translations'])) {
            $message = t('Finished @num elements and @num_translations translations created successfully.', [
                '@num' => $results['num'],
                '@num_translations' => $results['num_translations'],
            ]);
        }
        else {
            $message = t('Finished @num elements created successfully.', [
                '@num' => $results['num'],
            ]);
        }
    }
    else {
        $message = t('Finished with an error.');
    }
    \Drupal::messenger()->addMessage($message);
}

Functions

Title Deprecated Summary
devel_generate_batch_finished Standard finish batch function.
devel_generate_operation Calls the correct method responsible for handling a given batch operation.