Skip to content
Snippets Groups Projects
Commit fb6ceb97 authored by Robert Kasza's avatar Robert Kasza Committed by Robert Kasza
Browse files

Issue #3303170 by PCate, kaszarobert: Add integration with JSON Field module

parent bd1b1e01
No related branches found
No related tags found
No related merge requests found
......@@ -47,12 +47,18 @@ if you can find the libraries in the libraries
folder in your web folder.
## Set up module
1. Create a field to whatever content type,
taxonomy term, media, paragraph, etc.
2. When creating field, set type as Table.
3. You can set that if the table value should be
saved to the database as JSON or CSV format.
Choose whatever format.
1. If you already have a native JSON-field using the
contrib json_field module (any of those JSON fields),
then just set the form widgets and display formatters
to Table widget/formatter.
2. If you wish to create a new field for it,
then add a Table field that this module adds to Drupal.
This field will be saved in "longtext" type, not in
native JSON type in the database. To save the table as
JSON/JSOB type, use the fields provided by the
json_field module.
3. If you used the Table field type, you can save the
table data JSON or CSV format.
4. Optionally you can use MarkDown in the table
cell texts, at page `/admin/config/content/blizz_table_field/settings`
you can set help text for using MarkDown syntax.
......
......@@ -19,7 +19,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* id = "table_formatter",
* label = @Translation("Table formatter"),
* field_types = {
* "table"
* "table",
* "json",
* "json_native",
* "json_native_binary"
* }
* )
*/
......@@ -173,16 +176,13 @@ class TableFormatter extends FormatterBase implements ContainerFactoryPluginInte
* The textual output generated.
*/
protected function viewValue(FieldItemInterface $item, $format = 'json') {
switch ($format) {
case 'json':
return $this->tableFromJson($item);
case 'csv':
return $this->tableFromCsv($item);
}
return [];
default:
return $this->tableFromJson($item);
}
}
/**
......
......@@ -18,7 +18,10 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
* id = "table_widget",
* label = @Translation("Table widget"),
* field_types = {
* "table"
* "table",
* "json",
* "json_native",
* "json_native_binary"
* }
* )
*/
......@@ -245,7 +248,16 @@ class TableWidget extends WidgetBase implements ContainerFactoryPluginInterface
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$title = ($element['#title']) ?? $this->t('Table data');
$format = Xss::filter($items->getSetting('format'));
$format = $items->getSetting('format');
// If the format is not set in the field settings, we assume that it is
// a field from the json_field module.
if (empty($format)) {
$format = 'json';
}
else {
$format = Xss::filter($format);
}
$default['json'] = "[\r\n[\r\n\"Column 1\",\r\n\"Column 2\",\r\n\"Column 3\",\r\n\"Column 4\"\r\n],\r\n[\r\n\"\",\r\n\"\",\r\n\"\",\r\n\"\"\r\n],\r\n[\r\n\"\",\r\n\"\",\r\n\"\",\r\n\"\"\r\n],\r\n[\r\n\"\",\r\n\"\",\r\n\"\",\r\n\"\"\r\n],\r\n[\r\n\"\",\r\n\"\",\r\n\"\",\r\n\"\"\r\n ]\r\n]";
$default['csv'] = " Column 1, Column 2, Column 3, Column 4 \r\n,,,\r\n,,,\r\n,,,\r\n,,,";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment