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.

CommentFileSizeAuthor
#38 chessboard-1402020-38.patch4.12 KBeric_a
#38 interdiff-1402020-37-38.txt473 byteseric_a
#37 chessboard-1402020-37.patch4.22 KBeric_a
#37 interdiff-1402020-29-37.txt1.52 KBeric_a
#36 chessboard-1402020-36.patch5.86 KBeric_a
#36 interdiff-1402020-35-36.txt586 byteseric_a
#35 chessboard-1402020-35.patch5.69 KBeric_a
#35 interdiff-1402020-34-35.txt1.68 KBeric_a
#34 chessboard-1402020-34.patch4.79 KBeric_a
#34 interdiff-1402020-33-34.txt1010 byteseric_a
#33 chessboard-1402020-33.patch4.57 KBeric_a
#33 interdiff-1402020-32-33.txt764 byteseric_a
#32 chessboard-1402020-32.patch4.55 KBeric_a
#32 interdiff-1402020-31-32.txt725 byteseric_a
#31 chessboard-1402020-31.patch4.55 KBeric_a
#31 interdiff-1402020-30-31.txt1.48 KBeric_a
#30 chessboard-1402020-30.patch4.56 KBeric_a
#29 chessboard-1402020-29.patch3.32 KBeric_a
#29 interdiff-1402020-28-29.txt2.37 KBeric_a
#28 chessboard-1402020-28.patch3.32 KBeric_a
#28 interdiff-1402020-27-28.txt930 byteseric_a
#27 chessboard-1402020-27.patch3.5 KBeric_a
#27 interdiff-1402020-26-27.txt598 byteseric_a
#26 chessboard-1402020-26.patch3.5 KBeric_a
#26 interdiff-1402020-25-26.txt1.08 KBeric_a
#25 chessboard-1402020-25.patch3.92 KBeric_a
#25 interdiff-1402020-22-25.txt3.07 KBeric_a
#22 interdiff.txt572 byteseric_a
#22 chessboard-add-a-chessboard-field-1402020-22.patch3.86 KBeric_a
#21 interdiff.txt386 byteseric_a
#21 chessboard-add-a-chessboard-field-1402020-21.patch3.96 KBeric_a
#19 interdiff.txt324 byteseric_a
#19 chessboard-add-a-chessboard-field-1402020-19.patch3.96 KBeric_a
#18 interdiff.txt5.86 KBeric_a
#18 chessboard-add-a-chessboard-field-1402020-18.patch3.59 KBeric_a
#17 interdiff.txt2.12 KBeric_a
#17 chessboard-add-a-chessboard-field-1402020-17.patch3.57 KBeric_a
#16 chessboard-add-a-chessboard-field-1402020-16.patch3.39 KBeric_a
#11 chessboard-add-a-chessboard-field-1402020-11.patch13.33 KBkenneth.venken
#9 chessboard-add-a-chessboard-field-1402020-7.patch4.65 KBkenneth.venken
#7 devel_themer-accessible-design-1711392-7.patch5.23 KBkenneth.venken
#5 chessboard-add-a-chessboard-field-1402020-5.patch6.41 KBkenneth.venken
#4 chessboard-add-a-chessboard-field-1402020-3.patch6.52 KBkenneth.venken
#1 chessboard-add-a-chessboard-field-1402020-1.patch3.48 KBkenneth.venken

Comments

kenneth.venken’s picture

Attached 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.

kenneth.venken’s picture

Status: Active » Needs review

Feedback is appreciated.

Status: Needs review » Needs work

The last submitted patch, chessboard-add-a-chessboard-field-1402020-1.patch, failed testing.

kenneth.venken’s picture

Status: Needs work » Needs review
StatusFileSize
new6.52 KB

And simple FEN validation added.

kenneth.venken’s picture

And this time without the crlf line endings.

eric_a’s picture

Issue tags: +Needs tests

Alright, here's my first (partial) code review.

+        $board = chessboard_parse_fen($item['fen']);
+        $item['value'] = implode('/', $board['board']);
+        $item = chessboard_process_chessboard_notation($item, $settings);
+        $items = array($item);
+        $element[$delta] = _chessboard_filter_formatter_view($items);

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.

+/**
+ * Implements hook_field_is_empty().
+ */
+function chessboard_field_is_empty($item, $field) {
+  return empty($item['fen']);
+}

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.

