Problem/Motivation

I'm using default_content module as a dependency for my custom module which creates different command line tasks for drupal console. I need ability to import data from any folder, not just specific module.

Proposed resolution

I propose to add another parameter to importContent method, which will be null by default and if someone passes that parameter method will ignore $module and use $folder as an export path.

There is another way, we could refactor $module parameter logic so that we specify only folder, this way we will have a freedom to generate content where we want, but it might be conflicting to #2614650

I created a patch, I'll attach it to this issue, hope it makes sense to others too.

Comments

otarza created an issue. See original summary.

otarza’s picture

anil280988’s picture

Status: Active » Needs review
otarza’s picture

otarza’s picture

Hi, I created another patch,

I think it will give us ability to use importContent method in a cleaner way, with only one $options argument:

$options argument is an array with the following structure:

$options = array('type' => 'module', 'module_name' => 'someModuleNmae')

Or

$options = array('type' => 'folder', 'folder_path' => 'somePathToFolderContainingJSONData')

This way everyone could have ability to specify where they want to export content.

Status: Needs review » Needs work

The last submitted patch, 5: allow_folder_option_for_importContent_method-2631618-5.patch, failed testing.

otarza’s picture

I made some changes to patch so tests don't fail now.

anil280988’s picture

Status: Needs work » Needs review

Hi otarza,
Whenever you upload the patch, the Status need to be changed to "Needs Review", only after that the patch will be reviewed. Changing the status, thanks for the patch.

snehi’s picture

