Comments

jian he created an issue. See original summary.

jian he’s picture

Status: Active » Needs review
StatusFileSize
new1.99 KB
heddn’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Any chance we can show some tests of this in action?

Merkator’s picture

Status: Needs work » Needs review
StatusFileSize
new24.43 KB

Here is it ! A patch with change from Jian He and a new test with more than one field in values definition.
Let me know if something miss.

Merkator’s picture

Issue tags: -Needs tests

Remove Needs Tests tag.

ultimike’s picture

I just manually tested this patch with a migration I'm working on and it appears to work as advertised.

-mike

heddn’s picture

Status: Needs review » Needs work

Can we keep the whitespace changes to a minimum here? I see what looks like a pretty small change taking up 25k in the patch. Very hard to review this thing.

mikemadison’s picture

Does not apply for me on the most recent dev via composer.

k4v’s picture

Here is a reroll for the current dev

k4v’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work
k4v’s picture

Patch works for me... Not sure about the testing stuff....

nicholasthompson’s picture

I had to tweak patch #4 to get it to work with a processed field (without this change I had lots of error about trying to Get an NestedArray).

My Setup is something like this:

process:
  type:
    plugin: default_value
    default_value: MY_TYPE
  title: title
  'body/value': description
  field_video:
    plugin: entity_generate
    source: id
    value_key: field_media_oembed_video
    entity_type: media
    bundle: remote_video
    values:
      name: title
      field_media_oembed_video:
        plugin: MY_PLUGIN
        source: id

However I have not looked into the tests..

nicholasthompson’s picture

Ok... something went weird on that patch and it wouldn't apply to the dev branch. I've manually reapplied the changes, reviewed the test change (which looks like it just moved everything out of a fixed array and into a $info variable? So I skipped that change) and rebuilt my patch.

sonnykt’s picture

Status: Needs work » Reviewed & tested by the community

The patch from #14 works with Migrate Plus 8.x-4.1 I am able to create media images with the patch.

process:
  title: product_name
  _field_featured_image_file:
    plugin: image_import
    source: product_image_url
    destination: 'constants/file_destination'
    rename: true
    alt: '@title'
  field_featured_image:
    plugin: entity_generate
    entity_type: media
    bundle: image
    value_key: mid
    bundle_key: vid
    source: '@title'
    default_values:
      bundle: image
      mid: null
      vid: null
    values:
      name: '@title'
      field_media_caption: '@title'
      field_media_image: '@_field_featured_image_file'

Without the patch, all fields name, field_media_caption, field_media_image are always array of processed values from

[
  '@title',
  '@title',
  '@_field_featured_image_file'
]

joekers’s picture

Confirming the above - #14 is working well for me too! Thanks for the patch!

heddn’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

Can we add some tests? NW for tests. Also, can we check the major version of Drupal and use the new Row::get methodology if we are running 8.7? See https://www.drupal.org/node/3001535

heddn’s picture

Category: Bug report » Task

Also, this is more of a task than a bug.

sonnykt’s picture

I just reckoned that EntityGenerate does not support nested values, eg. field_description/value or field_link/uri does not work.

process:
  type:
    field_tags:
      plugin: entity_generate
      source: tags
      default_values:
        description: Default description
      values:
        'field_long_description/value': source_desc
        'field_long_description/text_format': 'constants/text_format'
        'field_link/uri': source_link
        'field_link/tilte': source_link_text

will result in

$entity_values = [
  'description' => 'Default description',
  'field_long_description/value' => 'Source long description',
  'field_long_description/text_format' => 'rich_text',
  'field_link/uri' => 'http://some-link',
  'field_link/title' => 'Some link text',
];     

instead of the expected values

$entity_values = [
  'description' => 'Default description',
  'field_long_description' => [
    'value' => Source long description',
    'text_format' => 'rich_text',
  ],
  'field_link' => [
    'uri' => 'http://some-link',
    'title' => 'Some link text',
  ],  
];     

The below patch uses NestedArray::setValue() (like Row::setDestinationProperty()) to set the nested values.

skdrupal88’s picture

#20 Works well to me. Thanks!

jian he’s picture

Category: Task » Bug report

This is bug. Because the running result is not the same as what the document of class EntityGenerate say.

jian he’s picture

Title: EntityGenerate does not process the values correctly » EntityGenerate: Provide multiple values will not process correctly
Issue summary: View changes
jian he’s picture

Issue summary: View changes
jian he’s picture

Status: Needs work » Needs review
StatusFileSize
new5.65 KB
new3.09 KB

