2021-03-17 18:56:01 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Drupal\images_styles_gen;
|
|
|
|
|
|
|
|
|
|
|
|
// use Drupal\node\Entity\Node;
|
|
|
|
|
|
|
|
class CreateImagesStyles {
|
|
|
|
|
|
|
|
public static function createStyles($item, &$context){
|
2021-03-17 19:24:09 +01:00
|
|
|
if (!array_key_exists('progress', $context['sandbox'])) {
|
2021-03-17 19:21:01 +01:00
|
|
|
$context['sandbox']['progress'] = 0;
|
|
|
|
}
|
2021-03-17 18:56:01 +01:00
|
|
|
$context['sandbox']['progress']++;
|
|
|
|
$context['sandbox']['current_file'] = $item->uri;
|
|
|
|
// $message = 'Creating Styles ...';
|
|
|
|
$results = array();
|
|
|
|
|
2021-03-17 19:21:01 +01:00
|
|
|
$results[] = $item->style->createDerivative($item->uri, $item->destination);
|
|
|
|
|
2021-03-17 18:56:01 +01:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|