You are here

function drush_content_export_yaml_cim_block in Content Export YAML 8

File

drush/content_export_yaml.drush.inc, line 417

Code

function drush_content_export_yaml_cim_block($bundle = NULL, $id = NULL) {
  $block_content_list = \Drupal\block_content\Entity\BlockContentType::loadMultiple();
  $block_content_list_name = array_keys($block_content_list);
  if ($bundle == NULL) {
    drush_print('Block Type is required ,it should be one of : ' . implode(" - ", $block_content_list_name));
  }
  else {
    $export = new ContentExport();
    if (!in_array($bundle, $block_content_list_name)) {
      drush_print('That Block type  not exist , it should be one of : ' . implode(" - ", $block_content_list_name));
      return NULL;
    }
    if ($id) {
      $start = $id;
      $end = $id;
    }
    else {
      drush_print('Please enter Range ID you want to export : ');
      $start = drush_prompt(dt('Start To'));
      $end = drush_prompt(dt('End'));
    }
    if ($id == 'all') {
      $result = $export
        ->load_entity_config_list('block_content', $bundle);
    }
    else {
      $result = $export
        ->load_entity_config_list('block_content', $bundle, [
        $start,
        $end,
      ]);
    }
    if (!empty($result)) {
      if (drush_confirm(dt('Find items ' . sizeof($result) . ' , Are you sure to continue the process ?'))) {
        $total = sizeof($result);
        foreach ($result as $key => $item) {
          $info = [
            'id' => $item,
            'index' => $key + 1,
            'total' => $total,
            'entity' => 'block_content',
            'type' => $bundle,
          ];
          $operations[] = [
            'content_export_yaml_block_cim_index_batch_process',
            [
              $info,
            ],
          ];
        }
        $batch = [
          'operations' => $operations,
          'title' => t('Import block content process'),
          'init_message' => t('Starting...'),
          'progress_message' => t('Completed @current of @total.'),
          'error_message' => t('An error occurred'),
          'finished' => 'content_export_batch_finish',
          'file' => drupal_get_path('module', 'content_export_yaml') . '/drush/content_export_yaml.batch.inc',
        ];

        // Start the batch job.
        batch_set($batch);
        drush_backend_batch_process();
      }
      else {
        drush_print('Content Import Canceled');
      }
    }
    else {
      drush_print('No items are found');
    }
  }
}