Adds selected sources to continuous jobs.
\Drupal\Core\Form\FormStateInterface $form_state: Form state array.
string $item_type: Entity type.
public function overviewSubmitToContinuousJobs(FormStateInterface $form_state, $item_type) {
if ($form_state
->getValue('add_all_to_continuous_jobs')) {
// Build a list of allowed search conditions and get their values from the request.
$entity_type = \Drupal::entityTypeManager()
->getDefinition($item_type);
$whitelist = array(
'langcode',
'target_language',
'target_status',
);
$whitelist[] = $entity_type
->getKey('bundle');
$whitelist[] = $entity_type
->getKey('label');
$search_property_params = array_filter(\Drupal::request()->query
->all());
$search_property_params = array_intersect_key($search_property_params, array_flip($whitelist));
$operations = array(
array(
array(
ContentEntitySourcePluginUi::class,
'createContinuousJobItemsBatch',
),
array(
$item_type,
$search_property_params,
),
),
);
$batch = array(
'title' => t('Creating continuous job items'),
'operations' => $operations,
'finished' => 'tmgmt_content_create_continuous_job_items_batch_finished',
);
batch_set($batch);
}
else {
$entities = ContentEntitySource::loadMultiple($item_type, array_filter($form_state
->getValue('items')));
$job_items = 0;
// Loop through entities and add them to continuous jobs.
foreach ($entities as $entity) {
$job_items += tmgmt_content_create_continuous_job_items($entity);
}
if ($job_items !== 0) {
\Drupal::messenger()
->addStatus(\Drupal::translation()
->formatPlural($job_items, '1 continuous job item has been created.', '@count continuous job items have been created.'));
}
else {
\Drupal::messenger()
->addWarning(t('None of the selected sources can be added to continuous jobs.'));
}
}
}