Skip to content

Commit

Permalink
Merge branch 'release/3.5.0'
Browse files Browse the repository at this point in the history
* release/3.5.0:
  Changelog for 3.5.0
  Refactored plugin component loading.
  Dropped the field refresh in the blocktypes service.
  Schema bump
  Finished up the migration code.
  Cleaning
  Validate new sort field
  Storing sort orders in the DB and sorting by them on fetch
  Added sort order to block types config
  Fixed fields not showing on Craft 3.4
  Fixed gulp
  • Loading branch information
joshangell committed Feb 5, 2020
2 parents 6f59100 + aec89c6 commit 53ef6f4
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 86 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
## Unreleased


## 3.5.0 - 2020-02-05

### Fixed
- Fixed things not working with Craft 3.4 ([79](https://github.com/angell-co/Spoon/issues/79))
- Fixed an issue with block type configurations not keeping their order when deployed to another environment via project config ([#80](https://github.com/angell-co/Spoon/issues/80))
- Fixed an issue where Craft’s info table was being updated on every CP request ([#82](https://github.com/angell-co/Spoon/issues/82))


## 3.4.3 - 2019-12-16

### Fixed
Expand Down
21 changes: 8 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
"matrix"
],
"support": {
"email": "[email protected]",
"issues": "https://github.com/angell-co/spoon/issues",
"source": "https://github.com/angell-co/spoon",
"docs": "https://github.com/angell-co/spoon/blob/master/README.md",
"issues": "https://github.com/angell-co/spoon/issues"
"rss": "https://github.com/angell-co/spoon/commits/v2.atom"
},
"license": "proprietary",
"authors": [
Expand All @@ -22,7 +25,7 @@
}
],
"require": {
"craftcms/cms": "^3.1.0"
"craftcms/cms": "^3.4.0"
},
"autoload": {
"psr-4": {
Expand All @@ -32,17 +35,9 @@
"extra": {
"name": "Spoon",
"handle": "spoon",
"hasCpSettings": true,
"hasCpSection": false,
"description" : "A plugin for Craft to enhance your Matrix fields with groups, tabs and more!",
"documentationUrl": "https://github.com/angell-co/spoon/blob/master/README.md",
"changelogUrl": "https://raw.githubusercontent.com/angell-co/spoon/master/CHANGELOG.md",
"components": {
"fields": "angellco\\spoon\\services\\Fields",
"blockTypes": "angellco\\spoon\\services\\BlockTypes",
"loader": "angellco\\spoon\\services\\Loader"
},
"class": "angellco\\spoon\\Spoon",
"branch-alias": {
"dev-master": "3.0.x-dev"
}
"class": "angellco\\spoon\\Spoon"
}
}
77 changes: 42 additions & 35 deletions src/Spoon.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@

namespace angellco\spoon;

use angellco\spoon\base\PluginTrait;
use angellco\spoon\helpers\ProjectConfig as ProjectConfigHelper;
use angellco\spoon\models\Settings;
use angellco\spoon\services\BlockTypes;
use angellco\spoon\services\Fields as FieldsService;
use angellco\spoon\services\BlockTypes as BlockTypesService;
use angellco\spoon\services\Loader as LoaderService;
use angellco\spoon\helpers\ProjectConfig as ProjectConfigHelper;
use angellco\spoon\services\Fields;
use angellco\spoon\services\Loader;

use Craft;
use craft\base\Plugin;
Expand All @@ -24,7 +24,11 @@
use craft\services\Plugins;
use craft\services\ProjectConfig;

use verbb\supertable\fields\SuperTableField;
use verbb\supertable\models\SuperTableBlockTypeModel;
use yii\base\Event;
use yii\base\InvalidConfigException;
use yii\web\Response;

/**
* Craft plugins are very much like little applications in and of themselves. We’ve made
Expand All @@ -36,37 +40,37 @@
*
* https://craftcms.com/docs/plugins/introduction
*
* @property BlockTypes $blockTypes The block types component.
* @property Fields $fields The fields component.
* @property Loader $loader The loader component.
* @property Response|mixed $settingsResponse
* @method BlockTypes getBlockTypes() Returns the block types component.
* @method Fields getFields() Returns the fields component.
* @method Loader getLoader() Returns the loader component.
* @method Settings getSettings() Returns the settings model.
* @author Angell & Co
* @package Spoon
* @since 3.0.0
*
* @property FieldsService $fields
* @property BlockTypesService $blockTypes
* @property LoaderService $loader
* @method Settings getSettings()
*/
class Spoon extends Plugin
{
// Static Properties
// Traits
// =========================================================================

/**
* Static property that is an instance of this plugin class so that it can be accessed via
* Spoon::$plugin
*
* @var Spoon
*/
public static $plugin;
use PluginTrait;

// Public Properties
// =========================================================================

/**
* To execute your plugin’s migrations, you’ll need to increase its schema version.
*
* @var string
* @inheritdoc
*/
public $schemaVersion = '3.4.0';
public $schemaVersion = '3.5.0';

/**
* @inheritdoc
*/
public $hasCpSettings = true;

// Public Methods
// =========================================================================
Expand All @@ -85,8 +89,11 @@ class Spoon extends Plugin
public function init()
{
parent::init();

self::$plugin = $this;

$this->_setPluginComponents();

// Wait until all the plugins have loaded before running the loader
Event::on(
Plugins::class,
Expand All @@ -100,9 +107,9 @@ function() {

// Project config listeners
Craft::$app->projectConfig
->onAdd($this->blockTypes::CONFIG_BLOCKTYPE_KEY.'.{uid}', [$this->blockTypes, 'handleChangedBlockType'])
->onUpdate($this->blockTypes::CONFIG_BLOCKTYPE_KEY.'.{uid}', [$this->blockTypes, 'handleChangedBlockType'])
->onRemove($this->blockTypes::CONFIG_BLOCKTYPE_KEY.'.{uid}', [$this->blockTypes, 'handleDeletedBlockType']);
->onAdd(BlockTypes::CONFIG_BLOCKTYPE_KEY.'.{uid}', [$this->getBlockTypes(), 'handleChangedBlockType'])
->onUpdate(BlockTypes::CONFIG_BLOCKTYPE_KEY.'.{uid}', [$this->getBlockTypes(), 'handleChangedBlockType'])
->onRemove(BlockTypes::CONFIG_BLOCKTYPE_KEY.'.{uid}', [$this->getBlockTypes(), 'handleDeletedBlockType']);

// Project config rebuild listener
Event::on(ProjectConfig::class, ProjectConfig::EVENT_REBUILD, function(RebuildConfigEvent $e) {
Expand All @@ -123,17 +130,17 @@ function() {
/**
* Loads the edit page for the global context.
*
* @return mixed|\yii\web\Response
* @throws \yii\base\InvalidConfigException
* @return mixed|Response
* @throws InvalidConfigException
*/
public function getSettingsResponse()
{
$variables['matrixFields'] = Spoon::$plugin->fields->getMatrixFields();
$variables['matrixFields'] = $this->fields->getMatrixFields();

$variables['globalSpoonedBlockTypes'] = Spoon::$plugin->blockTypes->getByContext('global', 'fieldId', true);
$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');
$superTablePlugin = Craft::$app->plugins->getPlugin('super-table');
if ($superTablePlugin && $variables['matrixFields']) {
$superTableService = new \verbb\supertable\services\SuperTableService();

Expand All @@ -145,11 +152,11 @@ public function getSettingsResponse()
$superTableBlockTypeId = Db::idByUid('{{%supertableblocktypes}}', $parts[1]);

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

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

$variables['superTableFields'][$matrixField->context] = [
'kind' => 'Super Table',
Expand All @@ -166,10 +173,10 @@ public function getSettingsResponse()

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

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

$variables['superTableFields'][$matrixField->context] = [
'kind' => 'Matrix',
Expand All @@ -188,7 +195,7 @@ public function getSettingsResponse()
}
}

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

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

0 comments on commit 53ef6f4

Please sign in to comment.