Passed
Push — develop-v3 ( 2011c7...a56f50 )
by Andrew
09:00
created

InstantAnalytics::iaInsertGtag()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 24
rs 9.8666
1
<?php
2
/**
3
 * Instant Analytics plugin for Craft CMS
4
 *
5
 * Instant Analytics brings full Google Analytics support to your Twig templates
6
 *
7
 * @link      https://nystudio107.com
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @copyright tag
Loading history...
8
 * @copyright Copyright (c) 2017 nystudio107
0 ignored issues
show
Coding Style introduced by
@copyright tag must contain a year and the name of the copyright holder
Loading history...
9
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
10
11
namespace nystudio107\instantanalyticsGa4;
12
13
use Craft;
14
use craft\base\Model;
15
use craft\base\Plugin;
16
use craft\commerce\elements\Order;
0 ignored issues
show
Bug introduced by
The type craft\commerce\elements\Order was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use craft\commerce\events\LineItemEvent;
0 ignored issues
show
Bug introduced by
The type craft\commerce\events\LineItemEvent was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
18
use craft\commerce\Plugin as Commerce;
0 ignored issues
show
Bug introduced by
The type craft\commerce\Plugin was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use craft\events\PluginEvent;
20
use craft\events\RegisterUrlRulesEvent;
21
use craft\events\TemplateEvent;
22
use craft\helpers\UrlHelper;
23
use craft\services\Plugins;
24
use craft\web\twig\variables\CraftVariable;
25
use craft\web\UrlManager;
26
use craft\web\View;
27
use Exception;
28
use nystudio107\instantanalyticsGa4\helpers\Analytics;
29
use nystudio107\instantanalyticsGa4\helpers\Field as FieldHelper;
30
use nystudio107\instantanalyticsGa4\models\Settings;
31
use nystudio107\instantanalyticsGa4\services\ServicesTrait;
32
use nystudio107\instantanalyticsGa4\twigextensions\InstantAnalyticsTwigExtension;
33
use nystudio107\instantanalyticsGa4\variables\InstantAnalyticsVariable;
34
use nystudio107\seomatic\Seomatic;
0 ignored issues
show
Bug introduced by
The type nystudio107\seomatic\Seomatic was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
35
use yii\base\Event;
36
use yii\web\Response;
37
use function array_merge;
38
39
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
40
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value for @author tag indented incorrectly; expected 2 spaces but found 4
Loading history...
41
 * @package   InstantAnalytics
0 ignored issues
show
Coding Style introduced by
Tag value for @package tag indented incorrectly; expected 1 spaces but found 3
Loading history...
42
 * @since     1.0.0
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
Coding Style introduced by
Tag value for @since tag indented incorrectly; expected 3 spaces but found 5
Loading history...
43
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
44
class InstantAnalytics extends Plugin
45
{
46
    // Traits
47
    // =========================================================================
48
49
    use ServicesTrait;
50
51
    // Constants
52
    // =========================================================================
53
54
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
55
     * @var string
56
     */
57
    protected const COMMERCE_PLUGIN_HANDLE = 'commerce';
58
59
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
60
     * @var string
61
     */
62
    protected const SEOMATIC_PLUGIN_HANDLE = 'seomatic';
63
64
    // Static Properties
65
    // =========================================================================
66
67
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
68
     * @var null|InstantAnalytics
69
     */
70
    public static $plugin = null;
71
72
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
73
     * @var null|Settings
74
     */
75
    public static $settings = null;
76
77
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
78
     * @var null|Commerce
79
     */
80
    public static $commercePlugin = null;
81
82
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
83
     * @var null|Seomatic
84
     */
85
    public static $seomaticPlugin = null;
86
87
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
88
     * @var string
89
     */
90
    public static $currentTemplate = '';
91
92
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
93
     * @var bool
94
     */
95
    public static $pageViewSent = false;
96
97
    // Public Properties
98
    // =========================================================================
99
100
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
101
     * @var string
102
     */
103
    public $schemaVersion = '1.0.0';
104
105
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
106
     * @var bool
107
     */
108
    public $hasCpSection = false;
109
110
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
111
     * @var bool
