Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blizz_table_field
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
blizz_table_field
Commits
fb6ceb97
Commit
fb6ceb97
authored
1 year ago
by
Robert Kasza
Committed by
Robert Kasza
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3303170
by PCate, kaszarobert: Add integration with JSON Field module
parent
bd1b1e01
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+12
-6
12 additions, 6 deletions
README.md
src/Plugin/Field/FieldFormatter/TableFormatter.php
+7
-7
7 additions, 7 deletions
src/Plugin/Field/FieldFormatter/TableFormatter.php
src/Plugin/Field/FieldWidget/TableWidget.php
+14
-2
14 additions, 2 deletions
src/Plugin/Field/FieldWidget/TableWidget.php
with
33 additions
and
15 deletions
README.md
+
12
−
6
View file @
fb6ceb97
...
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/Field/FieldFormatter/TableFormatter.php
+
7
−
7
View file @
fb6ceb97
...
...
@@ -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
);
}
}
/**
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/Field/FieldWidget/TableWidget.php
+
14
−
2
View file @
fb6ceb97
...
...
@@ -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
,,,"
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment