Skip to content

Commit 12cf23f

Browse files
committed
version 0.4.7
1 parent 7269eb0 commit 12cf23f

9 files changed

+130
-20
lines changed

changelog.json

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
[
2+
{
3+
"version": "0.4.7",
4+
"downloadUrl": "https://github.com/engram-design/SuperTable/archive/0.4.7.zip",
5+
"date": "2016-07-10T13:00:00+10:00",
6+
"notes": [
7+
"[Added] Added support for eager loading.",
8+
"[Added] Added `blocks()` template tag for Super Table block elements.",
9+
"[Improved] Column layout width now allows either px or % values. Defaults to % if unit-less.",
10+
"[Fixed] Fix for certain fields not settings content properly from draft.",
11+
"[Fixed] Fixed column layout not applying width correctly."
12+
]
13+
},
214
{
315
"version": "0.4.6",
416
"downloadUrl": "https://github.com/engram-design/SuperTable/archive/0.4.6.zip",

supertable/SuperTablePlugin.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public function getName()
1414

1515
public function getVersion()
1616
{
17-
return '0.4.6';
17+
return '0.4.7';
1818
}
1919

2020
public function getSchemaVersion()

supertable/elementtypes/SuperTable_BlockElementType.php

+23
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,27 @@ public function populateElementModel($row)
108108
{
109109
return SuperTable_BlockModel::populateModel($row);
110110
}
111+
112+
public function getEagerLoadingMap($sourceElements, $handle)
113+
{
114+
$superTableFieldId = $sourceElements[0]->fieldId;
115+
$blockTypes = craft()->superTable->getBlockTypesByFieldId($superTableFieldId);
116+
117+
if (!isset($blockTypes[0])) {
118+
return false;
119+
}
120+
121+
$blockType = $blockTypes[0];
122+
123+
// Set the field context
124+
$contentService = craft()->content;
125+
$originalFieldContext = $contentService->fieldContext;
126+
$contentService->fieldContext = 'superTableBlockType:' . $blockType->id;
127+
128+
$map = parent::getEagerLoadingMap($sourceElements, $handle);
129+
130+
$contentService->fieldContext = $originalFieldContext;
131+
132+
return $map;
133+
}
111134
}

supertable/fieldtypes/SuperTableFieldType.php

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace Craft;
33

4-
class SuperTableFieldType extends BaseFieldType
4+
class SuperTableFieldType extends BaseFieldType implements IEagerLoadingFieldType
55
{
66
// Public Methods
77
// =========================================================================
@@ -396,6 +396,34 @@ public function onAfterElementSave()
396396
craft()->superTable->saveField($this);
397397
}
398398

399+
public function getEagerLoadingMap($sourceElements)
400+
{
401+
// Get the source element IDs
402+
$sourceElementIds = array();
403+
404+
foreach ($sourceElements as $sourceElement) {
405+
$sourceElementIds[] = $sourceElement->id;
406+
}
407+
408+
// Return any relation data on these elements, defined with this field
409+
$map = craft()->db->createCommand()
410+
->select('ownerId as source, id as target')
411+
->from('supertableblocks')
412+
->where(
413+
array('and', 'fieldId=:fieldId', array('in', 'ownerId', $sourceElementIds)),
414+
array(':fieldId' => $this->model->id)
415+
)
416+
->order('sortOrder')
417+
->queryAll();
418+
419+
return array(
420+
'elementType' => 'SuperTable_Block',
421+
'map' => $map,
422+
'criteria' => array('fieldId' => $this->model->id)
423+
);
424+
}
425+
426+
399427
// Protected Methods
400428
// =========================================================================
401429

@@ -414,6 +442,7 @@ protected function getSettingsModel()
414442
return $settings;
415443
}
416444

445+
417446
// Private Methods
418447
// =========================================================================
419448

supertable/models/SuperTable_BlockModel.php

+36
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class SuperTable_BlockModel extends BaseElementModel
88

99
protected $elementType = 'SuperTable_Block';
1010
private $_owner;
11+
private $_eagerLoadedBlockTypeElements;
1112

1213
// Public Methods
1314
// =========================================================================
@@ -92,6 +93,40 @@ public function getFieldContext()
9293
return 'superTableBlockType:'.$this->typeId;
9394
}
9495