112
     */
113
    public $hasCpSettings = true;
114
115
    // Public Methods
116
    // =========================================================================
117
118
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
119
     * @inheritdoc
120
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
121
    public function init(): void
122
    {
123
        parent::init();
124
        self::$plugin = $this;
125
        self::$settings = $this->getSettings();
126
127
        // Add in our Craft components
128
        $this->addComponents();
129
        // Install our global event handlers
130
        $this->installEventListeners();
131
132
        Craft::info(
133
            Craft::t(
134
                'instant-analytics-ga4',
135
                '{name} plugin loaded',
136
                ['name' => $this->name]
137
            ),
138
            __METHOD__
139
        );
140
    }
141
142
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
143
     * @inheritdoc
144
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
145
    protected function settingsHtml(): ?string
146
    {
147
        $commerceFields = [];
148
149
        if (self::$commercePlugin !== null) {
150
            $productTypes = self::$commercePlugin->getProductTypes()->getAllProductTypes();
151
152
            foreach ($productTypes as $productType) {
153
                $productFields = $this->getPullFieldsFromLayoutId($productType->fieldLayoutId);
154
                /** @noinspection SlowArrayOperationsInLoopInspection */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
155
                $commerceFields = array_merge($commerceFields, $productFields);
156
                if ($productType->hasVariants) {
157
                    $variantFields = $this->getPullFieldsFromLayoutId($productType->variantFieldLayoutId);
158
                    /** @noinspection SlowArrayOperationsInLoopInspection */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
159
                    $commerceFields = array_merge($commerceFields, $variantFields);
160
                }
161
            }
162
        }
163
164
        // Rend the settings template
165
        try {
166
            return Craft::$app->getView()->renderTemplate(
167
                'instant-analytics-ga4/settings',
168
                [
169
                    'settings' => $this->getSettings(),
170
                    'commerceFields' => $commerceFields,
171
                ]
172
            );
173
        } catch (Exception $exception) {
174
            Craft::error($exception->getMessage(), __METHOD__);
175
        }
176
177
        return '';
178
    }
179
180
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $context should have a doc-comment as per coding-style.
Loading history...
181
     * Handle the `{% hook iaSendPageView %}`
182
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
183
    public function iaSendPageView(/** @noinspection PhpUnusedParameterInspection */ array &$context = []): string
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
184
    {
185
        $this->ga4->addPageViewEvent();
186
        return '';
187
    }
188
189
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $context should have a doc-comment as per coding-style.
Loading history...
190
     * Handle the `{% hook iaInsertGtag %}`
191
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
192
    public function iaInsertGtag(/** @noinspection PhpUnusedParameterInspection */ array &$context = []): string
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
193
    {
194
        $userSegment = '';
195
196
        if (self::$settings->sendUserId) {
197
            $userId = Analytics::getUserId();
198
            if (!empty($userId)) {
199
                $userSegment = "'user_id': '$userId'";
200
            }
201
        }
202
203
        $measurementId = Craft::parseEnv(self::$settings->googleAnalyticsMeasurementId);
0 ignored issues
show
Deprecated Code introduced by
The function Craft::parseEnv() has been deprecated: in 3.7.29. [[App::parseEnv()]] should be used instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

203
        $measurementId = /** @scrutinizer ignore-deprecated */ Craft::parseEnv(self::$settings->googleAnalyticsMeasurementId);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
204
205
        return <<<GTAG
206
<!-- Google tag (gtag.js) -->
207
<script async src="https://www.googletagmanager.com/gtag/js?id=$measurementId"></script>
208
<script>
209
  window.dataLayer = window.dataLayer || [];
210
  function gtag(){dataLayer.push(arguments);}
211
  gtag('js', new Date());
212
213
  gtag('config', '$measurementId', 
214
  {
215
  $userSegment
216
  });
217
</script>
218
GTAG;
219
    }
220
221
    public function logAnalyticsEvent(string $message, array $variables = [], string $category = ''): void
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function logAnalyticsEvent()
Loading history...
222
    {
223
        Craft::info(
224
            Craft::t('instant-analytics-ga4', $message, $variables),
225
            $category
226
        );
227
    }
