-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add component configurations to
Sprig
variable
- Loading branch information
Showing
6 changed files
with
56 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) PutYourLightsOn | ||
*/ | ||
|
||
namespace putyourlightson\sprig\helpers; | ||
|
||
use Craft; | ||
use craft\helpers\Json; | ||
use putyourlightson\sprig\base\Component; | ||
use putyourlightson\sprig\models\ConfigModel; | ||
|
||
/** | ||
* Manages the Sprig object in the console. | ||
* | ||
* @since 2.10.0 | ||
*/ | ||
class Console | ||
{ | ||
private static bool $initialized = false; | ||
|
||
/** | ||
* Initialises the Sprig object in the console. | ||
*/ | ||
public static function init(): void | ||
{ | ||
if (self::$initialized || Component::getIsRequest()) { | ||
return; | ||
} | ||
|
||
self::$initialized = true; | ||
|
||
Component::registerJs('Sprig = {components: []}'); | ||
} | ||
|
||
/** | ||
* Adds a component to the Sprig object in the console. | ||
*/ | ||
public static function addComponent(ConfigModel $config): void | ||
{ | ||
if (Craft::$app->getConfig()->getGeneral()->devMode === false) { | ||
return; | ||
} | ||
|
||
self::init(); | ||
|
||
$value = Json::encode($config->getAttributes()); | ||
|
||
Component::registerJs('Sprig.components.push(' . $value . ')'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters