Problem/Motivation

When a source definition is created, only the machine names of these sources are passed. For the Tamper plugin "copy" it is more user friendly when the source labels are displayed instead of the machine names.

Copy plugin form now:

Copy plugin form when source labels are passed:

Note: the copy plugin is under development: #2976172: Copy Plugin

Steps to reproduce

Proposed resolution

Pass the source labels, if available.

Remaining tasks

  • Add test coverage
  • Review
  • Commit

User interface changes

API changes

Data model changes

Changes will follow.

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:

Comments

MegaChriz created an issue. See original summary.

megachriz’s picture

Status: Active » Needs work

Needs tests.

jamesdixon’s picture

Thanks I plan to review this week!

jamesdixon’s picture

StatusFileSize
new17.25 KB

Looks good.

For tests I'm thinking we would create a test function like testGetSourceDefinition in feeds_tamper/tests/src/Unit/FeedTypeTamperMetaTest.php.

We could assert that $source_list['alpha'] is equal to 'Alpha' and $source_list['beta'] is equal to 'Beta' after this code in setUp() is run, then getSourceDefinition() is run:

We could also try changing that getMappingSources mock function to return this array:

['alpha', 'beta']

Then we would check to make sure getSourceDefinition() is returning

['alpha' => 'alpha', 'beta' => 'beta']

since no labels were provided in the second case.

megachriz’s picture

@jamesdixon
Your suggestion for the first case sounds good. I think the second case should be the following:

[
  'alpha' => [],
  'beta' => [],
]

We make the assumption here that sources are always keyed by their machine name. Here is for example the method to add a custom source from \Drupal\feeds\Entity\FeedType:

/**
 * {@inheritdoc}
 */
public function addCustomSource($name, array $source) {
  $this->custom_sources[$name] = $source;
  return $this;
}

The custom source is saved with the machine name as the key.

Feeds also assumes the key of a source contains the machine name. From \Drupal\feeds\Form\MappingForm::buildForm():

foreach ($feed_type->getMappingSources() as $key => $info) {
  $this->sourceOptions[$key] = $info['label'];
}

So I think it is safe to assume that getMappingSources() never returns a numerical indexed array.

jamesdixon’s picture

Thanks! I'll look into setting up this test.

jamesdixon’s picture

I pushed a commit to the branch which starts the test but does not cover the second case we described where there is no label available for the source definition.

I'm trying to figure out the best way to change the Feed Type to return a different value for getMappingSources() without reproducing all the code form setUp(). Unfortunately since $feed_type is protected and I can't just change that on $this->feedTypeTamperMeta I think I will need to create another function which recreates the entire FeedTypeTamperMeta like was done in setUp().

Thinking of setting up a data provider function for testGetSourceDefinition() unless there's a better way.

megachriz’s picture

Possible way to solve this:

  1. Create a method that creates a FeedTypeTamperMeta: createFeedTypeTamperMeta().
  2. In setUp(), assign parameters to pass to FeedTypeTamperMeta to class variables ($this->feedType instead of $feed_type).
  3. Declare the new class variables.
  4. Maybe switch to using prophesy. Not sure if that would allow you to override a return value for a certain method?
  5. In the test method for the second case, override the return value for getMappingSources(), then call the method to create the FeedTypeTamperMeta. If it is not possible to override, then you could add a parameter to the createFeedTypeTamperMeta() method in which you can pass the return value for getMappingSources().
jamesdixon’s picture

Thanks I'll check this out!

jamesdixon’s picture

StatusFileSize
new15.46 KB

Thanks for all the guidance @megachriz! I pushed a candidate for the getSourceList() test to this branch.

It may not be the most elegant solution but I made a createFeedTamperMeta() function in the test, and passed the mapping sources parameter in setup so you could call it again to change the FeedTamperMeta if you need to.

Now I noticed getSourceDefinition() is returning the value of the source label as the machine key in the code:

Now the test is testing for that case. Do you think we need to change the getSourceList() code to return what you suggested here?

I'm not sure I fully understood that comment.

Also is there a guide on creating a merge request using the new branching system? There are options like squash commit etc and I'm not fully sure what that would do. There are multiple commits for this one issue and I'm used to a single commit for an issue.

@megachriz have you been using the merge request feature?

Thanks for all the help.

jamesdixon’s picture

Status: Needs work » Needs review
jamesdixon’s picture

Nevermind on the merge request stuff I had a read of the docs!

megachriz’s picture

Assigned: megachriz » Unassigned
Status: Needs review » Needs work

I've submitted my review, @jamesdixon. Note that there are also a few coding standard issues. See https://www.drupal.org/pift-ci-job/1960645

jamesdixon’s picture

Status: Needs work » Needs review

Thanks for the review @megachriz! I've worked through your feedback and pushed it to the merge request. Let me know if you see anything else you think we need to tune. Appreciate it.

  • MegaChriz committed 14bcf24 on 8.x-2.x
    Issue #3185025 by jamesdixon, MegaChriz: Pass source labels to a Tamper...
megachriz’s picture

Status: Needs review » Fixed

Alright, I think this is good to go. Merged!

Status: Fixed » Closed (fixed)

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