Skip to content

Commit b17bba1

Browse files
authored
Merge pull request #42 from venveo/change/refactor
Beta 4 - Refactor
2 parents 3223a87 + e44e657 commit b17bba1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1753
-1410
lines changed

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Characteristic Changelog
22

3+
## 1.0.0-beta.4 - 2/13/20
4+
## Changed
5+
- Refactored element structures such that we rely more on native Craft relations and Block Elements
6+
- Rewrote frontend field input to be more maintainable
7+
- Drilldown should be more performant
8+
- Now requires Craft 3.4
9+
- Start using Vue Admin Table
10+
- Removed characteristic behavior in favor of field
11+
- Improved characteristic field to work more like Matrix fields
12+
- Changed CharacteristicLink to CharacteristicLinkBlock
13+
- Removed respectStructure from drilldown in favor of always respecting the structure
14+
- Characteristics now support multiple propagation methods
15+
16+
## Fixed
17+
- Various improvements to multi-site support
18+
- Erroneous warning about unsaved changes on edit element screens
19+
- Drilldown now respects existing query parameters and paths
20+
321
## 1.0.0-beta.3 - 1/31/20
422
## Fixed
523
- Fixed error when saving drafts

README.md

+20-43
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,41 @@ you to quickly create a "Quiz" to find the most suitable element.
5353

5454
## Requirements
5555

56-
This plugin requires Craft CMS 3.3.0 or later.
56+
This plugin requires Craft CMS 3.4.0 or later.
5757

5858
## Using Characteristic
5959

6060
### The Drilldown Helper
6161
```twig
62+
{# Any arbitrary base element query #}
6263
{% set query = craft.entries.section('restaurants') %}
63-
{% set drilldown = craft.characteristic.drilldown('restaurants', query) %}
64+
65+
{# Create an instance of the drilldown helper for the characteristic group with the handle `restaurantCharacteristics` #}
66+
{% set drilldown = craft.characteristic.drilldown('restaurantCharacteristics', query) %}
6467
6568
{% set state = drilldown.state %}
6669
6770
{% set current = drilldown.currentCharacteristic %}
6871
72+
{# Get a text field called characteristicDescription off of the characteristic #}
6973
<h2>{{ current.characteristicDescription }}</h2>
7074
75+
{# Get all of the options available for the current characteristic #}
7176
{% set options = drilldown.currentOptions.all() %}
7277
7378
<ul>
7479
{% for option in options %}
80+
{# Use the applyToDrilldownState method to create a URL for this value based on the current state #}
7581
<li><a href="{{ option.applyToDrilldownState(state).url }}">{{ option.value }}</a></li>
82+
83+
{# Grab a featuredImage Asset field off of the option #}
7684
{% if option.featuredImage.exists() %}
7785
<img src="{{ option.featuredImage.one().url }}" />
7886
{% endif %}
7987
{% endfor %}
8088
<hr>
89+
90+
{# Optional URL to skip the question with picking an answer #}
8191
<a href="{{ drilldown.skipUrl() }}">Skip Question</a>
8292
</ul>
8393
@@ -94,20 +104,9 @@ This plugin requires Craft CMS 3.3.0 or later.
94104
```
95105

96106
### The characteristics field
97-
The field returns a CharacteristicLinkQuery pre-configured for the
107+
The field returns a CharacteristicLinkBlockQuery pre-configured for the
98108
element.
99109

100-
#### Get a single characteristic's value
101-
```twig
102-
<ul>
103-
{# Loop over restaurants showing the selected price Characteristic #}
104-
{% for restaurant in query.all() %}
105-
{% set price = restaurant.restaurantAttributes.characteristic('price').with(['value']).all() %}
106-
<li>{{ restaurant.title }} - {{ price ? price[0].value.value : 'No Data' }}</li>
107-
{% endfor %}
108-
</ul>
109-
```
110-
111110
#### Get all characteristics on an entry and show them as a table
112111
```twig
113112
<table class="table-auto">
@@ -118,41 +117,19 @@ element.
118117
</tr>
119118
</thead>
120119
<tbody>
121-
{# We have to group our characteristics by something (title), otherwise they will show a distinct table rows #}
122-
{% set attributes = entry.restaurantAttributes.all()|group(v => v.characteristic.title) %}
123-
{% for title, values in attributes %}
120+
121+
{% set blocks = entry.restaurantAttributes.all() %}
122+
{% for block in blocks %}
124123
<tr>
125-
<td class="border px-4 py-2">{{ title }}</td>
124+
<td class="border px-4 py-2">{{ block.characteristic.title }}</td>
126125
{# We're going to create a string out of the characteristic value's text value #}
127-
<td class="border px-4 py-2">{{ values|column('value.value')|join(', ') }}</td>
126+
<td class="border px-4 py-2">{{ block.values.all()|column('value')|join(', ') }}</td>
128127
</tr>
129128
{% endfor %}
130129
</tbody>
131130
</table>
132131
```
133132

