├── .env
├── .gitignore
├── LICENSE
├── README.md
├── composer.json
├── docker-compose.yml
└── src
├── Helper
└── Data.php
├── Plugin
└── BlockPlugin.php
├── etc
├── frontend
│ └── di.xml
└── module.xml
└── registration.php
/.env:
--------------------------------------------------------------------------------
1 | COMPOSE_PROJECT_NAME=m2_meanbee_svghelper
2 |
3 | PROJECT_HOSTNAME=m2-meanbee-svghelper.dev.docker
4 | PROJECT_CERT=dev.docker
5 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /magento
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2017 Meanbee
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Magento 2 SVG Helper
2 |
3 | Simple module that provides a block level helper for reading in an SVG files source from a theme in Magento 2.
4 |
5 | ## Installation
6 |
7 | Install this extension via Composer:
8 |
9 | ```
10 | composer require meanbee/magento2-svghelper
11 | ```
12 |
13 | ## Development
14 |
15 | ### Setting up a development environment
16 |
17 | A Docker development environment is included with the project:
18 |
19 | ```
20 | docker-compose run --rm cli magento-extension-installer Meanbee_SVGHelper \
21 | && docker-compose up -d
22 | ```
23 |
24 | ## Usage
25 |
26 | The SVGHelper is set as data on every block. This means that in your template you can call:
27 |
28 | ```getData('svgHelper')->getViewSvg('pathtofile.svg') ?>```
29 |
30 | or
31 |
32 | ```getData('svgHelper')->getViewSvg('Magento_Module::pathtofile.svg') ?>```
33 |
34 | This will output the raw contents of the svg file.
35 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "meanbee/magento2-svghelper",
3 | "description": "Magento 2 module that provides a block level helper for reading in an SVG files source from a theme",
4 | "type": "magento2-module",
5 | "version": "1.1.0",
6 | "license": [
7 | "MIT"
8 | ],
9 | "repositories": {
10 | "magento": {
11 | "type": "composer",
12 | "url": "https://repo.magento.com/"
13 | }
14 | },
15 | "require": {
16 | "magento/framework": "101 - 102",
17 | "psr/log": "~1.0"
18 | },
19 | "authors": [
20 | {
21 | "name": "Darren Belding",
22 | "email": "darren.belding@meanbee.com"
23 | }
24 | ],
25 | "autoload": {
26 | "files": [
27 | "src/registration.php"
28 | ],
29 | "psr-4": {
30 | "Meanbee\\SVGHelper\\": "/src"
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "2"
2 | services:
3 | varnish:
4 | image: meanbee/magento2-varnish:latest
5 | hostname: ${PROJECT_HOSTNAME}
6 | ports:
7 | - 80
8 | environment:
9 | VIRTUAL_HOST: ${PROJECT_HOSTNAME}
10 | VIRTUAL_PORT: 80
11 | HTTPS_METHOD: noredirect
12 | CERT_NAME: ${PROJECT_CERT}
13 | links:
14 | - web
15 |
16 | web:
17 | image: meanbee/magento2-nginx:1.9
18 | hostname: web.${PROJECT_HOSTNAME}
19 | ports:
20 | - 80
21 | volumes_from:
22 | - magento
23 | links:
24 | - fpm
25 |
26 | fpm:
27 | image: meanbee/magento2-php:7.0-fpm
28 | hostname: fpm.${PROJECT_HOSTNAME}
29 | ports:
30 | - 9000
31 | volumes_from:
32 | - magento
33 | environment:
34 | ENABLE_SENDMAIL: "true"
35 | PHP_ENABLE_XDEBUG:
36 | links:
37 | - db
38 |
39 | cron:
40 | image: meanbee/magento2-php:7.0-cli
41 | hostname: cron.${PROJECT_HOSTNAME}
42 | command: run-cron
43 | volumes_from:
44 | - magento
45 | environment:
46 | ENABLE_SENDMAIL: "true"
47 | links:
48 | - db
49 |
50 | cli:
51 | image: meanbee/magento2-php:7.0-cli
52 | volumes_from:
53 | - magento
54 | environment:
55 | COMPOSER_HOME: /root/.composer
56 | COMPOSER_ALLOW_SUPERUSER: 1
57 | M2SETUP_INSTALL_DB: "true"
58 | M2SETUP_VERSION: 2.2.*
59 | M2SETUP_USE_SAMPLE_DATA: "true"
60 | M2SETUP_DB_HOST: db
61 | M2SETUP_DB_NAME: magento2
62 | M2SETUP_DB_USER: magento2
63 | M2SETUP_DB_PASSWORD: magento2
64 | M2SETUP_BASE_URL: https://${PROJECT_HOSTNAME}/
65 | M2SETUP_BACKEND_FRONTNAME: admin
66 | M2SETUP_ADMIN_FIRSTNAME: Admin
67 | M2SETUP_ADMIN_LASTNAME: User
68 | M2SETUP_ADMIN_EMAIL: admin@example.com
69 | M2SETUP_ADMIN_USER: admin
70 | M2SETUP_ADMIN_PASSWORD: password123
71 | links:
72 | - db
73 |
74 | db:
75 | image: mariadb:10
76 | ports:
77 | - 3306
78 | volumes:
79 | - dbdata:/var/lib/mysql
80 | environment:
81 | MYSQL_ROOT_PASSWORD: magento2
82 | MYSQL_USER: magento2
83 | MYSQL_PASSWORD: magento2
84 | MYSQL_DATABASE: magento2
85 | TERM: dumb
86 |
87 | magento:
88 | image: meanbee/magento2-data:2.2-sample
89 | volumes:
90 | - .:/extensions/Meanbee_SVGHelper
91 | environment:
92 | SYNC_DESTINATION: /extensions/Meanbee_SVGHelper/magento
93 | privileged: true
94 |
95 | volumes:
96 | dbdata:
97 | # Database tables
98 |
99 |
--------------------------------------------------------------------------------
/src/Helper/Data.php:
--------------------------------------------------------------------------------
1 | assetSource = $assetSource;
18 | $this->assetRepository = $assetRepository;
19 |
20 | parent::__construct($context);
21 | }
22 |
23 | /**
24 | * @param $path
25 | *
26 | * @return bool|string
27 | */
28 | public function getViewSvg($path)
29 | {
30 | $file = $this->assetRepository->createAsset($path);
31 | return $this->assetSource->getContent($file);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/Plugin/BlockPlugin.php:
--------------------------------------------------------------------------------
1 | svgHelper = $svgHelper;
13 | }
14 |
15 | public function afterCreateBlock($subject, $result)
16 | {
17 | return $result->setData('svgHelper', $this->svgHelper);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/etc/frontend/di.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/src/etc/module.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/src/registration.php:
--------------------------------------------------------------------------------
1 |