+  // Parse the board.
+  $rows = explode('/', $field[0]);
+  if (count($rows) != 8) {
+    return FALSE;
+  }
+  $rows = array_reverse($rows);

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.

kenneth.venken’s picture

#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.

Status: Needs review » Needs work

The last submitted patch, devel_themer-accessible-design-1711392-7.patch, failed testing.

kenneth.venken’s picture

Status: Needs work » Needs review
StatusFileSize
new4.65 KB

Ignore previous patch...
This is the correct one.

Status: Needs review » Needs work

The last submitted patch, chessboard-add-a-chessboard-field-1402020-7.patch, failed testing.

kenneth.venken’s picture

Patch 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.

eric_a’s picture

Assigned: eric_a » Unassigned

Alright, 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:

  • just the piece placement
  • just a standard 8x8 board (\Drupal\chessboard\PiecePlacement is in now.)
  • a char(64) for storage
  • an implementation of hook_field_load() for (cached) processing of the loaded value
  • Let's not use _chessboard_filter_process_chessboard_notation() here. Instead we can inline the few lines that we need from that function body.

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.)

eric_a’s picture

One 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.

eric_a’s picture

an implementation of hook_field_load() for (cached) processing of the loaded value

My 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.

a char(64) for storage

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?

eric_a’s picture

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?

Hm, 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.

eric_a’s picture

Status: Needs work » Needs review
StatusFileSize
new3.39 KB

Re-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.)

eric_a’s picture

Implemented most of the changes mentioned earlier. Right now the widget only understands the '-'-syntax for empty squares.

eric_a’s picture

Moved the code to chessboard.field.inc.

eric_a’s picture

StatusFileSize
new3.96 KB
new324 bytes

Now with include file loading.

Status: Needs review » Needs work

The last submitted patch, chessboard-add-a-chessboard-field-1402020-19.patch, failed testing.

eric_a’s picture

Status: Needs work » Needs review
StatusFileSize
new3.96 KB
new386 bytes
eric_a’s picture

eric_a’s picture

eric_a’s picture

eric_a’s picture

Issue summary: View changes
StatusFileSize
new3.07 KB
new3.92 KB

EDIT: uploaded the wrong patch with the correct interdiff... (Regarding chessboard_field_schema().)
We're not storing FEN, so changed the patch to reflect this.

eric_a’s picture

StatusFileSize
new1.08 KB
new3.5 KB

The default formatter is now the simple and direct piece placement format. E.g., rnbqkbnrpppppppp--------------------------------PPPPPPPPRNBQKBNR is formatted as

rnbqkbnr
pppppppp
--------
--------
--------
--------
PPPPPPPP
RNBQKBNR
eric_a’s picture

StatusFileSize
new598 bytes
new3.5 KB

With pre element tags we don't want nl2br()...

eric_a’s picture

StatusFileSize
new930 bytes
new3.32 KB

A little cleaning up.

eric_a’s picture

StatusFileSize
new2.37 KB
new3.32 KB

Renamed widget and formatter to chessboard_default/ chessboard_simple plus some minor changes.

eric_a’s picture

Version: 7.x-2.x-dev » 8.x-2.x-dev
StatusFileSize
new4.56 KB

And a D8 patch.

eric_a’s picture

StatusFileSize
new1.48 KB
new4.55 KB
eric_a’s picture

StatusFileSize
new725 bytes
new4.55 KB
eric_a’s picture

StatusFileSize
new764 bytes
new4.57 KB
eric_a’s picture

StatusFileSize
new1010 bytes
new4.79 KB

Added Regex constraint. Changed Length constraint.

eric_a’s picture

StatusFileSize
new1.68 KB
new5.69 KB

Core does not expose the Symfony Regex constraint (yet)...

eric_a’s picture

StatusFileSize
new586 bytes
new5.86 KB

Implemented isEmpty().

eric_a’s picture

Version: 8.x-2.x-dev » 7.x-2.x-dev
StatusFileSize
new1.52 KB
new4.22 KB

Pushed #36 to 8.x-2.x. Moving to 7.x-2.x.

eric_a’s picture

StatusFileSize
new473 bytes
new4.12 KB

Removed the index.

eric_a’s picture

Status: Needs review » Fixed

Pushed #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.

Status: Fixed » Closed (fixed)

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