134-
### The characteristic attribute
135-
Characteristic will inject some attributes into your elements to make
136-
querying characteristics easier! Take care to ensure you don't have any
137-
fields with the same handles as these.
138-
139-
- `characteristics` returns a CharacteristicQuery configured to return
140-
only those related to the source element.
141-
142-
```twig
143-
<ul>
144-
{% for product in craft.entries.section('products').all() %}
145-
<li>{{product.title}}</li>
146-
<ul>
147-
{% for characteristic in product.characteristics.all() %}
148-
{# We could use .values() without a parameter if we wanted to get all possible values indiscriminately #}
149-
<li>{{ characteristic.title }} - {{ characteristic.values(restaurant).all()|column('value')|join(', ') }}</li>
150-
{% endfor %}
151-
</ul>
152-
{% endfor %}
153-
</ul>
154-
```
155-
156133
### Querying for elements
157134
There are a few different ways to query for elements with certain characteristics.
158135

@@ -182,9 +159,9 @@ Characteristic Value is relative to a specific Characteristic. A
182159
Characteristic Value has a `value` attribute that is a text string that
183160
is unique to each Characteristic. For example: "Yes", "No", "1.25".
184161

185-
#### Characteristic Link
162+
#### Characteristic Link Block
186163
An Element that contains the linkage between a particular
187-
Characteristic, a Characteristic Value, the field it was created from,
164+
Characteristic, a number of Characteristic Values, the field it was created from,
188165
as well as the element its attached to.
189166

190167
#### Characteristic Field

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "venveo/craft-characteristic",
33
"description": "Drill-drown on element characteristics",
44
"type": "craft-plugin",
5-
"version": "1.0.0-beta.3",
5+
"version": "1.0.0-beta.4",
66
"keywords": [
77
"craft",
88
"cms",

src/Characteristic.php

+5-12
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
namespace venveo\characteristic;
1212

1313
use Craft;
14-
use craft\base\Element;
1514
use craft\base\Plugin;
16-
use craft\events\DefineBehaviorsEvent;
1715
use craft\events\RegisterComponentTypesEvent;
1816
use craft\events\RegisterCpSettingsEvent;
1917
use craft\events\RegisterUrlRulesEvent;
@@ -23,12 +21,12 @@
2321
use craft\web\twig\variables\Cp;
2422
use craft\web\twig\variables\CraftVariable;
2523
use craft\web\UrlManager;
26-
use venveo\characteristic\behaviors\ElementCharacteristicsBehavior;
2724
use venveo\characteristic\elements\Characteristic as CharacteristicElement;
25+
use venveo\characteristic\elements\CharacteristicLinkBlock as CharacteristicLinkBlockElement;
2826
use venveo\characteristic\elements\CharacteristicValue as CharacteristicValueElement;
2927
use venveo\characteristic\fields\Characteristics as CharacteristicsField;
3028
use venveo\characteristic\services\CharacteristicGroups;
31-
use venveo\characteristic\services\CharacteristicLinks;
29+
use venveo\characteristic\services\CharacteristicLinkBlocks;
3230
use venveo\characteristic\services\Characteristics;
3331
use venveo\characteristic\services\CharacteristicValues;
3432
use venveo\characteristic\variables\CharacteristicVariable;
@@ -44,7 +42,7 @@
4442
* @property CharacteristicGroups $characteristicGroups
4543
* @property Characteristics $characteristics
4644
* @property CharacteristicValues $characteristicValues
47-
* @property CharacteristicLinks $characteristicLinks
45+
* @property CharacteristicLinkBlocks $characteristicLinkBlocks
4846
*/
4947
class Characteristic extends Plugin
5048
{
@@ -81,7 +79,7 @@ public function init()
8179
'characteristicGroups' => CharacteristicGroups::class,
8280
'characteristics' => Characteristics::class,
8381
'characteristicValues' => CharacteristicValues::class,
84-
'characteristicLinks' => CharacteristicLinks::class,
82+
'characteristicLinkBlocks' => CharacteristicLinkBlocks::class,
8583
]);
8684

8785
Event::on(
@@ -114,14 +112,11 @@ function (RegisterUrlRulesEvent $event) {
114112
Elements::EVENT_REGISTER_ELEMENT_TYPES,
115113
function (RegisterComponentTypesEvent $event) {
116114
$event->types[] = CharacteristicElement::class;
115+
$event->types[] = CharacteristicLinkBlockElement::class;
117116
$event->types[] = CharacteristicValueElement::class;
118117
}
119118
);
120119

121-
Event::on(Element::class, Element::EVENT_DEFINE_BEHAVIORS, function (DefineBehaviorsEvent $e) {
122-
$e->behaviors[] = ElementCharacteristicsBehavior::class;
123-
});
124-
125120
Event::on(
126121
Fields::class,
127122
Fields::EVENT_REGISTER_FIELD_TYPES,
@@ -163,6 +158,4 @@ public function getCpNavItem()
163158
}
164159
return null;
165160
}
166-
// Protected Methods
167-
// =========================================================================
168161
}

src/assetbundles/characteristicsfield/dist/css/app.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)