You are here

function ContentExport::load_entity_config_list in Content Export YAML 8

File

src/ContentExport.php, line 121

Class

ContentExport
Created by PhpStorm. User: USER Date: 11/13/18 Time: 2:04 PM

Namespace

Drupal\content_export_yaml

Code

function load_entity_config_list($entity, $bundle = NULL, $ranges_nid = []) {
  $items = [];
  if ($bundle == 'all') {
    $bundle = NULL;
  }
  $config = \Drupal::config('content_export_yaml.contentexportsetting');
  $themes_str = $config
    ->get('path_export_content_folder');
  if ($themes_str) {
    if (empty($ranges_nid)) {
      if ($bundle) {
        $items = $this
          ->readDirectory($themes_str . "/" . $entity . "/" . $bundle);
      }
      else {
        $items = $this
          ->readDirectory($themes_str . "/" . $entity);
      }
      foreach ($items as $key => $file) {
        if (file_exists($file)) {
          $items[$key] = file_get_contents($file, FILE_USE_INCLUDE_PATH);
        }
        else {
          $this->logger
            ->error('File  not find exist : ' . $file);
        }
      }
    }
    else {
      if (is_numeric($ranges_nid[0]) && is_numeric($ranges_nid[1])) {
        for ($i = $ranges_nid[0]; $i < $ranges_nid[1] + 1; $i++) {
          if ($bundle) {
            $file = DRUPAL_ROOT . '/' . $themes_str . "/" . $entity . "/" . $bundle . "/" . $i . ".yml";
          }
          else {
            $file = DRUPAL_ROOT . '/' . $themes_str . "/" . $entity . "/" . $i . ".yml";
          }
          if (file_exists($file)) {
            $items[$i] = file_get_contents($file, FILE_USE_INCLUDE_PATH);
          }
          else {
            $this->logger
              ->warning('File  not find exist : ' . $file);
          }
        }
      }
      else {
        if ($ranges_nid[0] == $ranges_nid[1]) {
          $file = DRUPAL_ROOT . '/' . $themes_str . "/" . $entity . "/" . $ranges_nid[1] . ".yml";
          if (file_exists($file)) {
            $items[$ranges_nid[0]] = file_get_contents($file, FILE_USE_INCLUDE_PATH);
          }
        }
      }
    }
  }
  else {
    $this->logger
      ->error('Path directory empty ');
  }
  return $items;
}