Let's add a chessboard field in 7.x-2.x before we release 7.x-2.0.
A proper storage schema first. We'll do fancy widgets and formatters in follow-up issues.
| Comment | File | Size | Author |
|---|---|---|---|
| #38 | chessboard-1402020-38.patch | 4.12 KB | eric_a |
| #38 | interdiff-1402020-37-38.txt | 473 bytes | eric_a |
| #37 | chessboard-1402020-37.patch | 4.22 KB | eric_a |
| #37 | interdiff-1402020-29-37.txt | 1.52 KB | eric_a |
| #36 | chessboard-1402020-36.patch | 5.86 KB | eric_a |
Comments
Comment #1
kenneth.venken commentedAttached is a first version of a chessboard field.
I decided to store the chess position as FEN in the database. There's only one widget (a textfield to input FEN) and one formatter (the chessboard_diagram render element). Although this is a very primitive field, it is useable as is.
Comment #2
kenneth.venken commentedFeedback is appreciated.
Comment #4
kenneth.venken commentedAnd simple FEN validation added.
Comment #5
kenneth.venken commentedAnd this time without the crlf line endings.
Comment #6
eric_a commentedAlright, here's my first (partial) code review.
That last line introduces nasty chessboard_filter.module coupling.
And are we not parsing the piece placement, then undoing that parsing, then parsing it again but even more granular, then have it stuffed into a render array? Probably best to build that render array as quickly and directly as possible.
Probably better to implement it like this: link_field_is_empty().
In general, chessboard can learn from what link, email and text are doing with fields.
Why the reverse, what's happening here? Might need an inline comment.
At some point we'll have to add a test.
Last but not least:
I feel we really should add a caption. See also #101068: Caption option would be nice. Also, as the title indicates, we should investigate storing the chessboard in multiple columns instead of just string notation.
Comment #7
kenneth.venken commented#101068: Caption option would be nice: I don't think it is necessary to make this part of the field although it makes sense to be added to the chessboard filter. If a user really wants a chessboard caption field, it can be added as a standard textfield to the entity.
I'm guessing we will need multiple database representations for different use cases anyway, so overthinking the design of the field database schema is probably unproductive. As a first step, we should create a field which stores the notation of the board as a string, reusing as much code as possible. See attached patch. We can improve the database schema with update hooks when it becomes clear what the use cases are.
Comment #9
kenneth.venken commentedIgnore previous patch...
This is the correct one.
Comment #11
kenneth.venken commentedPatch updated to latest 7.x-2.x version with piece placement class.
I had to move the piece placement class to the chessboard module to prevent dependency of the chessboard module on the chessboard_filter module.
Comment #12
eric_a commentedAlright, we'll go for the simplest feature set and implementation for now. I want a field in next mostly to help test and improve the overall architectural design. So, what I need is:
Also, I would like to not remove \Drupal\chessboard_filter\PiecePlacement.
Finally, I'm very, very happy to see Doxygen improvements, but I'd like to keep the unrelated changes outside of this patch and upcoming commit.
@kenneth.venken, do you still want to work on this? If you can do the above, I'll commit ASAP. (You can leave the test for me to do if you want.)
Comment #13
eric_a commentedOne more thing. Let's follow core's example and move the field code to an include file. We'll just do a require_once() at the top of the module file. This will also make it easier to keep 8.x-2.x and 7.x-2.x in sync. My plan is to commit this, then forward port to 8.x-2.x than port new classes back to 7.x-2.x.
Comment #14
eric_a commentedMy original intention was to build the pieces array or a PiecePlacement object in this hook, assuming that every field formatter is going to need that structure. But let's discuss wether it's worth the trouble.
My idea is to store a string of length 64 with any empty square represented as '-', which makes everything so much simpler. (Which is also the way we have them when preparing for rendering). When building the widget we can use the #process property to reference a chessboard_form_process_piece_placement() callback function to process the data to normal FEN/ EPD piece placement syntax, no?
Comment #15
eric_a commentedHm, is there any use for a #process property if we're just computing the initial form element default value? I'll stop spamming the issue with ideas now. It's code that we need.
Comment #16
eric_a commentedRe-rolled and cleaned up #11, temporarily re-introducing the dependency on _chessboard_filter_process_chessboard_notation(). (To fix that we can inline the few lines that we need from that function body.)
Comment #17
eric_a commentedImplemented most of the changes mentioned earlier. Right now the widget only understands the '-'-syntax for empty squares.
Comment #18
eric_a commentedMoved the code to chessboard.field.inc.
Comment #19
eric_a commentedNow with include file loading.
Comment #21
eric_a commentedComment #22
eric_a commentedReroll for #1887698: Implement 8x8 board handling.
Comment #23
eric_a commented#22: chessboard-add-a-chessboard-field-1402020-22.patch queued for re-testing.
Comment #24
eric_a commented22: chessboard-add-a-chessboard-field-1402020-22.patch queued for re-testing.
Comment #25
eric_a commentedEDIT: uploaded the wrong patch with the correct interdiff... (Regarding
chessboard_field_schema().)We're not storing FEN, so changed the patch to reflect this.
Comment #26
eric_a commentedThe default formatter is now the simple and direct piece placement format. E.g.,
rnbqkbnrpppppppp--------------------------------PPPPPPPPRNBQKBNRis formatted asComment #27
eric_a commentedWith pre element tags we don't want nl2br()...
Comment #28
eric_a commentedA little cleaning up.
Comment #29
eric_a commentedRenamed widget and formatter to chessboard_default/ chessboard_simple plus some minor changes.
Comment #30
eric_a commentedAnd a D8 patch.
Comment #31
eric_a commentedComment #32
eric_a commentedComment #33
eric_a commentedComment #34
eric_a commentedAdded Regex constraint. Changed Length constraint.
Comment #35
eric_a commentedCore does not expose the Symfony Regex constraint (yet)...
Comment #36
eric_a commentedImplemented isEmpty().
Comment #37
eric_a commentedPushed #36 to 8.x-2.x. Moving to 7.x-2.x.
Comment #38
eric_a commentedRemoved the index.
Comment #39
eric_a commentedPushed #38 to 7.x-2.x.
Time to start work on widgets and formatters!
Many thanks to @kenneth.venken for helping to drive this home.