228
    // Protected Methods
229
    // =========================================================================
230
231
    /**
232
     * Add in our Craft components
233
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
234
    protected function addComponents(): void
235
    {
236
        $view = Craft::$app->getView();
237
        // Add in our Twig extensions
238
        $view->registerTwigExtension(new InstantAnalyticsTwigExtension());
239
240
        // Install our template hooks
241
        $view->hook('iaSendPageView', [$this, 'iaSendPageView']);
242
        $view->hook('iaInsertGtag', [$this, 'iaInsertGtag']);
243
244
        // Register our variables
245
        Event::on(
246
            CraftVariable::class,
247
            CraftVariable::EVENT_INIT,
248
            function (Event $event): void {
249
                /** @var CraftVariable $variable */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
250
                $variable = $event->sender;
251
                $variable->set('instantAnalytics', [
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
252
                    'class' => InstantAnalyticsVariable::class,
253
                    'viteService' => $this->vite,
254
                ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
255
            }
256
        );
257
    }
258
259
    /**
260
     * Install our event listeners
261
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
262
    protected function installEventListeners(): void
263
    {
264
        // Handler: Plugins::EVENT_AFTER_INSTALL_PLUGIN
265
        Event::on(
266
            Plugins::class,
267
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
268
            function (PluginEvent $event): void {
269
                if ($event->plugin === $this) {
270
                    $request = Craft::$app->getRequest();
271
                    if ($request->isCpRequest) {
272
                        Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('instant-analytics-ga4/welcome'))->send();
273
                    }
274
                }
275
            }
276
        );
277
278
        // Handler: Plugins::EVENT_AFTER_LOAD_PLUGINS
279
        Event::on(
280
            Plugins::class,
281
            Plugins::EVENT_AFTER_LOAD_PLUGINS,
282
            function (Event $event): void {
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

282
            function (/** @scrutinizer ignore-unused */ Event $event): void {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
283
                // Determine if Craft Commerce is installed & enabled
284
                self::$commercePlugin = Craft::$app->getPlugins()->getPlugin(self::COMMERCE_PLUGIN_HANDLE);
285
                // Determine if SEOmatic is installed & enabled
286
                self::$seomaticPlugin = Craft::$app->getPlugins()->getPlugin(self::SEOMATIC_PLUGIN_HANDLE);
287
288
                // Make sure to install these only after we definitely know whether other plugins are installed
289
                $request = Craft::$app->getRequest();
290
                // Install only for non-console site requests
291
                if ($request->getIsSiteRequest() && !$request->getIsConsoleRequest()) {
292
                    $this->installSiteEventListeners();
293
                }
294
295
                // Install only for non-console Control Panel requests
296
                if ($request->getIsCpRequest() && !$request->getIsConsoleRequest()) {
297
                    $this->installCpEventListeners();
298
                }
299
            }
300
        );
301
    }
302
303
    /**
304
     * Install site event listeners for site requests only
305
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
306
    protected function installSiteEventListeners(): void
307
    {
308
        // Handler: UrlManager::EVENT_REGISTER_SITE_URL_RULES
309
        Event::on(
310
            UrlManager::class,
311
            UrlManager::EVENT_REGISTER_SITE_URL_RULES,
312
            function (RegisterUrlRulesEvent $event): void {
313
                Craft::debug(
314
                    'UrlManager::EVENT_REGISTER_SITE_URL_RULES',
315
                    __METHOD__
316
                );
317
                // Register our Control Panel routes
318
                $event->rules = array_merge(
319
                    $event->rules,
320
                    $this->customFrontendRoutes()
321
                );
322
            }
323
        );
324
        // Remember the name of the currently rendering template
325
        Event::on(
326
            View::class,
327
            View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE,
328
            static function (TemplateEvent $event): void {
329
                self::$currentTemplate = $event->template;
330
            }
331
        );
332
        // Send the page-view event.
333
        Event::on(
334
            View::class,
335
            View::EVENT_AFTER_RENDER_PAGE_TEMPLATE,
336
            function (TemplateEvent $event): void {
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

336
            function (/** @scrutinizer ignore-unused */ TemplateEvent $event): void {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
337
                if (self::$settings->autoSendPageView) {
338
                    $request = Craft::$app->getRequest();
339
                    if (!$request->getIsAjax()) {
340
                        $this->ga4->addPageViewEvent();
341
                    }
342
                }
343
            }
