You are here

public function ContentExportController::view in Content Export YAML 8

Handles html requests.

Return value

string Return Hello string.

1 string reference to 'ContentExportController::view'
content_export_yaml.routing.yml in ./content_export_yaml.routing.yml
content_export_yaml.routing.yml

File

src/Controller/ContentExportController.php, line 21

Class

ContentExportController
Class ContentExportController.

Namespace

Drupal\content_export_yaml\Controller

Code

public function view() {
  $query = \Drupal::request()->query
    ->all();
  if ($query['file_single']) {
    $result = $query['file_single'];
    $id = basename($query['file_single'], '.yml');
    $bundle = $this
      ->_getBundleName($result);
    $entity_type = $this
      ->_getEntityType($result);
    $object_file = $this
      ->_getObjectinFile($result);

    ///in database
    $entity_list_name = array_keys(\Drupal::entityTypeManager()
      ->getDefinitions());
    if (in_array($entity_type, $entity_list_name)) {
      $item['is_entity'] = true;
      $bundle_list_name = \Drupal::service('entity_type.bundle.info')
        ->getBundleInfo($entity_type);
      if (in_array($bundle, array_keys($bundle_list_name))) {
        $item['is_bundle'] = true;
        $object = \Drupal::entityTypeManager()
          ->getStorage($entity_type)
          ->load($id);
        if ($object) {
          $item['database']['id'] = $object ? $object
            ->id() : "";
          $item['database']['label'] = $object ? $object
            ->label() : "";
          $item['database']['created'] = $object && $object->created ? date("Y-m-d H:i:s", $object->created->value) : "";
          $item['database']['changed'] = $object && $object->changed ? date("Y-m-d H:i:s", $object->changed->value) : "";
          $item['database']['uid'] = $object && $object->uid ? $object->uid->target_id : "";
        }
        if ($object_file) {
          $item['file']['id'] = $object_file ? $object_file
            ->id() : "";
          $item['file']['label'] = $object_file ? $object_file
            ->label() : "";
          $item['file']['created'] = $object_file && $object_file->created ? date("Y-m-d H:i:s", $object_file->created->value) : "";
          $item['file']['changed'] = $object_file && $object_file->changed ? date("Y-m-d H:i:s", $object_file->changed->value) : "";
          $item['file']['uid'] = $object_file && $object_file->uid ? $object_file->uid->target_id : "";
        }
      }
    }
    $item['file_path'] = $query['file_single'];
    $item['entity_type'] = $entity_type;
    $item['bundle'] = $bundle;
    $output = [
      '#theme' => 'view_template_item',
      '#item' => $item,
      '#cache' => [
        'max-age' => 0,
      ],
    ];
    return $output;
  }
  else {
    return [
      '#markup' => $this
        ->t('Item not found.'),
    ];
  }
}