From ca2b25f12dd1917b5ef9a0eb8455e8b158f27317 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Mon, 27 Mar 2017 18:00:59 -0400 Subject: [PATCH] ### Added * Added an example of accessing a plugin's settings from a service --- CHANGLOG.md | 4 ++++ app/templates/api_version_3_0/src/_Plugin.php | 1 - app/templates/api_version_3_0/src/services/_Service.php | 8 ++++++++ package.json | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGLOG.md b/CHANGLOG.md index d8fc58a..837fb63 100755 --- a/CHANGLOG.md +++ b/CHANGLOG.md @@ -1,5 +1,9 @@ # generator-craftplugin Changelog +## 1.2.32 - 2017.03.27 +### Added +* Added an example of accessing a plugin's settings from a service + ## 1.2.31 - 2017.03.25 ### Changed * Fixed the docblock for the `install` migration diff --git a/app/templates/api_version_3_0/src/_Plugin.php b/app/templates/api_version_3_0/src/_Plugin.php index 7a31c85..c69197b 100755 --- a/app/templates/api_version_3_0/src/_Plugin.php +++ b/app/templates/api_version_3_0/src/_Plugin.php @@ -379,7 +379,6 @@ public function defineTemplateComponent() // ========================================================================= <% if (pluginComponents.indexOf('settings') >= 0){ -%> - <% if ((typeof codeComments !== 'undefined') && (codeComments)) { -%> /** * Creates and returns the model used to store the plugin’s settings. diff --git a/app/templates/api_version_3_0/src/services/_Service.php b/app/templates/api_version_3_0/src/services/_Service.php index 1affaac..718e088 100644 --- a/app/templates/api_version_3_0/src/services/_Service.php +++ b/app/templates/api_version_3_0/src/services/_Service.php @@ -60,6 +60,14 @@ class <%= serviceName[index] %> extends Component public function exampleService() { $result = 'something'; +<% if (pluginComponents.indexOf('settings') >= 0){ -%> + // Check our Plugin's settings for `someField` +<% if ((typeof codeComments !== 'undefined') && (codeComments)) { -%> +<% } else { -%> +<% } -%> + if (<%= pluginHandle %>::$plugin->getSettings()->someField) { + } +<% } -%> return $result; } diff --git a/package.json b/package.json index 3e1e8a4..4fc178d 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "generator-craftplugin", - "version": "1.2.31", + "version": "1.2.32", "description": "generator-craftplugin is a Yeoman generator for Craft CMS plugins", "main": "app/index.js", "files": [