You are here

function filefield_paths_batch_update in File (Field) Paths 8

Same name and namespace in other branches
  1. 6 filefield_paths.module \filefield_paths_batch_update()
  2. 7 filefield_paths.module \filefield_paths_batch_update()

Set batch process to update File (Field) Paths.

Parameters

FieldConfig $field_config: TODO.

Return value

bool TODO.

2 calls to filefield_paths_batch_update()
filefield_paths_form_submit in ./filefield_paths.module
Submit callback for File (Field) Paths settings form.
_filefield_paths_drush_ffp_update in ./filefield_paths.drush.inc
Helper function; Invokes File (Field) Paths Retroactive updates.

File

./filefield_paths.module, line 255
Contains core functions for the File (Field) Paths module.

Code

function filefield_paths_batch_update(FieldConfig $field_config) {
  $entity_info = \Drupal::entityTypeManager()
    ->getDefinition($field_config
    ->getTargetEntityTypeId());
  $query = \Drupal::entityQuery($field_config
    ->getTargetEntityTypeId());
  $result = $query
    ->condition($entity_info
    ->getKey('bundle'), $field_config
    ->getTargetBundle())
    ->condition("{$field_config->getName()}.target_id", '', '<>')
    ->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT')
    ->execute();

  // If there are no results, do not set a batch as there is nothing to process.
  if (empty($result)) {
    return FALSE;
  }

  // Create batch.
  $batch = [
    'title' => t('Updating File (Field) Paths'),
    'operations' => [
      [
        '_filefield_paths_batch_update_process',
        [
          $result,
          $field_config,
        ],
      ],
    ],
  ];
  batch_set($batch);
  return TRUE;
}