Skip to content

Commit

Permalink
Merge branch 'release/3.3.1'
Browse files Browse the repository at this point in the history
* release/3.3.1:
  Changelog for 3.3.1
  Changelog for #46 reversion
  tidying.
  Removed the field cache refresh as it has a massive DB impact.
  Its not pretty but disabled Matrix fields now work.
  WIP on fixing the broken entry versions page
  package-lock.json
  Make our FieldManipulatorAsset depend on the MatrixAsset
  Be consistent with context handles
  Added support for the Commerce Product Type context
  README and CHANGELOG for #51
  Load global context editor under the top level cp nav item
  Updated the icon mask
  Remove hi-jacking of settings page for global context stuff
  Added some links to the recent Changelog update
  Changelog for Solspace Calendar support
  Added specific context for Solspace Calendar events
  • Loading branch information
joshangell committed Feb 21, 2019
2 parents 8a350ca + 9b5ef39 commit 281cf2c
Show file tree
Hide file tree
Showing 17 changed files with 3,928 additions and 233 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## Unreleased


## 3.3.1 - 2019-02-21

### Added
- Added support for [Solspace Calendar](https://solspace.com/craft/calendar/) specific contexts ([#36](https://github.com/angell-co/Spoon/issues/36))
- Added partial support for [Craft Commerce](https://craftcms.com/commerce) product type contexts ([#49](https://github.com/angell-co/Spoon/issues/49))

### Changed
- Moved the global block type context out of the plugin settings section ([#51](https://github.com/angell-co/Spoon/issues/51))

### Fixed
- Reverted PR [#46](https://github.com/angell-co/Spoon/pull/46) due to large DB impact resulting in slow page loads


## 3.3.0 - 2019-02-14

### Changed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ You can override your defaults for a specific context by going to the field layo

### Setting up defaults

To create default block type groups and field layouts for all your Matrix fields go to Settings → Spoon. Here you will find a list of your current Matrix fields.
To create default block type groups and field layouts for all your Matrix fields go to Spoon in the main navigation. Here you will find a list of your current Matrix fields.

Click a field name to launch the block type groups editor. It should look something like this:

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"extra": {
"name": "Spoon",
"handle": "spoon",
"hasCpSettings": true,
"hasCpSection": false,
"hasCpSettings": false,
"hasCpSection": true,
"changelogUrl": "https://raw.githubusercontent.com/angell-co/spoon/master/CHANGELOG.md",
"components": {
"fields": "angellco\\spoon\\services\\Fields",
Expand Down
90 changes: 16 additions & 74 deletions src/Spoon.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

use Craft;
use craft\base\Plugin;
use craft\helpers\Db;
use craft\events\RegisterUrlRulesEvent;
use craft\services\Plugins;
use craft\events\PluginEvent;

use craft\web\UrlManager;
use yii\base\Event;

/**
Expand Down Expand Up @@ -65,6 +65,12 @@ class Spoon extends Plugin
*/
public $schemaVersion = '3.0.0';

/**
* @var bool Whether the plugin has its own section in the CP
*/
public $hasCpSection = true;


// Public Methods
// =========================================================================

Expand All @@ -84,6 +90,14 @@ public function init()
parent::init();
self::$plugin = $this;

Event::on(
UrlManager::class,
UrlManager::EVENT_REGISTER_CP_URL_RULES,
function(RegisterUrlRulesEvent $event) {
$event->rules['spoon'] = 'spoon/block-types/index';
}
);

// Wait until all the plugins have loaded before running the loader
Event::on(
Plugins::class,
Expand All @@ -105,78 +119,6 @@ function() {
);
}

/**
* Loads the edit page for the global context.
*
* @return mixed|\yii\web\Response
*/
public function getSettingsResponse()
{
$variables = [];

$variables['matrixFields'] = $this->fields->getMatrixFields();

$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->getPlugin('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])) {

$superTableBlockTypeId = Db::idByUid('{{%supertableblocktypes}}', $parts[1]);

/** @var \verbb\supertable\models\SuperTableBlockTypeModel $superTableBlockType */
$superTableBlockType = $superTableService->getBlockTypeById($superTableBlockTypeId);

/** @var \verbb\supertable\fields\SuperTableField $superTableField */
$superTableField = \Craft::$app->fields->getFieldById($superTableBlockType->fieldId);

$variables['superTableFields'][$matrixField->context] = [
'kind' => 'Super Table',
'field' => $superTableField,
'child' => false
];

// If the context of _this_ field is inside a Matrix block ... then we need to do more inception
if (strpos($superTableField->context, 'matrixBlockType') === 0) {
$nestedParts = explode(':', $superTableField->context);
if (isset($nestedParts[1])) {

$matrixBlockTypeId = Db::idByUid('{{%matrixblocktypes}}', $nestedParts[1]);

/** @var craft\models\MatrixBlockType $matrixBlockType */
$matrixBlockType = \Craft::$app->matrix->getBlockTypeById($matrixBlockTypeId);

/** @var craft\fields\Matrix $globalField */
$globalField = \Craft::$app->fields->getFieldById($matrixBlockType->fieldId);

$variables['superTableFields'][$matrixField->context] = [
'kind' => 'Matrix',
'field' => $globalField,
'child' => [
'kind' => 'Super Table',
'field' => $superTableField
]
];

}
}

}
}
}
}

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

return \Craft::$app->controller->renderTemplate('spoon/_settings/edit-global-context', $variables);
}

// Protected Methods
// =========================================================================

Expand Down
2 changes: 2 additions & 0 deletions src/assetbundles/FieldManipulatorAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Craft;
use craft\web\AssetBundle;
use craft\web\assets\cp\CpAsset;
use craft\web\assets\matrix\MatrixAsset;
use craft\web\View;

/**
Expand All @@ -38,6 +39,7 @@ public function init()
// define the dependencies
$this->depends = [
CpAsset::class,
MatrixAsset::class
];

// define the relative path to CSS/JS files that should be registered with the page
Expand Down
2 changes: 1 addition & 1 deletion src/assetbundles/dist/css/main.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 281cf2c

Please sign in to comment.