Skip to content

Commit

Permalink
Add global config
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbushnell committed Apr 26, 2023
1 parent 4e79cc6 commit 00cb88d
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Release Notes for Spacing

## 0.7.1
- Setup a `{{ craft.spacing.config }}` to globally access config values in Twig templates

## 0.7.0
- Initial release
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "trendyminds/craft-spacing",
"description": "A utility field to insert spacing between your Matrix blocks",
"type": "craft-plugin",
"version": "0.7.0",
"version": "0.7.1",
"license": "mit",
"support": {
"email": "dev@trendyminds.com",
Expand Down Expand Up @@ -37,5 +37,8 @@
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true
}
},
"require-dev": {
"laravel/pint": "^1.5"
}
}
71 changes: 69 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/Spacing.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
use craft\events\RegisterComponentTypesEvent;
use craft\helpers\Json;
use craft\services\Fields;
use craft\web\twig\variables\CraftVariable;
use Exception;
use Illuminate\Support\Collection;
use trendyminds\spacing\fields\Field;
use trendyminds\spacing\variables\Variable;
use yii\base\Event;

/**
Expand Down Expand Up @@ -42,6 +44,16 @@ function (RegisterComponentTypesEvent $event) {
$event->types[] = Field::class;
}
);

Event::on(
CraftVariable::class,
CraftVariable::EVENT_INIT,
function (Event $event) {
/** @var CraftVariable $variable */
$variable = $event->sender;
$variable->set('spacing', Variable::class);
}
);
}

public static function options(): Collection
Expand Down
14 changes: 14 additions & 0 deletions src/variables/Variable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace trendyminds\spacing\variables;

use Illuminate\Support\Collection;
use trendyminds\spacing\Spacing;

class Variable
{
public function config(): Collection
{
return Spacing::options();
}
}

0 comments on commit 00cb88d

Please sign in to comment.