ClearJobItemsDataTmgmtActionApproveForm.php in TMGMT Extension Suite 8
File
src/Form/ClearJobItemsDataTmgmtActionApproveForm.php
View source
<?php
namespace Drupal\tmgmt_extension_suit\Form;
use Drupal\Component\Render\FormattableMarkup;
class ClearJobItemsDataTmgmtActionApproveForm extends BaseTmgmtActionApproveForm {
protected $tempStorageName = 'tmgmt_extension_suit_tmgmt_job_operations_clear_job_items_data';
public function getFormId() {
return 'tmgmt_extension_suit_clear_job_items_data_multiple_confirm';
}
public function getConfirmText() {
return $this
->t('Clear JobItem cache (data property)');
}
public function getQuestion() {
return $this
->t('Are you sure you want to clear JobItem cache (data property) from selected jobs?');
}
public function getDescription() {
return $this
->t('Clearing job items data can take some time, do not close the browser');
}
public static function processBatch($data, &$context) {
if (!isset($context['results']['errors'])) {
$context['results']['errors'] = [];
$context['results']['count'] = 0;
}
$entity_type_id = $data['entity_type'];
$entity_id = $data['entity_id'];
$job = \Drupal::entityTypeManager()
->getStorage($entity_type_id)
->loadMultiple([
$entity_id,
]);
$job = reset($job);
if (!$job) {
$context['results']['errors'][] = t('Entity @entity_type:@entity_id not found', [
'@entity_type' => $entity_type_id,
'@entity_id' => $entity_id,
]);
}
else {
$context['results']['count']++;
foreach ($job
->getItems() as $job_item) {
$job_item
->resetData();
$job_item
->save();
}
}
$context['message'] = new FormattableMarkup('Processed %name.', [
'%name' => $job
->label(),
]);
}
}