Skip to content

Commit

Permalink
entry components!
Browse files Browse the repository at this point in the history
  • Loading branch information
markhuot committed Nov 18, 2023
1 parent 3393d8e commit f09b623
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/controllers/ComponentsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function actionAdd()
'path' => $data->path,
'slot' => $data->slot,
'parent' => $parent,
'groups' => (new GetComponentType())->all()->groupBy(fn ($t) => $t->getCategory()),
'groups' => (new GetComponentType())->all()->groupBy(fn ($t) => $t->getCategory())->sortKeys(),
'sortOrder' => $data->sortOrder,
]);
}
Expand Down
1 change: 1 addition & 0 deletions src/listeners/RegisterDefaultComponentTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public function handle(RegisterComponentTypes $event): void
{
$event->registerTwigTemplate('keystone/asset', 'cp:keystone/components/asset.twig');
$event->registerTwigTemplate('keystone/elementquery', 'cp:keystone/components/elementquery.twig');
$event->registerTwigTemplate('keystone/entry', 'cp:keystone/components/entry.twig');
$event->registerTwigTemplate('keystone/fragment', 'cp:keystone/components/fragment.twig');
$event->registerTwigTemplate('keystone/heading', 'cp:keystone/components/heading.twig');
$event->registerTwigTemplate('keystone/icon', 'cp:keystone/components/icon.twig');
Expand Down
1 change: 1 addition & 0 deletions src/templates/components/asset.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
}))),
} %}
{% export summary = props.asset.one().title|default %}
{% export category = "Data" %}
{% for asset in props.asset %}
<img {{ attributes}} src="{{asset.getUrl(props.transform.value|default(null))|default }}">
{% endfor %}
21 changes: 21 additions & 0 deletions src/templates/components/entry.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{% export icon %}<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><path d="M213.66,82.34l-56-56A8,8,0,0,0,152,24H56A16,16,0,0,0,40,40V216a16,16,0,0,0,16,16H200a16,16,0,0,0,16-16V88A8,8,0,0,0,213.66,82.34ZM160,51.31,188.69,80H160ZM200,216H56V40h88V88a8,8,0,0,0,8,8h48V216Zm-32-80a8,8,0,0,1-8,8H96a8,8,0,0,1,0-16h64A8,8,0,0,1,168,136Zm0,32a8,8,0,0,1-8,8H96a8,8,0,0,1,0-16h64A8,8,0,0,1,168,168Z"></path></svg>{% endexport %}
{# it would be nice to set `template` to a `craft\fields\Dropdown` but that causes the edit entry page to not render and redirect to the homepage without any errors #}
{% export propTypes = {
entry: field('craft\\fields\\Entries'),
template: field('craft\\fields\\Dropdown').options([
{label: 'Default', value: '' },
{label: 'Link', value: 'keystone/entry/link'},
]),
} %}
{% export summary = props.entry.one().title|default %}
{% export category = "Data" %}
{% set slot = component.getType().defineSlot() %}
{% for entry in props.entry %}
{% if props.template.value %}
{% include props.template.value with {entry: entry} only %}
{% else %}
{% do component.mergeContext({entry: entry}) %}
{{ slot }}
{% do component.mergeContext({entry: null}) %}
{% endif %}
{% endfor %}
1 change: 1 addition & 0 deletions src/templates/entry/link.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="{{ entry.uri }}">{{ entry.title }}</a>
2 changes: 1 addition & 1 deletion src/templates/field.twig
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<a class="k-text-link" href="{{ cpUrl('keystone/components/edit', params) }}" data-open-keystone-component-editor='{{ params|json_encode }}'>
<div style="background: white; display: inline-block; position: relative; padding: 4px;">{{ child.getType().getIcon({class: 'k-w-4 k-inline'})|raw }}</div>
{{ child.getType().getName() }}
<span class="k-text-gray-400 [.k-collapsed_&]:k-hidden">{{ child.getSummary() }}</span>
<span class="k-text-gray-400">{{ child.getSummary() }}</span>
</a>
<a class="k-expander k-hidden k-ml-1 [.k-collapsed_&]:k-inline-flex k-bg-gray-200 k-rounded k-w-5 k-h-3 k-text-gray-800 k-justify-center k-items-center hover:k-no-underline hover:k-bg-blue-500 hover:k-text-white" href="#" @click="$event.target.closest('li').classList.toggle('k-collapsed')">⋯</a>
{{ hiddenInput('nodes[]', child.id ~ '@' ~ child.dateUpdated) }}
Expand Down

0 comments on commit f09b623

Please sign in to comment.