Closed (fixed)
Project:
Feeds
Version:
8.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
7 Aug 2019 at 15:19 UTC
Updated:
20 Jun 2022 at 14:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
megachrizI think it is technically possible to import data for books (without architectural changes in Feeds).
Book data is stored in a separate table, namely the table "book". When I look at the code of the book module, it seems it is coded in a quite customly manner: no fields are used and the book data is also not entity data.
I think the best way forward is creating a new target plugin that is based on
\Drupal\feeds\Plugin\Type\Target\TargetBaseand which sets properties of 'book'. Seebook_schema()for which properties there are for book.Looking at the code, it looks like some properties are automatically set, like 'nid', for example. At first glance, useful properties to expose are at least:
Not sure about the others.
Will you work on this feature, @Harrietech? You assigned the issue to yourself. If not, you may need to hire a developer if this is an important feature to you.
Comment #3
megachrizI've created a mapping target for 'Book'.
Summary of the additions:
prepareValues()method.isMutable()andisEmpty(). This is because locally I was creating this feature on top of the Entity ID target feature (#2989279: Add a target to entity ID) and that feature requires these new methods. I hope to finish off that one soon too, so both can be committed.Comment #4
megachrizCoding standard fixes.
Comment #6
megachriz"scalar" is not valid type hint, so it seems. I tried to fix the coding standard violation in an other way.
Comment #7
bwong commentedThis saved me a a lot of time. I can confirm that this works as advertised using different sources for finding the book and parents including feed item.guid.
Comment #8
irinaz commentedI tested updated module on a site with existing feeds and updated version works correctly. I think I accidentally created fork https://git.drupalcode.org/issue/feeds-3073275 instead of branch.
Comment #9
megachrizI updated the book target to make it compatible with the updated Entity service (which was committed yesterday in #3206365: Add an EntityFinder service).
It would be good to test the updated version before commit. I did tests the changes myself and so far I think it still works.
Comment #11
megachrizThe code changes are now in an issue branch instead of a patch.
Comment #12
irinaz commentedI set up testing instance using DevPanel here http://dev-13c1d72a-13c1d77f-13c1d783.app.devpanel.com/, but I realized that I do not have good data example for books import. Are there any recommendations on how to set this data so this feature could be tested?
Comment #13
megachriz@irinaz
Books in Drupal are hierarchical nodes. Each book page refers to the book that they are in and what their parent node is.
I have tested importing books myself with the following CSV data:
Note that Chapter 5 is defined before Section 2 is defined: in this case, a second import would be needed to put "Chapter 5" at the right spot in the book.
And this is a screenshot of how I setup the mapping:

I already tested with this configuration and data and for me that worked correctly. It would be more interesting to test with other configurations. For example: I have not tested what happens if you do map to "Book outline (book): Parent item", but not to "Book outline (book): Book". And vice versa. Also, I've not tested other fields to reference by (I only tested referencing data by title, not by ID, UUID or "Feeds item: GUID"). These cases should be covered by the automated tests, but I think are still useful to test manually because tests could potentially also have bugs.
Comment #14
irinaz commentedTested import with weight, works great. If "Book outline (book): Book" is not mapped then outline is not created correctly. Maybe "Book outline (book): Book" should be required.
Comment #15
irinaz commentedComment #16
kristen polReviewed the code quickly and WOW. @MegaChriz has such clean code!!! :)
Regarding:
I think it would cause less confusion if it was required. What's the use case is using "Book outline (book): Parent item"?
Seems like @MegaChriz mainly wants more manual testing?
Comment #17
irinaz commented@Kristen Pol, books are used for hierarchy structure "out of the box". Top level page in a book does not have parent. I think that adding this feature "as is" will be helpful. After your review do we move it to RTBC?
Comment #18
kristen polI only looked at the code and didn't do any testing. I assume more is needed? Or is what you did last year sufficient? Also, there is a ton of code and I don't claim to understand it all so, if you want a deep code review, then you could ask around.
Comment #19
megachrizMarking this as "Needs work" because of the feedback in #14:
Comment #20
megachrizSummary of the changes:
1is passed, Feeds will attempt to create a new book of the item.Comment #21
lucienchalom commentedI will try to review and test =)
Comment #22
paulocsWorking testing this issue :)
Comment #23
paulocsWow. I tested the MR and it looks really good.
I made a very small change related to unused statements and deprecated code but for me is RTBC.
Comment #25
megachrizThe code is merged! Thanks everyone for testing and reviewing!