Skip to content

Commit

Permalink
Show the parent Super Table field in the global settings view.
Browse files Browse the repository at this point in the history
  • Loading branch information
joshangell committed Aug 29, 2018
1 parent 1767676 commit 3bc6f2c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## Unreleased

### Added
- Now the global settings page shows you the parent field if the Matrix field is contained in a Super Table block

### Fixed
- Fixed an issue with the settings model rules not being declared properly
- Fixed an issue where sometimes the loader js wasn’t getting run
Expand Down
19 changes: 19 additions & 0 deletions src/Spoon.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,25 @@ public function getSettingsResponse()

$variables['globalSpoonedBlockTypes'] = $this->blockTypes->getByContext('global', 'fieldId', true);

// If Super Table is installed get all of the ST fields and store by child field context
$superTablePlugin = \Craft::$app->plugins->getPluginByPackageName('verbb/super-table');
if ($superTablePlugin && $variables['matrixFields']) {
$superTableService = new \verbb\supertable\services\SuperTableService();

foreach ($variables['matrixFields'] as $matrixField) {
if (strpos($matrixField->context, 'superTableBlockType') === 0) {
$parts = explode(':', $matrixField->context);
if (isset($parts[1])) {

/** @var \verbb\supertable\models\SuperTableBlockTypeModel $superTableBlockType */
$superTableBlockType = $superTableService->getBlockTypeById($parts[1]);

$variables['superTableFields'][$matrixField->context] = \Craft::$app->fields->getFieldById($superTableBlockType->fieldId);
}
}
}
}

$this->loader->configurator('#spoon-global-context-table', 'global');

return \Craft::$app->controller->renderTemplate('spoon/_settings/edit-global-context', $variables);
Expand Down
19 changes: 18 additions & 1 deletion src/templates/_settings/edit-global-context.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,29 @@
<p>{{ "Here you can set up default block type groups and field layouts for all your Matrix fields."|t }}</p>
{% if matrixFields|length %}
<table id="spoon-global-context-table" class="data fullwidth">
<thead>
<tr>
<th>Matrix Field</th>
{% if superTableFields is defined %}
<th colspan="2">Parent Field</th>
{% endif %}
<th></th>
</tr>
</thead>
<tbody>
{% for field in matrixFields %}
<tr>
<td>
<td{% if superTableFields is defined and 'superTableBlockType' not in field.context %} colspan="3"{% endif %}>
<a title="{{ 'Edit'|t }}" role="button" class="edit" data-spoon-field-id="{{ field.id }}">{{ field.name }}</a>
</td>
{% if superTableFields is defined and 'superTableBlockType' in field.context %}
<td>
<a href="{{ url('settings/fields/edit/' ~ superTableFields[field.context].id) }}" title="{{ 'Edit'|t }}" role="button">
{{ superTableFields[field.context].name }}
</a>
</td>
<td>Super Table</td>
{% endif %}
<td class="thin">
<a class="delete icon{% if field.id not in globalSpoonedBlockTypes|keys %} hidden{% endif %}" title="{{ 'Delete'|t }}" role="button" data-spoon-field-id="{{ field.id }}"></a>
</td>
Expand Down

0 comments on commit 3bc6f2c

Please sign in to comment.