materio-d9/web/modules/custom/images_styles_gen/src/CreateImagesStyles.php

40 lines
1.1 KiB
PHP

<?php
namespace Drupal\images_styles_gen;
// use Drupal\node\Entity\Node;
class CreateImagesStyles {
public static function createStyles($item, &$context){
if (!array_key_exists('progress', $context['sandbox'])) {
$context['sandbox']['progress'] = 0;
}
$context['sandbox']['progress']++;
$context['sandbox']['current_file'] = $item->uri;
// $message = 'Creating Styles ...';
$results = array();
$results[] = $item->style->createDerivative($item->uri, $item->destination);
$context['message'] = $item->uri . ' processed.';
$context['results'][] = $item->destination;
}
public static function createStylesFinishedCallback($success, $results, $operations) {
// The 'success' parameter means no fatal PHP errors were detected. All
// other error management should be handled using 'results'.
if ($success) {
$message = \Drupal::translation()->formatPlural(
count($results),
'One image processed.', '@count image processed.'
);
}
else {
$message = t('Finished with an error.');
}
drupal_set_message($message);
}
}