Skip to content

Commit

Permalink
Autosuggest templates
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Dec 10, 2024
1 parent ce3a3a5 commit d08b8ed
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- The Queue Manager utility now shows jobs’ class names. ([#16228](https://github.com/craftcms/cms/pull/16228))
- Improved the wording of field instance action labels. ([#16261](https://github.com/craftcms/cms/discussions/16261))
- Templates rendered for “Template” field layout UI elements can now call control panel template functions like `elementChip()` and `elementCard()`. ([#16267](https://github.com/craftcms/cms/issues/16267))
- “Template” field layout UI elements now show suggestions for the Template input.
- Improved the error output for nested elements when they can’t be resaved via `resave` commands.
- `resave` commands’ `--drafts`, `--provisional-drafts`, and `--revisions` options can now be set to `null`, causing elements to be resaved regardless of whether they’re drafts/provisional drafts/revisions.

Expand Down Expand Up @@ -82,8 +83,9 @@
- `craft\services\Revisions::createRevision()` no longer creates the revision if an `EVENT_BEFORE_CREATE_REVISION` event handler sets `$event->handled` to `true` and at least one revision already exists for the element. ([#16260](https://github.com/craftcms/cms/discussions/16260))
- Deprecated `craft\fields\Color::$presets`. ([#16249](https://github.com/craftcms/cms/pull/16249))
- Deprecated `craft\fields\Link::$showTargetField`.
- `_includes/forms/autosuggest.twig` now supports a `suggestTemplates` variable.
- `_includes/forms/colorSelect.twig` now supports `options` and `withBlankOption` variables.
- `_includes/forms/selectize.twig` now supports a `color` property in option data, which can be set to a hex value or a color name.
- `_includes/forms/selectize.twig` now supports a `color` property in option data, which can be set to a hex value or a color name.
- Sortable checkbox selects now always display the selected options first on initial render.

### System
Expand Down
3 changes: 2 additions & 1 deletion src/fieldlayoutelements/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ public function hasSettings()
*/
protected function settingsHtml(): ?string
{
return Cp::textFieldHtml([
return Cp::autosuggestFieldHtml([
'label' => Craft::t('app', 'Template'),
'instructions' => Craft::t('app', 'The path to a template file within your `templates/` folder.'),
'tip' => Craft::t('app', 'The template will be rendered with an `element` variable.'),
'class' => 'code',
'id' => 'template',
'name' => 'template',
'suggestTemplates' => true,
'value' => $this->template,
]);
}
Expand Down
10 changes: 5 additions & 5 deletions src/templates/_includes/forms/autosuggest.twig
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% do view.registerAssetBundle("craft\\web\\assets\\vue\\VueAsset") %}

{% if suggestEnvVars ?? false %}
{% set suggestions = (suggestions ?? [])|merge(craft.cp.getEnvSuggestions(
{% set suggestions = (suggestions ?? [])
|merge((suggestTemplates ?? false) ? craft.cp.getTemplateSuggestions() : [])
|merge((suggestEnvVars ?? false) ? craft.cp.getEnvSuggestions(
suggestAliases ?? false,
suggestionFilter ?? null
)) %}
{% endif %}
) : []) %}

{%- set id = id ?? "autosuggest#{random()}" %}
{%- set containerId = "#{id}-container" %}
Expand Down Expand Up @@ -50,7 +50,7 @@ new Vue({
query: (value ?? '')|lower,
selected: '',
filteredOptions: [],
suggestions: suggestions ?? [],
suggestions,
id: autosuggestId,
inputProps: {
class: class|join(' '),
Expand Down
2 changes: 1 addition & 1 deletion src/templates/_includes/forms/editableTable.twig
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
{%- case 'autosuggest' or 'template' -%}
{% include "_includes/forms/autosuggest" with {
name: cellName,
suggestions: col.type == 'template' ? craft.cp.getTemplateSuggestions() : [],
suggestTemplates: col.type == 'template',
suggestEnvVars: col.suggestEnvVars ?? false,
suggestAliases: col.suggestAliases ?? false,
value: value,
Expand Down
2 changes: 1 addition & 1 deletion src/templates/settings/email/_index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
instructions: "The template Craft CMS will use for HTML emails"|t('app'),
id: 'template',
name: 'template',
suggestions: craft.cp.getTemplateSuggestions(),
suggestTemplates: true,
suggestEnvVars: true,
value: settings.template,
errors: (freshSettings ? null : settings.getErrors('template'))
Expand Down

0 comments on commit d08b8ed

Please sign in to comment.