Skip to content

Commit

Permalink
Fix error where on initial install (where you don't have an API key s…
Browse files Browse the repository at this point in the history
…et yet) the plugin would try to fetch data from hubspot, causing a "cant call ->all() on null" error.
  • Loading branch information
HelgeSverre committed Dec 18, 2018
1 parent 1b98cd9 commit 11ffd6e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "guilty/hubspot-connector",
"description": "Expose Hubspot API features in Twig and pull in content from your HubSpot Portal.",
"type": "craft-plugin",
"version": "1.0.2",
"version": "1.0.3",
"keywords": [
"craft",
"cms",
Expand Down
13 changes: 12 additions & 1 deletion src/HubspotConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class HubspotConnector extends Plugin
/**
* @var string
*/
public $schemaVersion = '1.0.2';
public $schemaVersion = '1.0.3';

public function init()
{
Expand Down Expand Up @@ -76,6 +76,7 @@ protected function settingsHtml(): string
'hubspot-connector/settings',
[
'settings' => $this->getSettings(),
'isConnected' => $this->hubspot->hasApiKey(),
'blogSubscriptionFrequencies' => $this->getFrequencyList(),
'contactProperties' => $this->getContactInformationPropertiesList(),
]
Expand All @@ -84,6 +85,10 @@ protected function settingsHtml(): string

protected function getFrequencyList()
{
if ($this->hubspot->hasApiKey() === false) {
return [];
}

return [
[
"label" => "Instant",
Expand All @@ -106,6 +111,12 @@ protected function getFrequencyList()

protected function getContactInformationPropertiesList()
{


if ($this->hubspot->hasApiKey() === false) {
return [];
}

return array_map(function ($item) {
return [
"label" => $item->label,
Expand Down
2 changes: 1 addition & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function rules()
{
return [
['apiKey', 'string'],
['apiKey', 'required'],
['apiKey', 'string'],
['defaultBlogSubscriptionFrequency', 'string'],
['blogSubscriptionProperty', 'string'],
];
Expand Down
44 changes: 24 additions & 20 deletions src/templates/settings.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,27 @@

<hr>

{{ forms.lightswitchField({
label: 'Enable Blog Subscription Endpoint?',
instructions: 'Registers a controller action that allows you to subscribe a user to blog updates',
name: 'enableBlogSubscriptionEndpoint',
on: settings['enableBlogSubscriptionEndpoint']}) }}


{{ forms.selectField({
label: 'Blog Subscription Property',
instructions: 'Set the property that signifies the blog subscription frequency',
name: 'blogSubscriptionProperty',
value: settings['blogSubscriptionProperty'],
options: contactProperties }) }}

{{ forms.selectField({
label: 'Default Blog Subscription Frequency',
instructions: 'Set the default blog subscription frequency',
name: 'defaultBlogSubscriptionFrequency',
value: settings['defaultBlogSubscriptionFrequency'],
options: blogSubscriptionFrequencies }) }}
{% if isConnected %}

{{ forms.lightswitchField({
label: 'Enable Blog Subscription Endpoint?',
instructions: 'Registers a controller action that allows you to subscribe a user to blog updates',
name: 'enableBlogSubscriptionEndpoint',
on: settings['enableBlogSubscriptionEndpoint']}) }}


{{ forms.selectField({
label: 'Blog Subscription Property',
instructions: 'Set the property that signifies the blog subscription frequency',
name: 'blogSubscriptionProperty',
value: settings['blogSubscriptionProperty'],
options: contactProperties }) }}

{{ forms.selectField({
label: 'Default Blog Subscription Frequency',
instructions: 'Set the default blog subscription frequency',
name: 'defaultBlogSubscriptionFrequency',
value: settings['defaultBlogSubscriptionFrequency'],
options: blogSubscriptionFrequencies }) }}

{% endif %}

0 comments on commit 11ffd6e

Please sign in to comment.