Commit a4840a26 authored by Arthur Callant's avatar Arthur Callant Committed by Oleksandr Kuzava
Browse files

Issue #3229470: Download as a zip with all assets

parent 9eed7734
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -62,8 +62,17 @@ hook_content_import_field_value_alter(&$value, FieldItemListInterface $field)
Yes! Please use the importer service and hook_update_N or similar to do it. Check it out

```php
function exaple_update_8001() {
function example_update_8001() {
  $file_path = drupal_get_path('module', 'example') . '/assets/homepage.yml';
  \Drupal::service('single_content_sync.importer')->importFromFile($file_path);
}
```

If you would like to import content from a generated zip file, use the following code:

```php
function example_update_8001() {
  $file_path = drupal_get_path('module', 'example') . '/assets/homepage.zip';
  \Drupal::service('single_content_sync.importer')->importFromZip($file_path);
}
```
+2 −3
Original line number Diff line number Diff line
name: Single Content Sync
type: module
description: 'Export/import a single content between different environments.'
core: 8.x
core_version_requirement: ^8 || ^9
core_version_requirement: ^8.8 || ^9
package: Content
dependencies:
  - drupal:yaml_editor
  - yaml_editor:yaml_editor
+5 −6
Original line number Diff line number Diff line
@@ -18,20 +18,19 @@ function single_content_sync_help($route_name, RouteMatchInterface $route_match)
      /** @var \Drupal\node\NodeInterface $node */
      $node = $route_match->getParameter('node');
      $output = '';
      $output .= '<p>' . t('Here is exported content of %title in %language.', [
      $output .= '<p>' . t('Here is the exported content of %title in %language.', [
        '%title' => $node->getTitle(),
        '%language' => $node->language()->getName(),
      ]) . '</p>';
      $output .= '<p>' . t('Just copy it and go to import page of another environment to paste it, or use the action buttons below.') . '</p>';
      $output .= '<br><p>' . t('You can download results as a zip file with all file references such as images, documents, videos and etc.') . '</p>';
      $output .= '<p>' . t('You can also download results as a single YAML file, in this case files will be imported by the absolute URL (suitable if you use CDN for files)') . '</p>';
      $output .= '<br><p>' . t('By using the file result you can import content on deploy. See README how to do it.') . '</p>';
      $output .= '<p>' . t('Simply copy it and go to the import page of another environment to paste it, or use the action buttons below.') . '</p>';
      $output .= '<br><p>' . t('You can download the results as a zip file with all file assets such as images, documents, videos and etc.') . '</p>';
      $output .= '<p>' . t('You can also download results as a single YAML file, in this case files will be imported by the absolute URL (suitable if your files hosted externally)') . '</p>';
      $output .= '<br><p>' . t('By using the generated file you can import content on deploy. See README how to do it.') . '</p>';

      return $output;

    case 'single_content_sync.import':
      $output = '';
      $output .= '<p>' . t('Paste the content that you just imported and click on the Import button.') . '</p>';
      $output .= '<p>' . t('We check content by uuid, so existing content is updated, and new content is created.') . '</p>';

      return $output;
+30 −2
Original line number Diff line number Diff line
services:
  single_content_sync.exporter:
    class: Drupal\single_content_sync\ContentExporter
    arguments: ['@entity_type.manager', '@module_handler', '@messenger', '@database']
    arguments:
      - '@entity_type.manager'
      - '@module_handler'
      - '@messenger'
      - '@database'

  single_content_sync.importer:
    class: Drupal\single_content_sync\ContentImporter
    arguments: [ '@entity_type.manager', '@entity.repository', '@module_handler', '@file_system']
    arguments:
      - '@entity_type.manager'
      - '@entity.repository'
      - '@module_handler'
      - '@file_system'
      - '@single_content_sync.helper'

  single_content_sync.file_generator:
    class: Drupal\single_content_sync\ContentFileGenerator
    arguments:
      - '@file_system'
      - '@entity_field.manager'
      - '@entity_type.manager'
      - '@single_content_sync.helper'
      - '@single_content_sync.exporter'

  single_content_sync.helper:
    class: Drupal\single_content_sync\ContentSyncHelper
    arguments:
      - '@uuid'
      - '@file_system'
      - '@plugin.manager.archiver'
      - '@entity_type.manager'
      - '@config.factory'
+4 −4
Original line number Diff line number Diff line
@@ -79,7 +79,7 @@ class ContentExporter implements ContentExporterInterface {
  /**
   * {@inheritdoc}
   */
  public function doExportToArray(FieldableEntityInterface $entity) {
  public function doExportToArray(FieldableEntityInterface $entity): array {
    $output = [
      'uuid' => $entity->uuid(),
      'entity_type' => $entity->getEntityTypeId(),
@@ -122,7 +122,7 @@ class ContentExporter implements ContentExporterInterface {
  /**
   * {@inheritdoc}
   */
  public function doExportToYml(FieldableEntityInterface $entity, $extract_translations = FALSE) {
  public function doExportToYml(FieldableEntityInterface $entity, $extract_translations = FALSE): string {
    // Remember the extract translation option to use it later.
    $this->extractTranslationsMode = (bool) $extract_translations;

@@ -135,7 +135,7 @@ class ContentExporter implements ContentExporterInterface {
  /**
   * {@inheritdoc}
   */
  public function exportBaseValues(FieldableEntityInterface $entity) {
  public function exportBaseValues(FieldableEntityInterface $entity): array {
    $entity_type = $entity->getEntityTypeId();

    switch ($entity_type) {
@@ -220,7 +220,7 @@ class ContentExporter implements ContentExporterInterface {
  /**
   * {@inheritdoc}
   */
  public function exportCustomValues(FieldableEntityInterface $entity, $check_translated_fields_only = FALSE) {
  public function exportCustomValues(FieldableEntityInterface $entity, bool $check_translated_fields_only = FALSE): array {
    $fields = $check_translated_fields_only ? $entity->getTranslatableFields() : $entity->getFields();
    $values = [];

Loading