Passed
Push — develop-v4 ( b4fdd0...09ded3 )
by Andrew
04:32
created

InstantAnalytics::installEventListeners()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 5
eloc 7
c 3
b 1
f 0
nc 4
nop 0
dl 0
loc 15
rs 9.6111
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\Field as FieldHelper;
29
use nystudio107\instantanalyticsGa4\models\Settings;
30
use nystudio107\instantanalyticsGa4\services\ServicesTrait;
31
use nystudio107\instantanalyticsGa4\twigextensions\InstantAnalyticsTwigExtension;
32
use nystudio107\instantanalyticsGa4\variables\InstantAnalyticsVariable;
33
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...
34
use yii\base\Event;
35
use yii\web\Response;
36
use function array_merge;
37
38
/** @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
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...
39
40
/**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
41
 * @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...
42
 * @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...
43
 * @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...
44
 */
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...
45
class InstantAnalytics extends Plugin
46
{
47
    // Traits
48
    // =========================================================================
49
50
    use ServicesTrait;
51
52
    // Constants
53
    // =========================================================================
54
55
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
56
     * @var string
57
     */
58
    protected const COMMERCE_PLUGIN_HANDLE = 'commerce';
59
60
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
61
     * @var string
62
     */
63
    protected const SEOMATIC_PLUGIN_HANDLE = 'seomatic';
64
65
    // Static Properties
66
    // =========================================================================
67
68
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
69
     * @var null|InstantAnalytics
70
     */
71
    public static ?InstantAnalytics $plugin = null;
72
73
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
74
     * @var null|Settings
75
     */
76
    public static ?Settings $settings = null;
77
78
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
79
     * @var null|Commerce
80
     */
81
    public static ?Commerce $commercePlugin = null;
82
83
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
84
     * @var null|Seomatic
85
     */
86
    public static ?Seomatic $seomaticPlugin = null;
87
88
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
89
     * @var string
90
     */
91
    public static string $currentTemplate = '';
92
93
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
94
     * @var bool
95
     */
96
    public static bool $pageViewSent = false;
97
98
    // Public Properties
99
    // =========================================================================
100
101
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
102
     * @var string
103
     */
104
    public string $schemaVersion = '1.0.0';
105
106
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
107
     * @var bool
108
     */
109
    public bool $hasCpSection = false;
110
111
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
112
     * @var bool
113
     */
114
    public bool $hasCpSettings = true;
115
116
    // Public Methods
117
    // =========================================================================
118
119
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
120
     * @inheritdoc
121
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
122
    public function init(): void
123
    {
124
        parent::init();
125
        self::$plugin = $this;
126
        self::$settings = $this->getSettings();
127
128
        // Defer most setup tasks until Craft is fully initialized
129
        Craft::$app->onInit(function () {
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...
130
            // Add in our Craft components
131
            $this->addComponents();
132
            // Install our global event handlers
133
            $this->installEventListeners();
134
        });
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...
135
136
        // Handler: Plugins::EVENT_AFTER_INSTALL_PLUGIN
137
        Event::on(
138
            Plugins::class,
139
            Plugins::EVENT_AFTER_INSTALL_PLUGIN,
140
            function (PluginEvent $event): void {
141
                if ($event->plugin === $this) {
0 ignored issues
show
introduced by
The condition $event->plugin === $this is always false.
Loading history...
142
                    $request = Craft::$app->getRequest();
143
                    if ($request->isCpRequest) {
144
                        Craft::$app->getResponse()->redirect(UrlHelper::cpUrl('instant-analytics-ga4/welcome'))->send();
145
                    }
146
                }
147
            }
148
        );
149
150
        Craft::info(
151
            Craft::t(
152
                'instant-analytics-ga4',
153
                '{name} plugin loaded',
154
                ['name' => $this->name]
155
            ),
156
            __METHOD__
157
        );
158
    }
159
160
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
161
     * @inheritdoc
162
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
163
    protected function settingsHtml(): ?string
164
    {
165
        $commerceFields = [];
166
167
        if (self::$commercePlugin !== null) {
168
            $productTypes = self::$commercePlugin->getProductTypes()->getAllProductTypes();
169
170
            foreach ($productTypes as $productType) {
171
                $productFields = $this->getPullFieldsFromLayoutId($productType->fieldLayoutId);
172
                /** @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...
173
                $commerceFields = array_merge($commerceFields, $productFields);
174
                if ($productType->hasVariants) {
175
                    $variantFields = $this->getPullFieldsFromLayoutId($productType->variantFieldLayoutId);
176
                    /** @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...
177
                    $commerceFields = array_merge($commerceFields, $variantFields);
178
                }
179
            }
180
        }
181
182
        // Rend the settings template
183
        try {
184
            return Craft::$app->getView()->renderTemplate(
185
                'instant-analytics-ga4/settings',
186
                [
187
                    'settings' => $this->getSettings(),
188
                    'commerceFields' => $commerceFields,
189
                ]
190
            );
191
        } catch (Exception $exception) {
192
            Craft::error($exception->getMessage(), __METHOD__);
193
        }
194
195
        return '';
196
    }
197
198
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $context should have a doc-comment as per coding-style.
Loading history...
199
     * Handle the `{% hook iaSendPageView %}`
200
     *
201
     *
202
     */
0 ignored issues
show
Coding Style introduced by
Additional blank lines found at end of doc comment
Loading history...
Coding Style introduced by
Missing @return tag in function comment
Loading history...
203
    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...
204
    {
205
        $this->ga4->addPageViewEvent();
206
        return '';
207
    }
208
209
    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...
210
    {
211
        Craft::info(
212
            Craft::t('instant-analytics-ga4', $message, $variables),
213
            $category
214
        );
215
    }
216
    // Protected Methods
217
    // =========================================================================
218
219
    /**
220
     * Add in our Craft components
221
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
222
    protected function addComponents(): void
223
    {
224
        $view = Craft::$app->getView();
225
        // Add in our Twig extensions
226
        $view->registerTwigExtension(new InstantAnalyticsTwigExtension());
227
        // Install our template hook
228
        $view->hook('iaSendPageView', fn(array $context): string => (string)$this->ga4->addPageViewEvent());
0 ignored issues
show
Unused Code introduced by
The parameter $context 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

228
        $view->hook('iaSendPageView', fn(/** @scrutinizer ignore-unused */ array $context): string => (string)$this->ga4->addPageViewEvent());

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...
Bug introduced by
Are you sure the usage of $this->ga4->addPageViewEvent() targeting nystudio107\instantanaly...Ga4::addPageViewEvent() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
229
230
        // Register our variables
231
        Event::on(
232
            CraftVariable::class,
233
            CraftVariable::EVENT_INIT,
234
            function (Event $event): void {
235
                /** @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...
236
                $variable = $event->sender;
237
                $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...
238
                    'class' => InstantAnalyticsVariable::class,
239
                    'viteService' => $this->vite,
240
                ]);
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...
241
            }
242
        );
243
    }
244
245
    /**
246
     * Install our event listeners
247
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
248
    protected function installEventListeners(): void
249
    {
250
        // Determine if Craft Commerce is installed & enabled
251
        self::$commercePlugin = Craft::$app->getPlugins()->getPlugin(self::COMMERCE_PLUGIN_HANDLE);
252
        // Determine if SEOmatic is installed & enabled
253
        self::$seomaticPlugin = Craft::$app->getPlugins()->getPlugin(self::SEOMATIC_PLUGIN_HANDLE);
254
        $request = Craft::$app->getRequest();
255
        // Install only for non-console site requests
256
        if ($request->getIsSiteRequest() && !$request->getIsConsoleRequest()) {
257
            $this->installSiteEventListeners();
258
        }
259
260
        // Install only for non-console Control Panel requests
261
        if ($request->getIsCpRequest() && !$request->getIsConsoleRequest()) {
262
            $this->installCpEventListeners();
263
        }
264
    }
265
266
    /**
267
     * Install site event listeners for site requests only
268
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
269
    protected function installSiteEventListeners(): void
270
    {
271
        // Handler: UrlManager::EVENT_REGISTER_SITE_URL_RULES
272
        Event::on(
273
            UrlManager::class,
274
            UrlManager::EVENT_REGISTER_SITE_URL_RULES,
275
            function (RegisterUrlRulesEvent $event): void {
276
                Craft::debug(
277
                    'UrlManager::EVENT_REGISTER_SITE_URL_RULES',
278
                    __METHOD__
279
                );
280
                // Register our Control Panel routes
281
                $event->rules = array_merge(
282
                    $event->rules,
283
                    $this->customFrontendRoutes()
284
                );
285
            }
286
        );
287
        // Remember the name of the currently rendering template
288
        Event::on(
289
            View::class,
290
            View::EVENT_BEFORE_RENDER_PAGE_TEMPLATE,
291
            static function (TemplateEvent $event): void {
292
                self::$currentTemplate = $event->template;
293
            }
294
        );
295
        // Send the page-view event.
296
        Event::on(
297
            View::class,
298
            View::EVENT_AFTER_RENDER_PAGE_TEMPLATE,
299
            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

299
            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...
300
                if (self::$settings->autoSendPageView) {
301
                    $request = Craft::$app->getRequest();
302
                    if (!$request->getIsAjax()) {
303
                        $this->ga4->addPageViewEvent();
304
                    }
305
                }
306
            }
307
        );
308
309
        // Send the collected events
310
        Event::on(
311
            Response::class,
312
            Response::EVENT_BEFORE_SEND,
313
            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

313
            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...
314
                // Initialize this sooner rather than later, since it's possible this will want to tinker with cookies
315
                $this->ga4->getAnalytics();
316
            }
317
        );
318
319
        // Send the collected events
320
        Event::on(
321
            Response::class,
322
            Response::EVENT_AFTER_SEND,
323
            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

323
            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...
324
                $this->ga4->getAnalytics()->sendCollectedEvents();
325
            }
326
        );
327
328
        // Commerce-specific hooks
329
        if (self::$commercePlugin !== null) {
330
            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...
331
                $order = $e->sender;
332
                if (self::$settings->autoSendPurchaseComplete) {
333
                    $this->commerce->triggerOrderCompleteEvent($order);
334
                }
335
            });
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...
336
337
            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...
338
                $lineItem = $e->lineItem;
339
                if (self::$settings->autoSendAddToCart) {
340
                    $this->commerce->triggerAddToCartEvent($lineItem);
341
                }
342
            });
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...
343
344
            // Check to make sure Order::EVENT_AFTER_REMOVE_LINE_ITEM is defined
345
            if (defined(Order::class . '::EVENT_AFTER_REMOVE_LINE_ITEM')) {
346
                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...
347
                    $lineItem = $e->lineItem;
348
                    if (self::$settings->autoSendRemoveFromCart) {
349
                        $this->commerce->triggerRemoveFromCartEvent($lineItem);
350
                    }
351
                });
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...
352
            }
353
        }
354
    }
355
356
    /**
357
     * Install site event listeners for Control Panel requests only
358
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
359
    protected function installCpEventListeners(): void
360
    {
361
    }
362
363
    /**
364
     * Return the custom frontend routes
365
     *
366
     * @return array<string, string>
367
     */
368
    protected function customFrontendRoutes(): array
369
    {
370
        return [
371
            'instantanalytics/pageViewTrack' =>
372
                'instant-analytics-ga4/track/track-page-view-url',
373
            'instantanalytics/eventTrack/<filename:[-\w\.*]+>?' =>
374
                'instant-analytics-ga4/track/track-event-url',
375
        ];
376
    }
377
378
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
379
     * @inheritdoc
380
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
381
    protected function createSettingsModel(): ?Model
382
    {
383
        return new Settings();
384
    }
385
386
    // Private Methods
387
    // =========================================================================
388
389
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
390
     * @param $layoutId
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
391
     *
392
     * @return mixed[]|array<string, string>
393
     */
394
    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...
395
    {
396
        $result = ['' => 'none'];
397
        if ($layoutId === null) {
398
            return $result;
399
        }
400
401
        $fieldLayout = Craft::$app->getFields()->getLayoutById($layoutId);
402
        if ($fieldLayout) {
403
            $result = FieldHelper::fieldsOfTypeFromLayout(FieldHelper::TEXT_FIELD_CLASS_KEY, $fieldLayout, false);
404
        }
405
406
        return $result;
407
    }
408
}
409