diff --git a/src/actions/GetComponentType.php b/src/actions/GetComponentType.php
index c1c77be..d729f7d 100644
--- a/src/actions/GetComponentType.php
+++ b/src/actions/GetComponentType.php
@@ -53,7 +53,7 @@ public function byType(string $type): ComponentType
$fqcn = $className;
}
- if ($fqcn) {
+ if (! empty($fqcn)) {
return Craft::$container->get($fqcn, ['context' => $this->context]);
}
diff --git a/src/listeners/RegisterDefaultComponentTypes.php b/src/listeners/RegisterDefaultComponentTypes.php
index 60a4ca1..ed4245f 100644
--- a/src/listeners/RegisterDefaultComponentTypes.php
+++ b/src/listeners/RegisterDefaultComponentTypes.php
@@ -9,8 +9,8 @@ class RegisterDefaultComponentTypes
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/entryquery', 'cp:keystone/components/entryquery.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');
diff --git a/src/templates/asset/embed.twig b/src/templates/asset/embed.twig
new file mode 100644
index 0000000..90700f5
--- /dev/null
+++ b/src/templates/asset/embed.twig
@@ -0,0 +1,3 @@
+{% if asset|default(false) %}
+
+{% endif %}
diff --git a/src/templates/components/asset.twig b/src/templates/components/asset.twig
index 28218af..d0cde03 100644
--- a/src/templates/components/asset.twig
+++ b/src/templates/components/asset.twig
@@ -9,6 +9,9 @@
} %}
{% export summary = props.asset.one().title|default %}
{% export category = "Data" %}
+{% set slot = component.getType.defineSlot().defaults([{type: 'keystone/template', data: {template: 'cp:keystone/asset/embed'}}]) %}
{% for asset in props.asset %}
-
+ {% do component.mergeContext({asset: asset, transform: props.transform.value|default(null)}) %}
+ {{ slot }}
+ {% do component.mergeContext({asset: null, transform: null}) %}
{% endfor %}
diff --git a/src/templates/components/entry.twig b/src/templates/components/entry.twig
index 58d367a..2ebec90 100644
--- a/src/templates/components/entry.twig
+++ b/src/templates/components/entry.twig
@@ -5,7 +5,7 @@
} %}
{% export summary = props.entry.one().title|default %}
{% export category = "Data" %}
-{% set slot = component.getType().defineSlot() %}
+{% set slot = component.getType().defineSlot().defaults([{type: 'keystone/template', data: {template: 'cp:keystone/entry/link'}}]) %}
{% for entry in props.entry %}
{% do component.mergeContext({entry: entry}) %}
{{ slot }}
diff --git a/src/templates/components/elementquery.twig b/src/templates/components/entryquery.twig
similarity index 80%
rename from src/templates/components/elementquery.twig
rename to src/templates/components/entryquery.twig
index fb42762..f4d13f6 100644
--- a/src/templates/components/elementquery.twig
+++ b/src/templates/components/entryquery.twig
@@ -1,12 +1,12 @@
{% export category = "Data" %}
-{% export name = "Element Query" %}
+{% export name = "Entry Query" %}
{% export icon %}{% endexport %}
{% export propTypes = {
search: field('\\markhuot\\keystone\\fields\\Condition'),
limit: field('\\craft\\fields\\Number'),
} %}
{% set defaultSlot = component.getType().defineSlot() %}
-{% set elements = props.search.limit(props.limit|default(100)).all()|default([]) %}
+{% set elements = props.search.all()|default([]) %}
{% for element in elements %}
- {{ defaultSlot.render({element: element}) }}
+ {{ defaultSlot.render({entry: element}) }}
{% endfor %}
diff --git a/src/templates/components/template.twig b/src/templates/components/template.twig
index d65e068..b84c19f 100644
--- a/src/templates/components/template.twig
+++ b/src/templates/components/template.twig
@@ -1,3 +1,4 @@
+{% export summary = props.template %}
{% if props.template %}
{% set parts = props.template|split(':') %}
{% if parts|length == 2 %}
diff --git a/src/templates/entry/link.twig b/src/templates/entry/link.twig
index 5601d97..ad52a09 100644
--- a/src/templates/entry/link.twig
+++ b/src/templates/entry/link.twig
@@ -1 +1,3 @@
-{{ entry.title }}
+{% if entry|default(false) %}
+ {{ entry.title }}
+{% endif %}
diff --git a/tests/RouteTest.php b/tests/RouteTest.php
index f7d6153..309fe1e 100644
--- a/tests/RouteTest.php
+++ b/tests/RouteTest.php
@@ -23,11 +23,12 @@
$this->actingAsAdmin()
->get(UrlHelper::cpUrl('keystone/components/edit', $component->getQueryCondition()))
->assertOk();
-})->with([
- 'keystone/asset', 'keystone/elementquery', 'keystone/fragment',
- 'keystone/icon', 'keystone/link', 'keystone/heading',
- 'keystone/section', 'keystone/text',
-]);
+})->with(collect(scandir(__DIR__.'/../src/templates/components'))
+ ->filter(fn ($file) => ! str_starts_with($file, '.'))
+ ->filter(fn ($file) => str_ends_with($file, '.twig'))
+ ->map(fn ($file) => 'keystone/'.preg_replace('/\.twig$/', '', $file))
+ ->all()
+);
it('stores a component', function () {
$component = Component::factory()
diff --git a/tests/components/ElementQueryTest.php b/tests/components/EntryQueryTest.php
similarity index 72%
rename from tests/components/ElementQueryTest.php
rename to tests/components/EntryQueryTest.php
index 2a7182c..24b7f65 100644
--- a/tests/components/ElementQueryTest.php
+++ b/tests/components/EntryQueryTest.php
@@ -5,9 +5,9 @@
it('renders element queries', function () {
$entry = Entry::factory()->title('foobarbaz')->create();
- $component = Component::factory()->type('keystone/elementquery')->create();
+ $component = Component::factory()->type('keystone/entryquery')->create();
$test = Component::factory()->type('keystone/text')->path($component->id)->create();
- $test->data->merge(['text' => '{element.title}'])->save();
+ $test->data->merge(['text' => '{entry.title}'])->save();
$response = $component->render();
expect($response)->toContain('foobarbaz');
});