Add automated test.

jian he’s picture

jian he’s picture

Issue tags: -Needs tests

Automated test already provided

jian he’s picture

StatusFileSize
new5.61 KB
new1.26 KB

1. Fix #18, check the major version of Drupal and use the new Row::get methodology if running on 8.7
2. Remove miss added nested process plugin, because we already have @destination supported.

heddn’s picture

Status: Needs review » Needs work
Issue tags: +Novice

Very close. Tagging novice since this should be pretty trivial.

  1. +++ b/src/Plugin/migrate/process/EntityGenerate.php
    @@ -86,9 +87,7 @@ class EntityGenerate extends EntityLookup {
    +    $this->migratePluginManager = $migratePluginManager;
    

    Let's call this processPluginManager?

  2. +++ b/src/Plugin/migrate/process/EntityGenerate.php
    @@ -168,8 +167,14 @@ class EntityGenerate extends EntityLookup {
    +        else {
    +          $getProcessPlugin = $this->migratePluginManager->createInstance('get', ['source' => $property]);
    +          $source_value = $getProcessPlugin->transform(NULL, $this->migrateExecutable, $this->row, $property);
    

    Can we add a TODO and a link to an issue that is postponed to remove this logic once 8.6 is no longer supported?

jian he’s picture

Status: Needs work » Needs review
StatusFileSize
new6.39 KB
new2.69 KB

Thanks for the great review.

heddn’s picture

Status: Needs review » Reviewed & tested by the community

Looking good.

coufu’s picture

Great patch. Thanks all for the hard work.

heddn’s picture

Status: Reviewed & tested by the community » Fixed

  • heddn committed d452202 on 8.x-4.x authored by jian he
    Issue #2975266 by jian he, nicholasThompson, sonnykt, k4v, Merkator,...
heddn’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

l0ke’s picture

Is possible to create a release that will include this fix? I would say it's quite a major bug!

pcate’s picture

Version: 8.x-4.x-dev » 8.x-5.0-rc1

I've tried using this functionality with v5.0RC, but can't seem to get it working. I'm trying to generate missing taxonomy terms with it, but also add the description and description format at the same time. Here's the yaml:

field_job_type:
  - plugin: get
    source: JobType
  - plugin: callback
    callable: trim
  - plugin: entity_generate
    value_key: name
    bundle_key: vid
    bundle: job_type
    entity_type: taxonomy_term
    ignore_case: true
    values:
      description/value: JobCode
      description/format: 'plain_text'

The terms are generated fine with the correct name, but the description and format are not imported. Am I missed a configuration option or how this process plugin works? Appreciate any help.

gueguerreiro’s picture

@PCate, the format needs to be inside the 'default_values' configuration, and not 'values', since it's using an hardcoded value.
So:

field_job_type:
  - plugin: get
    source: JobType
  - plugin: callback
    callable: trim
  - plugin: entity_generate
    value_key: name
    bundle_key: vid
    bundle: job_type
    entity_type: taxonomy_term
    ignore_case: true
    default_values:
      description/format: 'plain_text'
    values:
      description/value: JobCode

Regardless, there's currently a problem processing array properties inside default_values. I opened up an issue here: https://www.drupal.org/project/migrate_plus/issues/3082060#comment-13262940 with a patch you can use to fix it.

stefan vaduva’s picture

I've installed the latest version and tried to use the following code:

field_point_of_contact:
    plugin: entity_generate
    access_check: false
    entity_type: node
    bundle: point_of_contact
    ignore_case: true
    values:
      title: contact_name
      body: contact_description
      field_email: email
      field_telephone: phone_number

Although contact_name, contact_description, email and phone_number have correct values, the point_of_contact node is not added in the database. Is there anything that I still need to do in order to have the entity created?

gueguerreiro’s picture

@stefan-vaduva it seems you're missing the source and value_key. Entity Generate checks if an entity already exists before creating it. You need to give it something to look for.

In your example, you could use the title, for example.

So, your end result should be:

field_point_of_contact:
    plugin: entity_generate
    access_check: false
    entity_type: node
    source: contact_name
    value_key: title
    bundle: point_of_contact
    ignore_case: true
    values:
      body: contact_description
      field_email: email
      field_telephone: phone_number
stefan vaduva’s picture

Thank you! I thought that the source & value_key are not mandatory if you just want to create it without looking for an existing one. Now it works

gueguerreiro’s picture

No problem, I'm glad you got it working :) To offer more information, it needs those values because Entity Generate is an extension of the Migration Lookup process plugin.