Skip to content

Commit

Permalink
Create UI Icons module and display bootstrap icons
Browse files Browse the repository at this point in the history
  • Loading branch information
celdia committed May 25, 2024
0 parents commit af5ba75
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Controller/IconDisplayController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php


namespace Drupal\ui_icons\Controller;

use Drupal\Core\Controller\ControllerBase;

/**
* Class IconDisplayController.
*/
class IconDisplayController extends ControllerBase
{

/**
* Display icons.
*
* @return array
* Return render array.
*/
public function display()
{
$build = [];
$iconsets = \Drupal::service('strategy.manager.iconset')->getIconsets();
foreach ($iconsets as $iconset_id=>$label) {
$iconset = \Drupal::service('strategy.manager.iconset')->getInstance($iconset_id);
$icons = $iconset->getIcons();
$build[] = [
'#type' => 'html_tag',
'#tag' => 'h2',
'#value' => $label,
];
foreach ($icons as $icon_id => $icon) {
$build[] = $iconset->build($icon_id);
}
}
return $build;
}

}
1 change: 1 addition & 0 deletions src/Plugin/IconHandler/CustomIconHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
6 changes: 6 additions & 0 deletions ui_icons.iconset.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bootstrap_icons:
label: 'Bootstrap Icons'
plugin: 'svg'
assets:
- '/libraries/bootstrap-icons/house.svg'
- '/libraries/bootstrap-icons/people.svg'
8 changes: 8 additions & 0 deletions ui_icons.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: 'UI Icons'
type: module
description: 'A custom module to display icons using Iconset'
core_version_requirement: ^9 || ^10
package: Custom
dependencies:
- iconset:iconset

7 changes: 7 additions & 0 deletions ui_icons.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ui_icons_display.display:
path: '/admin/config/media/iconset/icon-display'
defaults:
_controller: '\Drupal\ui_icons\Controller\IconDisplayController::display'
_title: 'Bootstrap Icon Display'
requirements:
_permission: 'access content'

0 comments on commit af5ba75

Please sign in to comment.