You are here

commerce_generate.module in Commerce Bulk 8

File

modules/commerce_generate/commerce_generate.module
View source
<?php

/**
 * @file
 * Contains commerce_generate.module.
 */
use Drupal\Core\Entity\EntityInterface;
use Drupal\devel_generate\DevelGenerateBaseInterface;

/**
 * Implements hook_ENTITY_TYPE_insert().
 *
 * Do something with the newly saved product entity. Note that product must be
 * saved after making desirable changes.
 */
function commerce_generate_commerce_product_insert(EntityInterface $product) {
  if ($product->commerce_generate) {

    // $form_values = $product->commerce_generate;
    // ...
    // $product->save();
  }
}

/**
 * Wrapper for a given batch operation.
 *
 * Invokes the right method responsible for handling a given batch operation.
 * Available for this module's implementations of DevelGeneratePlugin.
 */
function commerce_generate_operation(DevelGenerateBaseInterface $class, $method, $vars, &$context) {
  return $class
    ->{$method}($vars, $context);
}

/**
 * Batch finish handler for implementations of DevelGeneratePlugin.
 */
function commerce_generate_batch_finished($success, $results, $operations) {
  if ($success) {
    $message = t('Creation of elements successfully finished.');
  }
  else {
    $message = t('Finished with an error.');
  }
  \Drupal::messenger()
    ->addMessage($message);
}

Functions

Namesort descending Description
commerce_generate_batch_finished Batch finish handler for implementations of DevelGeneratePlugin.
commerce_generate_commerce_product_insert Implements hook_ENTITY_TYPE_insert().
commerce_generate_operation Wrapper for a given batch operation.