Passed
Push — v4 ( 483dd2...9bab8e )
by Andrew
15:49 queued 09:35
created

InstantAnalytics::iaInsertGtag()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 12
c 0
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\App;
23
use craft\helpers\UrlHelper;
24
use craft\services\Plugins;
25
use craft\web\twig\variables\CraftVariable;
26
use craft\web\UrlManager;
27
use craft\web\View;
28
use Exception;
29
use nystudio107\instantanalyticsGa4\helpers\Analytics;
30
use nystudio107\instantanalyticsGa4\helpers\Field as FieldHelper;
31
use nystudio107\instantanalyticsGa4\models\Settings;
32
use nystudio107\instantanalyticsGa4\services\ServicesTrait;
33
use nystudio107\instantanalyticsGa4\twigextensions\InstantAnalyticsTwigExtension;
34
use nystudio107\instantanalyticsGa4\variables\InstantAnalyticsVariable;
35
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...
36
use yii\base\Event;
37
use yii\web\Response;
38
use function array_merge;
39
40
/** @noinspection MissingPropertyAnnotationsInspection */
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
The close comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
41
42
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
43
 * @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...
44
 * @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...
45
 * @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...
46
 */
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...
47
class InstantAnalytics extends Plugin
48
{
49
    // Traits
50
    // =========================================================================
51
52
    use ServicesTrait;
53
54
    // Constants
55
    // =========================================================================
56
57
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
58
     * @var string
59
     */
60
    protected const COMMERCE_PLUGIN_HANDLE = 'commerce';
61
62
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
63
     * @var string
64
     */
65
    protected const SEOMATIC_PLUGIN_HANDLE = 'seomatic';
66
67
    // Static Properties
68
    // =========================================================================
69
70
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
71
     * @var null|InstantAnalytics
72
     */
73
    public static ?InstantAnalytics $plugin = null;
74
75
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
76
     * @var null|Settings
77
     */
78
    public static ?Settings $settings = null;
79
80
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
81
     * @var null|Commerce
82
     */
83
    public static ?Commerce $commercePlugin = null;
84
85
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
86
     * @var null|Seomatic
87
     */
88
    public static ?Seomatic $seomaticPlugin = null;
89
90
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
91
     * @var string
92
     */
93
    public static string $currentTemplate = '';
94
95
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
96
     * @var bool
97
     */
98
    public static bool $pageViewSent = false;
99
100
    // Public Properties
101
    // =========================================================================
102
103
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
104
     * @var string
105
     */
106
    public string $schemaVersion = '1.0.0';
107
108
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
109
     * @var bool
110
     */
111
    public bool $hasCpSection = false;
112
113
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
114
     * @var bool
115
     */
116
    public bool $hasCpSettings = true;
117
118
    // Public Methods
119
    // =========================================================================
120
121
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
122
     * @inheritdoc
123
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
124
    public function init(): void
125
    {
126
        parent::init();
127
        self::$plugin = $this;
128
        self::$settings = $this->getSettings();
129
130
        // Add in our Craft components
131
        $this->addComponents();
132
        // Install our global event handlers
133
        $this->installEventListeners();
134
135
        Craft::info(
136
            Craft::t(
137
                'instant-analytics-ga4',
138
                '{name} plugin loaded',
139
                ['name' => $this->name]
140
            ),
141
            __METHOD__
142
        );
143
    }
144
145
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
146
     * @inheritdoc
147
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
148
    protected function settingsHtml(): ?string
149
    {
150
        $commerceFields = [];
151
152
        if (self::$commercePlugin !== null) {
153
            $productTypes = self::$commercePlugin->getProductTypes()->getAllProductTypes();
154
155
            foreach ($productTypes as $productType) {
156
                $productFields = $this->getPullFieldsFromLayoutId($productType->fieldLayoutId);
157
                /** @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...
158
                $commerceFields = array_merge($commerceFields, $productFields);
159
                if ($productType->hasVariants) {
160
                    $variantFields = $this->getPullFieldsFromLayoutId($productType->variantFieldLayoutId);
161
                    /** @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...
162
                    $commerceFields = array_merge($commerceFields, $variantFields);
163
                }
164
            }
165
        }
166
167
        // Rend the settings template
168
        try {
169
            return Craft::$app->getView()->renderTemplate(
170
                'instant-analytics-ga4/settings',
171
                [
172
                    'settings' => $this->getSettings(),
173
                    'commerceFields' => $commerceFields,
174
                ]
175
            );
176
        } catch (Exception $exception) {
177
            Craft::error($exception->getMessage(), __METHOD__);
178
        }
179
180
        return '';
181
    }
182
183
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $context should have a doc-comment as per coding-style.
Loading history...
184
     * Handle the `{% hook iaSendPageView %}`
185
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
186
    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...
187
    {
188
        $this->ga4->addPageViewEvent();
189
        return '';
190
    }
191
192
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $context should have a doc-comment as per coding-style.
Loading history...
193
     * Handle the `{% hook iaInsertGtag %}`
194
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
195
    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...
196
    {
197
        $userSegment = '';
198
199
        if (self::$settings->sendUserId) {
200
            $userId = Analytics::getUserId();
201
            if (!empty($userId)) {
202
                $userSegment = "'user_id': '$userId'";
203
            }
204
        }
205
206
        $measurementId = App::parseEnv(self::$settings->googleAnalyticsMeasurementId);
207
208
        return <<<GTAG
209
<!-- Google tag (gtag.js) -->
210
<script async src="https://www.googletagmanager.com/gtag/js?id=$measurementId"></script>
211
<script>
212
  window.dataLayer = window.dataLayer || [];
213
  function gtag(){dataLayer.push(arguments);}
214
  gtag('js', new Date());
215
216
  gtag('config', '$measurementId', 
217
  {
218
  $userSegment
219
  });
220
</script>
221
GTAG;
222
    }
223
224
    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...
225
    {
226
        Craft::info(
227
            Craft::t('instant-analytics-ga4', $message, $variables),
228
            $category
229
        );
230
    }
231
    // Protected Methods
232
    // =========================================================================
233
234
    /**
235
     * Add in our Craft components
236
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
237
    protected function addComponents(): void
238
    {
239
        $view = Craft::$app->getView();
240
        // Add in our Twig extensions
241
        $view->registerTwigExtension(new InstantAnalyticsTwigExtension());
242
        // Install our template hooks
243
        $view->hook('iaSendPageView', [$this, 'iaSendPageView']);
244
        $view->hook('iaInsertGtag', [$this, 'iaInsertGtag']);
245
246
        // Register our variables
247
        Event::on(
248
            CraftVariable::class,
249
            CraftVariable::EVENT_INIT,
250
            function (Event $event): void {
251
                /** @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...
252
                $variable = $event->sender;
253
                $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...
254
                    'class' => InstantAnalyticsVariable::class,
255
                    'viteService' => $this->vite,
256
                ]);
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...
257
            }
258
        );
259
    }
260
261
    /**
262
     * Install our event listeners
263
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
264
    protected function installEventListeners(): void
265
    {
266
        // Handler: Plugins::EVENT_AFTER_INSTALL_PLUGIN
267
        Event::on(
268
            Plugins::class,
269
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
270
            function (PluginEvent $event): void {
271
                if ($event->plugin === $this) {
0 ignored issues
show
introduced by
The condition $event->plugin === $this is always false.
Loading history...
272
                    $request = Craft::$app->getRequest();
273
                    if ($request->isCpRequest) {
274
                        Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('instant-analytics-ga4/welcome'))->send();
275
                    }
276
                }
277
            }
278
        );
279
280
        // Handler: Plugins::EVENT_AFTER_LOAD_PLUGINS
281
        Event::on(
282
            Plugins::class,
283
            Plugins::EVENT_AFTER_LOAD_PLUGINS,
284
            function () {
285
                // Determine if Craft Commerce is installed & enabled
286
                self::$commercePlugin = Craft::$app->getPlugins()->getPlugin(self::COMMERCE_PLUGIN_HANDLE);
287
                // Determine if SEOmatic is installed & enabled
288
                self::$seomaticPlugin = Craft::$app->getPlugins()->getPlugin(self::SEOMATIC_PLUGIN_HANDLE);
289
290
                // Make sure to install these only after we definitely know whether other plugins are installed
291
                $request = Craft::$app->getRequest();
292
                // Install only for non-console site requests
293
                if ($request->getIsSiteRequest() && !$request->getIsConsoleRequest()) {
294
                    $this->installSiteEventListeners();
295
                }
296
297
                // Install only for non-console Control Panel requests
298
                if ($request->getIsCpRequest() && !$request->getIsConsoleRequest()) {
299
                    $this->installCpEventListeners();
300
                }
301
            }
302
        );
303
    }
304
305
    /**
306
     * Install site event listeners for site requests only
307
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
308
    protected function installSiteEventListeners(): void
309
    {
310
        // Handler: UrlManager::EVENT_REGISTER_SITE_URL_RULES
311
        Event::on(
312
            UrlManager::class,
313
            UrlManager::EVENT_REGISTER_SITE_URL_RULES,
314
            function (RegisterUrlRulesEvent $event): void {
315
                Craft::debug(
316
                    'UrlManager::EVENT_REGISTER_SITE_URL_RULES',
317
                    __METHOD__
318
                );
319
                // Register our Control Panel routes
320
                $event->rules = array_merge(
321
                    $event->rules,
322
                    $this->customFrontendRoutes()
323
                );
324
            }
325
        );
326
        // Remember the name of the currently rendering template
327
        Event::on(
328
            View::class,
329
            View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE,
330
            static function (TemplateEvent $event): void {
331
                self::$currentTemplate = $event->template;
332
            }
333
        );
334
        // Send the page-view event.
335
        Event::on(
336
            View::class,
337
            View::EVENT_AFTER_RENDER_PAGE_TEMPLATE,
338
            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

338
            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...
339
                if (self::$settings->autoSendPageView) {
340
                    $request = Craft::$app->getRequest();
341
                    if (!$request->getIsAjax()) {
342
                        $this->ga4->addPageViewEvent();
343
                    }
344
                }
345
            }
346
        );
347
348
        // Send the collected events
349
        Event::on(
350
            Response::class,
351
            Response::EVENT_BEFORE_SEND,
352
            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

352
            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...
353
                // Initialize this sooner rather than later, since it's possible this will want to tinker with cookies
354
                $this->ga4->getAnalytics();
355
            }
356
        );
357
358
        // Send the collected events
359
        Event::on(
360
            Response::class,
361
            Response::EVENT_AFTER_SEND,
362
            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

362
            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...
363
                $this->ga4->getAnalytics()->sendCollectedEvents();
364
            }
365
        );
366
367
        // Commerce-specific hooks
368
        if (self::$commercePlugin !== null) {
369
            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...
370
                $order = $e->sender;
371
                if (self::$settings->autoSendPurchaseComplete) {
372
                    $this->commerce->triggerOrderCompleteEvent($order);
373
                }
374
            });
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...
375
376
            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...
377
                $lineItem = $e->lineItem;
378
                if (self::$settings->autoSendAddToCart) {
379
                    $this->commerce->triggerAddToCartEvent($lineItem);
380
                }
381
            });
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...
382
383
            // Check to make sure Order::EVENT_AFTER_REMOVE_LINE_ITEM is defined
384
            if (defined(Order::class . '::EVENT_AFTER_REMOVE_LINE_ITEM')) {
385
                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...
386
                    $lineItem = $e->lineItem;
387
                    if (self::$settings->autoSendRemoveFromCart) {
388
                        $this->commerce->triggerRemoveFromCartEvent($lineItem);
389
                    }
390
                });
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...
391
            }
392
        }
393
    }
394
395
    /**
396
     * Install site event listeners for Control Panel requests only
397
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
398
    protected function installCpEventListeners(): void
399
    {
400
    }
401
402
    /**
403
     * Return the custom frontend routes
404
     *
405
     * @return array<string, string>
406
     */
407
    protected function customFrontendRoutes(): array
408
    {
409
        return [
410
            'instantanalytics/pageViewTrack' =>
411
                'instant-analytics-ga4/track/track-page-view-url',
412
            'instantanalytics/eventTrack/<filename:[-\w\.*]+>?' =>
413
                'instant-analytics-ga4/track/track-event-url',
414
        ];
415
    }
416
417
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
418
     * @inheritdoc
419
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
420
    protected function createSettingsModel(): ?Model
421
    {
422
        return new Settings();
423
    }
424
425
    // Private Methods
426
    // =========================================================================
427
428
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
429
     * @param $layoutId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
430
     *
431
     * @return mixed[]|array<string, string>
432
     */
433
    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...
434
    {
435
        $result = ['' => 'none'];
436
        if ($layoutId === null) {
437
            return $result;
438
        }
439
440
        $fieldLayout = Craft::$app->getFields()->getLayoutById($layoutId);
441
        if ($fieldLayout) {
442
            $result = FieldHelper::fieldsOfTypeFromLayout(FieldHelper::TEXT_FIELD_CLASS_KEY, $fieldLayout, false);
443
        }
444
445
        return $result;
446
    }
447
}
448