Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v3 - Add Twigfield integration for fields that render as object temp… #12120

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"league/flysystem": "^1.1.4",
"league/oauth2-client": "^2.6.0",
"mikehaertl/php-shellcommand": "^1.6.3",
"nystudio107/craft-twigfield": "^1.0.13",
"pixelandtonic/imagine": "~1.2.4.1",
"seld/cli-prompt": "^1.0.4",
"symfony/yaml": "^5.2.1",
Expand Down
12 changes: 11 additions & 1 deletion src/templates/_components/fieldtypes/Assets/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

{% import "_includes/forms" as forms %}

{% import "twigfield/twigfield" as twigfield %}

{% set fileKindOptions = field.getFileKindOptions() %}
{% set isMatrix = 'craft\\fields\\Matrix' in craft.app.view.getNamespace() %}

{% macro uploadLocationField(config) %}
{% embed '_includes/forms/field' with config %}
{% import "twigfield/twigfield" as twigfield %}
{% block input %}
{% import '_includes/forms' as forms %}
<div class="flex">
Expand All @@ -19,12 +22,17 @@
}) }}
</div>
<div class="flex-grow">
{{ forms.text({
{{ twigfield.text({
id: config.id,
class: 'ltr',
name: "#{config.name}Subpath",
value: config.subpathValue,
placeholder: "path/to/subfolder"|t('app'),
describedBy: describedBy,
}, "Twigfield", "monaco-editor-background-frame", {
'fontSize': 13,
}, {
'SectionShorthandFields': 0,
}) }}
</div>
</div>
Expand Down Expand Up @@ -57,6 +65,7 @@
{{ block('sourcesField') }}

{{ _self.uploadLocationField({
id: 'defaultUploadLocation',
label: 'Default Asset Location'|t('app'),
instructions: 'Where assets should be stored when they are uploaded directly to the field, or via a front-end form.'|t('app') ~' '~ uploadLocationNote,
name: 'defaultUploadLocation',
Expand All @@ -69,6 +78,7 @@

<div id="single-folder-settings"{% if not field.useSingleFolder %} class="hidden"{% endif %}>
{{ _self.uploadLocationField({
id: 'singleUploadLocation',
label: 'Asset Location'|t('app'),
instructions: 'Where selected assets should be stored.'|t('app') ~' '~ uploadLocationNote,
name: 'singleUploadLocation',
Expand Down
18 changes: 17 additions & 1 deletion src/templates/_includes/forms/editableTable.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
{{ hiddenInput(name, '') }}
{% endif %}

{% import "twigfield/twigfield" as twigfield %}

{% macro cellClass(fullWidth, col, class) %}
{{- (class is iterable ? class : [class])|merge([
"#{col.type}-cell",
Expand Down Expand Up @@ -92,7 +94,7 @@
{% set headingId = "#{id}-heading-#{loop.index}" %}
{% set hasErrors = cell.hasErrors ?? false %}
{% set cellName = name~'['~rowId~']['~colId~']' %}
{% set isCode = (col.code ?? false) or col.type == 'color' %}
{% set isCode = ((col.code ?? false) or col.type == 'color') and not col.type == 'twigfield' %}
<td class="{{ _self.cellClass(fullWidth, col, col.class ?? []) }} {% if isCode %}code{% endif %} {% if hasErrors %}error{% endif %}"{% if col.width ?? false %} width="{{ col.width }}"{% endif %}>
{% block tablecell %}
{%- switch col.type -%}
Expand Down Expand Up @@ -173,6 +175,20 @@
labelledBy: headingId,
describedBy: describedBy,
} only %}
{%- case 'twigfield' -%}
{% set fieldId = "#{id}-twigfield-#{rowNumber}-#{loop.index}" %}
{{ twigfield.text({
id: fieldId,
name: "{{ cellName }}",
value: value,
labelledBy: headingId,
describedBy: describedBy,
placeholder: col.placeholder ?? '',
}, "Twigfield", "monaco-editor-inline-frame", {
'fontSize': 13,
}, {
'SectionShorthandFields': section.id,
}) }}
{%- default -%}
{% if static %}
<pre class="disabled">{{ value }}</pre>
Expand Down
12 changes: 7 additions & 5 deletions src/templates/settings/sections/_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@
value: (section.type == 'single' and siteSettings and siteSettings.uriFormat == '__home__')
},
singleUri: {
value: (section.type == 'single' and siteSettings and siteSettings.uriFormat != '__home__') ? siteSettings.uriFormat,
hasErrors: (section.type == 'single' and siteSettings ? siteSettings.hasErrors('uriFormat'))
value: (section.type == 'single' and siteSettings and siteSettings.uriFormat != '__home__') ? siteSettings.uriFormat,
hasErrors: (section.type == 'single' and siteSettings ? siteSettings.hasErrors('uriFormat'))
},
uriFormat: {
value: siteSettings ? siteSettings.uriFormat,
Expand Down Expand Up @@ -151,19 +151,20 @@
class: ['single-uri', 'type-single', section.type != 'single' ? 'hidden']|filter
},
uriFormat: {
type: 'singleline',
type: 'twigfield',
heading: "Entry URI Format"|t('app'),
info: "What entry URIs should look like for the site. Leave blank if entries don’t have URLs."|t('app'),
placeholder: 'Leave blank if entries don’t have URLs'|t('app'),
code: true,
width: headlessMode ? 500,
width: headlessMode ? 500 : '40%',
class: ['type-channel', 'type-structure', section.type == 'single' ? ' hidden']|filter
},
template: not headlessMode ? {
type: 'template',
heading: "Template"|t('app'),
info: "Which template should be loaded when an entry’s URL is requested."|t('app'),
code: true
code: true,
width: '40%',
},
enabledByDefault: {
type: 'lightswitch',
Expand All @@ -175,6 +176,7 @@
rows: siteRows,
fullWidth: true,
staticRows: true,
section: section,
errors: siteErrors|unique
}) }}

Expand Down
7 changes: 6 additions & 1 deletion src/templates/settings/sections/_entrytypes/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

{% import "_includes/forms" as forms %}

{% import "twigfield/twigfield" as twigfield %}

{% block content %}
{{ actionInput('sections/save-entry-type') }}
Expand Down Expand Up @@ -99,7 +100,7 @@
{% endif %}

<div id="titleFormat-container"{% if entryType.hasTitleField %} class="hidden"{% endif %}>
{{ forms.textField({
{{ twigfield.textField({
label: "Title Format"|t('app'),
instructions: "What the auto-generated entry titles should look like. You can include tags that output entry properties, such as {ex}."|t('app', { ex: '<code>{myCustomField}</code>' }),
id: 'titleFormat',
Expand All @@ -108,6 +109,10 @@
value: entryType.titleFormat,
errors: entryType.getErrors('titleFormat'),
required: true
}, "Twigfield", "monaco-editor-background-frame", {
'fontSize': 13,
}, {
'SectionShorthandFields': section.id,
}) }}
</div>

Expand Down