96+
public function hasEagerLoadedElements($handle)
97+
{
98+
if (isset($this->_eagerLoadedBlockTypeElements[$handle])) {
99+
return true;
100+
}
101+
102+
return parent::hasEagerLoadedElements($handle);
103+
}
104+
105+
public function getEagerLoadedElements($handle)
106+
{
107+
if (isset($this->_eagerLoadedBlockTypeElements[$handle])) {
108+
return $this->_eagerLoadedBlockTypeElements[$handle];
109+
}
110+
111+
return parent::getEagerLoadedElements($handle);
112+
}
113+
114+
public function setEagerLoadedElements($handle, $elements)
115+
{
116+
$this->_eagerLoadedBlockTypeElements[$handle] = $elements;
117+
118+
parent::setEagerLoadedElements($handle, $elements);
119+
}
120+
121+
public function getHasFreshContent()
122+
{
123+
// Defer to the owner element
124+
$owner = $this->getOwner();
125+
126+
return $owner ? $owner->getHasFreshContent() : false;
127+
}
128+
129+
95130
// Protected Methods
96131
// =========================================================================
97132

@@ -106,6 +141,7 @@ protected function defineAttributes()
106141
));
107142
}
108143

144+
109145
// Private Methods
110146
// =========================================================================
111147

supertable/resources/css/SuperTableInput.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ body.ltr table.editable.superTable tbody tr td:nth-child(2) {
4646
}
4747

4848
.superTableColumn table.editable.superTable th.col-header {
49-
width: 100%;
49+
/*width: 100%;*/
5050
}
5151

5252
.superTableColumn table.editable.superTable th.col-header[colspan="2"] {
53-
width: 48px;
53+
width: 29px;
5454
}
5555

5656
.superTableColumn table.editable.superTable tbody tr td.action + td.action {

supertable/templates/fields.html

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
11
{% if element is not defined %}{% set element = null %}{% endif %}
22
{% if namespace is not defined %}{% set namespace = 'fields' %}{% endif %}
33

4-
{% set columnSettings = [] %}
5-
{% if settings is defined and settings %}
6-
{% for col in settings.columns %}
7-
{% set columnSettings = columnSettings | merge([col]) %}
8-
{% endfor %}
9-
{% endif %}
10-
114
{% namespace namespace %}
125
{% for index, field in fields %}
13-
14-
{# Additional field settings #}
15-
{% if columnSettings[index] is defined %}
16-
{% set width = columnSettings[index].width %}
17-
{% endif %}
18-
196
{% if settings is defined and settings.fieldLayout == 'row' %}
207

218
<tr data-id="">
@@ -40,7 +27,7 @@
4027
</tr>
4128

4229
{% else %}
43-
<td {% if width is defined and width %}style="width: {{ width }}px"{% endif %}>
30+
<td>
4431
{% include "supertable/field" with {
4532
field: field.getField(),
4633
required: field.required,

supertable/templates/tableInput.html

+20-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,33 @@
44

55
<input type="hidden" name="{{ name }}" value="">
66

7+
{% set columnSettings = [] %}
8+
{% if settings is defined and settings %}
9+
{% for col in settings.columns %}
10+
{% set columnSettings = columnSettings | merge([col]) %}
11+
{% endfor %}
12+
{% endif %}
13+
714
<div class="superTableContainer columnLayout">
815
<div class="superTableColumn">
916
<table id="{{ id }}" class="shadow-box editable superTable">
1017
<thead>
1118
<tr>
1219
<th class="hidden"></th>
20+
1321
{% if table %}
14-
{% for field in table.getFields() %}
15-
<th scope="col" class="col-header">
22+
{% for index, field in table.getFields() %}
23+
{% if columnSettings[index] is defined %}
24+
{% set width = columnSettings[index].width %}
25+
26+
{% if width %}
27+
{% if 'px' not in width and '%' not in width %}
28+
{% set width = width ~ '%' %}
29+
{% endif %}
30+
{% endif %}
31+
{% endif %}
32+
33+
<th scope="col" class="col-header" {% if width is defined and width %}style="width: {{ width }}"{% endif %}>
1634
<span class="heading-text {% if field.required %}required{% endif %}">{{ field.name }}</span>
1735
</th>
1836
{% endfor %}

supertable/variables/SuperTableVariable.php

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
class SuperTableVariable
55
{
6+
public function blocks($criteria)
7+
{
8+
return craft()->elements->getCriteria('SuperTable_Block', $criteria);
9+
}
10+
611
/**
712
* Expands the defualt relationship behaviour to include Super Table
813
* fields so that the user can filter by those too.

0 commit comments

Comments
 (0)