This repository was archived by the owner on Apr 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
[WIP] SVG Icons #441
Closed
Closed
[WIP] SVG Icons #441
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
|
|
||
| use Joomla\CMS\Cache\Cache; | ||
| use Joomla\CMS\Helper\ModuleHelper; | ||
| use Joomla\CMS\HTML\HTMLHelper; | ||
| use Joomla\CMS\Log\Log; | ||
| use Joomla\CMS\Uri\Uri; | ||
| use Joomla\Registry\Registry; | ||
|
|
@@ -151,6 +152,7 @@ public function getHeadData() | |
| $data['scripts'] = $this->_scripts; | ||
| $data['script'] = $this->_script; | ||
| $data['custom'] = $this->_custom; | ||
| $data['icons'] = $this->icons; | ||
| $data['scriptText'] = \JText::getScriptStrings(); | ||
|
|
||
| return $data; | ||
|
|
@@ -179,6 +181,7 @@ public function resetHeadData($types = null) | |
| $this->_scripts = array(); | ||
| $this->_script = array(); | ||
| $this->_custom = array(); | ||
| $this->icons = array(); | ||
| } | ||
|
|
||
| if (is_array($types)) | ||
|
|
@@ -255,6 +258,7 @@ public function setHeadData($data) | |
| $this->_scripts = $data['scripts'] ?? $this->_scripts; | ||
| $this->_script = $data['script'] ?? $this->_script; | ||
| $this->_custom = $data['custom'] ?? $this->_custom; | ||
| $this->icons = $data['custom'] ?? $this->icons; | ||
|
|
||
| if (isset($data['scriptText']) && !empty($data['scriptText'])) | ||
| { | ||
|
|
@@ -794,6 +798,39 @@ protected function _renderTemplate() | |
| $with[] = $this->getBuffer($args['type'], $args['name'], $args['attribs']); | ||
| } | ||
|
|
||
| $this->_template = str_replace('</body>', self::renderIcons() . '</body>', $this->_template); | ||
|
|
||
| return str_replace($replace, $with, $this->_template); | ||
| } | ||
|
|
||
|
|
||
| /** | ||
| * Renders the document icons | ||
| * | ||
| * @return string The svgs markup for the icons | ||
| * | ||
| * @since 4.0.0 | ||
| */ | ||
| public function renderIcons() | ||
| { | ||
| $files = []; | ||
|
|
||
| // Generate the file and load the stylesheet link | ||
| foreach ($this->icons as $key => $icon) | ||
| { | ||
| $file = HTMLHelper::image('vendor/font-awesome/' . $icon . '.svg', '', null,true, 1); | ||
|
|
||
| if ($file) { | ||
| $matches = []; | ||
| preg_match('$(\/media.+)$', $file, $matches); | ||
| $files[] = @file_get_contents(JPATH_ROOT . $matches[1]); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed it does. Nice one. If you want, you can do this as an oneliner Added the same technique now in DPCalendar. |
||
| } | ||
| } | ||
|
|
||
| if (!empty($files)) { | ||
| return '<div style="display:none">' . implode('', $files) . '</div>'; | ||
| } | ||
|
|
||
| return ''; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We made something similar in DPCalendar for J3. While doing that, an idea popped up, to first search in the template for an svg and then in vendor. Like that a template can override the core icons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exactly what is happening here as well thanks to the magic of HTMLHelper::image