The docs for EmptySource at https://api.drupal.org/api/drupal/core%21modules%21migrate%21src%21Plugi... say:

> This will return a single row containing 'entity_type' and 'field_name' elements, with values of 'user' and 'image', respectively.

But when I tried this, it doesn't work:

source:
  plugin: empty
  constants:
    title: 'My title'
    type: 'default'
    uid: 1
process:
  title: title
  type: type
  uid: uid

I had to do this instead:

process:
  title: constants/title
  type: constants/type
  uid: constants/uid

Using constants like that is no different from what can be done with any other migration source plugin.

The documentation claims the row will be populated with the constant values, but it's not. Looking at the code, I don't see that the plugin is doing anything of the sort.

Issue fork drupal-3197749

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim created an issue. See original summary.

quietone’s picture

I don't think that how to use 'constants' is documented at all. :-(

Adding this to the meta for documenting source plugins.

joachim’s picture

I'm not sure whether this issue here is a documentation error, or a code error. The two don't agree, but which should be taken as correct?

quietone’s picture

I could not find where the use of 'constants' is documented. I am not sure where to put it but I think that SourcePluginBase is the best option. The term 'constants' isn't a configuration key and in fact one can use any name or have several names. For example, the following is valid.

source:
   plugin: empty
   constants:
     entity_type: user
     field_name: image
   foo:
     bar: baz
process:
    a: foo/bar
    b: constants/entity_type

It is just the way that \Drupal\migrate\Row::get works.

quietone’s picture

Status: Active » Needs work
quietone’s picture

Status: Needs work » Needs review
joachim’s picture

Status: Needs review » Needs work

Patch looks good, apart from documenting the use of other keys. I think that's a bug we should be removing.

I kinda thought populating fields with the constant names was a nice feature, but at the same time, having one source plugin where constants behave differently was a potential WTF.

quietone’s picture

@joachim, I wasn't sure if the ability to add other keys should be documented or not. I added it for completeness and to see what reviewers would say. I am happy for it to remain undocumented.

I don't think it is a bug either. Any value can be placed on the row and source plugins can define any configuration properties they want. How would Row::getSourceProperty distinguish a that a property name, e.g. 'other', from the other properties on the row or in the source configuration.

quietone’s picture

Status: Needs work » Needs review
joachim’s picture

Status: Needs review » Reviewed & tested by the community

> I don't think it is a bug either. Any value can be placed on the row and source plugins can define any configuration properties they want. How would Row::getSourceProperty distinguish a that a property name, e.g. 'other', from the other properties on the row or in the source configuration.

Wouldn't it be possible for properties set in the migration YML to clash with data the source plugin wants to put into the row as well? Anyway, we can open a new issue for discussing whether this is a bug to be fixed, or a feature to be documented.

Patch here looks good!

alexpott’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: +Documentation

Committed and pushed 499e358acd to 9.2.x and 714570280d to 9.1.x. Thanks!

Backported to 9.1.x as this is a documentation fix.

  • alexpott committed 499e358 on 9.2.x
    Issue #3197749 by quietone, joachim: empty migrate source does not...

  • alexpott committed 7145702 on 9.1.x
    Issue #3197749 by quietone, joachim: empty migrate source does not...

Status: Fixed » Closed (fixed)

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