1 | <?php |
||||||
2 | /** |
||||||
3 | * Rich Variables plugin for Craft CMS 3.x |
||||||
4 | * |
||||||
5 | * Allows you to easily use Craft Globals as variables in Rich Text fields |
||||||
6 | * |
||||||
7 | * @link https://nystudio107.com |
||||||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||||||
8 | * @copyright Copyright (c) 2017 nystudio107 |
||||||
0 ignored issues
–
show
|
|||||||
9 | */ |
||||||
0 ignored issues
–
show
|
|||||||
10 | |||||||
11 | namespace nystudio107\richvariables\controllers; |
||||||
12 | |||||||
13 | use aelvan\preparsefield\fields\PreparseFieldType as PreparseField; |
||||||
0 ignored issues
–
show
The type
aelvan\preparsefield\fields\PreparseFieldType 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
14 | use Craft; |
||||||
15 | use craft\base\Field; |
||||||
16 | use craft\ckeditor\Field as CKEditorField; |
||||||
0 ignored issues
–
show
The type
craft\ckeditor\Field 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
17 | use craft\fields\Date as DateField; |
||||||
18 | use craft\fields\Dropdown as DropdownField; |
||||||
19 | use craft\fields\Number as NumberField; |
||||||
20 | use craft\fields\PlainText as PlainTextField; |
||||||
21 | use craft\helpers\Json; |
||||||
22 | use craft\redactor\Field as RedactorField; |
||||||
0 ignored issues
–
show
The type
craft\redactor\Field 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. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||||||
23 | use craft\web\Controller; |
||||||
24 | use nystudio107\richvariables\assetbundles\richvariables\RichVariablesAsset; |
||||||
25 | use nystudio107\richvariables\RichVariables; |
||||||
26 | use yii\base\InvalidConfigException; |
||||||
27 | |||||||
28 | /** |
||||||
0 ignored issues
–
show
|
|||||||
29 | * @author nystudio107 |
||||||
0 ignored issues
–
show
Content of the @author tag must be in the form "Display Name <[email protected]>"
![]() |
|||||||
30 | * @package RichVariables |
||||||
0 ignored issues
–
show
|
|||||||
31 | * @since 1.0.0 |
||||||
0 ignored issues
–
show
|
|||||||
32 | */ |
||||||
0 ignored issues
–
show
|
|||||||
33 | class DefaultController extends Controller |
||||||
34 | { |
||||||
35 | // Constants |
||||||
36 | // ========================================================================= |
||||||
37 | |||||||
38 | const VALID_FIELD_CLASSES = [ |
||||||
39 | PlainTextField::class, |
||||||
40 | NumberField::class, |
||||||
41 | DateField::class, |
||||||
42 | DropdownField::class, |
||||||
43 | RedactorField::class, |
||||||
44 | CKEditorField::class, |
||||||
45 | PreparseField::class, |
||||||
46 | ]; |
||||||
47 | |||||||
48 | // Public Methods |
||||||
49 | // ========================================================================= |
||||||
50 | |||||||
51 | /** |
||||||
0 ignored issues
–
show
|
|||||||
52 | * @return mixed |
||||||
53 | */ |
||||||
54 | public function actionIndex() |
||||||
55 | { |
||||||
56 | $result = []; |
||||||
57 | $variablesList = []; |
||||||
58 | |||||||
59 | // Get the global set to use |
||||||
60 | $settings = RichVariables::$plugin->getSettings(); |
||||||
61 | $globalsSet = Craft::$app->getGlobals()->getSetByHandle($settings['globalSetHandle']); |
||||||
62 | // Grab the first global set if they haven't specified one yet |
||||||
63 | if (!$globalsSet) { |
||||||
64 | $allGlobalsSetIds = Craft::$app->getGlobals()->getAllSetIds(); |
||||||
65 | if (!empty($allGlobalsSetIds)) { |
||||||
66 | $globalsSet = Craft::$app->globals->getSetById($allGlobalsSetIds[0]); |
||||||
0 ignored issues
–
show
The method
getSetById() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||||
67 | } |
||||||
68 | } |
||||||
69 | if ($globalsSet) { |
||||||
70 | // Get the field layout fields used for this global set |
||||||
71 | $layout = $globalsSet->getFieldLayout(); |
||||||
72 | if ($layout) { |
||||||
73 | $fieldLayoutFields = $layout->getFields(); |
||||||
74 | /** @var Field $field */ |
||||||
0 ignored issues
–
show
|
|||||||
75 | foreach ($fieldLayoutFields as $field) { |
||||||
76 | foreach (self::VALID_FIELD_CLASSES as $fieldClass) { |
||||||
77 | if ($field instanceof $fieldClass) { |
||||||
78 | // Add the field title and Reference Tag as per https://craftcms.com/docs/reference-tags |
||||||
79 | $thisVar = [ |
||||||
80 | 'title' => $field->name, |
||||||
81 | 'text' => '{globalset:' . $globalsSet->attributes['id'] . ':' . $field->handle . '}', |
||||||
82 | ]; |
||||||
83 | $variablesList[] = $thisVar; |
||||||
84 | } |
||||||
85 | } |
||||||
86 | } |
||||||
87 | } |
||||||
88 | } |
||||||
89 | |||||||
90 | // Get the URL to our menu icon from our resource bundle |
||||||
91 | try { |
||||||
92 | Craft::$app->getView()->registerAssetBundle(RichVariablesAsset::class); |
||||||
93 | } catch (InvalidConfigException $e) { |
||||||
94 | Craft::error($e->getMessage(), __METHOD__); |
||||||
95 | } |
||||||
96 | $menuIconUrl = Craft::$app->assetManager->getPublishedUrl( |
||||||
0 ignored issues
–
show
Are you sure
Craft::app->assetManager...web/assets/dist', true) of type false|mixed|string can be used in concatenation ?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
97 | '@nystudio107/richvariables/web/assets/dist', |
||||||
0 ignored issues
–
show
|
|||||||
98 | true |
||||||
0 ignored issues
–
show
The call to
yii\web\AssetManager::getPublishedUrl() has too many arguments starting with true .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above. ![]() |
|||||||
99 | ) . '/img/RichVariables-menu-icon.svg'; |
||||||
0 ignored issues
–
show
|
|||||||
100 | |||||||
101 | // Return everything to our JavaScript encoded as JSON |
||||||
102 | $result['variablesList'] = $variablesList; |
||||||
103 | $result['menuIconUrl'] = $menuIconUrl; |
||||||
104 | $result['useIconForMenu'] = $settings['useIconForMenu']; |
||||||
105 | |||||||
106 | return Json::encode($result); |
||||||
107 | } |
||||||
108 | } |
||||||
109 |