344
        );
345
346
        // Send the collected events
347
        Event::on(
348
            Response::class,
349
            Response::EVENT_BEFORE_SEND,
350
            function (Event $event): void {
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

350
            function (/** @scrutinizer ignore-unused */ Event $event): void {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
351
                // Initialize this sooner rather than later, since it's possible this will want to tinker with cookies
352
                $this->ga4->getAnalytics();
353
            }
354
        );
355
356
        // Send the collected events
357
        Event::on(
358
            Response::class,
359
            Response::EVENT_AFTER_SEND,
360
            function (Event $event): void {
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

360
            function (/** @scrutinizer ignore-unused */ Event $event): void {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
361
                $this->ga4->getAnalytics()->sendCollectedEvents();
362
            }
363
        );
364
365
        // Commerce-specific hooks
366
        if (self::$commercePlugin !== null) {
367
            Event::on(Order::class, Order::EVENT_AFTER_COMPLETE_ORDER, function (Event $e): void {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
368
                $order = $e->sender;
369
                if (self::$settings->autoSendPurchaseComplete) {
370
                    $this->commerce->triggerOrderCompleteEvent($order);
371
                }
372
            });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
373
374
            Event::on(Order::class, Order::EVENT_AFTER_ADD_LINE_ITEM, function (LineItemEvent $e): void {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
375
                $lineItem = $e->lineItem;
376
                if (self::$settings->autoSendAddToCart) {
377
                    $this->commerce->triggerAddToCartEvent($lineItem);
378
                }
379
            });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
380
381
            // Check to make sure Order::EVENT_AFTER_REMOVE_LINE_ITEM is defined
382
            if (defined(Order::class . '::EVENT_AFTER_REMOVE_LINE_ITEM')) {
383
                Event::on(Order::class, Order::EVENT_AFTER_REMOVE_LINE_ITEM, function (LineItemEvent $e): void {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
384
                    $lineItem = $e->lineItem;
385
                    if (self::$settings->autoSendRemoveFromCart) {
386
                        $this->commerce->triggerRemoveFromCartEvent($lineItem);
387
                    }
388
                });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
389
            }
390
        }
391
    }
392
393
    /**
394
     * Install site event listeners for Control Panel requests only
395
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
396
    protected function installCpEventListeners(): void
397
    {
398
    }
399
400
    /**
401
     * Return the custom frontend routes
402
     *
403
     * @return array<string, string>
404
     */
405
    protected function customFrontendRoutes(): array
406
    {
407
        return [
408
            'instantanalytics/pageViewTrack' =>
409
                'instant-analytics-ga4/track/track-page-view-url',
410
            'instantanalytics/eventTrack/<filename:[-\w\.*]+>?' =>
411
                'instant-analytics-ga4/track/track-event-url',
412
        ];
413
    }
414
415
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
416
     * @inheritdoc
417
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
418
    protected function createSettingsModel(): ?Model
419
    {
420
        return new Settings();
421
    }
422
423
    // Private Methods
424
    // =========================================================================
425
426
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
427
     * @param $layoutId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
428
     *
429
     * @return array|array<string, string>
430
     */
431
    private function getPullFieldsFromLayoutId($layoutId): array
0 ignored issues
show
Coding Style introduced by
Private method name "InstantAnalytics::getPullFieldsFromLayoutId" must be prefixed with an underscore
Loading history...
432
    {
433
        $result = ['' => 'none'];
434
        if ($layoutId === null) {
435
            return $result;
436
        }
437
438
        $fieldLayout = Craft::$app->getFields()->getLayoutById($layoutId);
439
        if ($fieldLayout) {
440
            $result = FieldHelper::fieldsOfTypeFromLayout(FieldHelper::TEXT_FIELD_CLASS_KEY, $fieldLayout, false);
441
        }
442
443
        return $result;
444
    }
445
}
446