-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 29f60eb
Showing
4 changed files
with
62 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
vendor | ||
mix-manifest.json |
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,11 @@ | ||
# Graphql Svg String | ||
|
||
**Graphql Svg String** is a Statamic addon that adds a field `svgString` to an `AssetInterface`, which – you guessed it – returns the SVG as a string. | ||
|
||
## How to Install | ||
|
||
You can search for this addon in the `Tools > Addons` section of the Statamic control panel and click **install**, or run the following command from your project root: | ||
|
||
```bash | ||
composer require el-schneider/graphql-svg-string | ||
``` |
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,19 @@ | ||
{ | ||
"name": "el-schneider/graphql-svg-string", | ||
"autoload": { | ||
"psr-4": { | ||
"ElSchneider\\GraphqlSvgString\\": "src" | ||
} | ||
}, | ||
"extra": { | ||
"statamic": { | ||
"name": "Graphql Svg String", | ||
"description": "Graphql Svg String addon" | ||
}, | ||
"laravel": { | ||
"providers": [ | ||
"ElSchneider\\GraphqlSvgString\\ServiceProvider" | ||
] | ||
} | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace ElSchneider\GraphqlSvgString; | ||
|
||
use Statamic\Facades\GraphQL; | ||
use Statamic\Assets\Asset; | ||
use Statamic\Providers\AddonServiceProvider; | ||
|
||
class ServiceProvider extends AddonServiceProvider | ||
{ | ||
public function bootAddon() | ||
{ | ||
GraphQL::addField( | ||
"AssetInterface", | ||
'svgString', | ||
function () { | ||
return [ | ||
"type" => GraphQL::type('String'), | ||
"resolve" => function (Asset $asset) { | ||
if ($asset->extension() === 'svg') { | ||
return $asset->contents(); | ||
} | ||
return null; | ||
} | ||
]; | ||
} | ||
); | ||
} | ||
} |