Status: Needs review » Needs work
+++ b/src/DefaultContentManagerInterface.php
@@ -23,13 +23,15 @@ interface DefaultContentManagerInterface {
+   *   $options = array('type' => 'folder', 'folder_path' => 'somePathToFolderContainingJSONData')

Can we wrap it to 80 col. Otherwise look fine set of work.

otarza’s picture

Hello @snehi,

I made changes, this is a new patch which is wrapped in 80 col.

anil280988’s picture

Status: Needs work » Needs review

Hi otarza,
As mentioned before also, you need to change the status of the issue to "Needs review", else it will not be reviewed. Kindly keep that in mind from next time. Thanks for the patch.

otarza’s picture

anil280988 I cant change status to "Needs review" because looks like I'm not "confirmed" user :|

anil280988’s picture

Sorry for that @otarza.
To be a confirm user you can apply for the "confirmed" user role via the issue queue. Issue summary can just say 'Please review'.
See the following Link
-- https://www.drupal.org/node/1887616
-- https://www.drupal.org/node/add/project-issue/webmasters?component=User%...

snehi’s picture

looks ok to me +1 for RTBC. In future please add interdiff so that we can easily find what has been changed.

anil280988’s picture

Any update on this ?

andrewsuth’s picture

+1

Looks ready to merge.

andrewsuth’s picture

Status: Needs review » Reviewed & tested by the community
larowlan’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests
  1. +++ b/default_content.module
    @@ -12,7 +12,8 @@ function default_content_modules_installed($modules) {
    +      $options = array('type' => 'module', 'module_name' => $module);
    
    +++ b/src/DefaultContentManager.php
    @@ -141,9 +141,15 @@ class DefaultContentManager implements DefaultContentManagerInterface {
    +  public function importContent($options) {
    

    Why an array of options and not a second option argument?
    I'd prefer the later

  2. +++ b/src/DefaultContentManager.php
    @@ -217,7 +223,10 @@ class DefaultContentManager implements DefaultContentManagerInterface {
    +      if(!$folder) {
    +        $this->eventDispatcher->dispatch(DefaultContentEvents::IMPORT,
    +          new ImportEvent($created, $options['module_name']));
    +      }
    

    We need the event in both instances, but it should be a different event.

    This means it makes more sense to rename importContent as importContentFromModule and add a new method importContentFromFolder

Also, we need a test if possible, should be able to use drupal_get_path() to the test module and test using the folder

otarza’s picture

Hello,

I considered @larowlan's comment and refactored my patch.

Here is a new patch, containing following changes:

I refactored importContent method a little but I left most of it unchanged, I did this to prevent code duplicates.

So now importContent accepts $folder parameter only, not $module.

I also implemented 2 additional methods:

  • importContentFromModule($module) - accepts $module - machine name of the module.
  • importContentFromFolder($folder) - accepts $folder - the path to import content from.

Both methods call importContent($folder) method.

This way module's regular flow stays unchanged, only the name of method is changed when importing content from module.

I also updated .module file and DefaultContentManagerInterface accordingly.

otarza’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
otarza’s picture

Sorry, my previous patch failed tests, I checked and tested it now locally now it passes.

Find description of this patch above in #19

otarza’s picture

Status: Needs work » Needs review
ademarco’s picture

Status: Needs review » Reviewed & tested by the community

Patch works well in my case, marking as RTBC.

ademarco’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: -Needs tests
StatusFileSize
new32.87 KB
new32.37 KB

I've re-rolled patch on #22 working on the following points:

  • Writing tests for "import from folder" functionality: in order to test import from arbitrary directory I had to split default_content_test module into two modules: "default_content_test" which just holds configuration such as tags vocabulary and page term reference and "default_content_import_test" which depends from "default_content_test" and just provides default content.
  • Providing two different events for import from module and import from folder functionalities as suggested by @larowlan on #18
  • Splitting the "importContent()" method into two, protected, service methods: this will allow for custom modules to extend "DefaultContentManager" class in order to easily provide custom import logic reducing feature requests such as this very issue since now developers could simply build the importer as they see fit to their project
  • Fixing typos and Drupal coding-standards where I could spot them
  • Fixing deprecated usage of "SafeMarkup" class as per https://www.drupal.org/node/1312890

Interdiff between #22 and #26 is also provided.

bircher’s picture

Status: Needs review » Reviewed & tested by the community

Nice! This is a nice addition!

otarza’s picture

+1 for #26

otarza’s picture

Hello,

I wanted to use #26 but it turned out codebase changed so that I needed to create a reroll.

I'm including the reroll as a patch here, it would be great if we find the way to merge this soon.

I have added this message:

drupal_set_message(t('node @uuid imported', ['@uuid' => $entity->uuid()]));

to this reroll, so it will output not only already existed messages but newly created ones.

otarza’s picture

Issue summary: View changes
ademarco’s picture

I've reviewed the re-roll and everything works as expected. Thanks!

otarza’s picture

StatusFileSize
new32.85 KB

I have created another reroll because last one was failing while applying it to latest 8.x-1.x branch.

Status: Reviewed & tested by the community » Needs work

snehi’s picture

Anyone working on this ?

andypost’s picture

This will be useful with related

ndf’s picture

Status: Needs work » Needs review
StatusFileSize
new18.97 KB

Another reroll on current 8.x-1.x branch.
The reroll is manual, let's see what the testbot says.

Status: Needs review » Needs work
ndf’s picture

Status: Needs work » Needs review
StatusFileSize
new18.96 KB

Status: Needs review » Needs work
ndf’s picture

Assigned: Unassigned » ndf

The patch applies, but the tests are failing. Try to fix it next days/week.

ndf’s picture

Assigned: ndf » Unassigned
aaronbauman’s picture

Issue tags: -Novice

This feature would also allow the default content manager to be used, e.g. in an install profile.
Thanks for the patch

ao2’s picture

This could also be useful in relation to manual imports #2640734: [PP-1] Allow manual imports.

For example, the default-content-export-references has a --folder option, and an import command could have it too, for symmetry.

kalpaitch’s picture

I think this ticket may have merged with #2824103: default-content-export-references behaves differently than default-content-export which also needs to use the --folder option for symmetry.

Suggested credits get moved and work gets continued there.

kalpaitch’s picture

Status: Needs work » Closed (duplicate)

IMO anyway.

bryanmanalo’s picture

StatusFileSize
new1.04 KB

Adding a patch for 2.x branch.

These two issues do not alter the import behavior, only the export behavior.
#2824103: default-content-export-references behaves differently than default-content-export
#2640734: [PP-1] Allow manual imports

For my use case, I need to import from a folder, that is not in a module.