Skip to content
Snippets Groups Projects
Commit ae264278 authored by Shibin Das's avatar Shibin Das
Browse files

feat: #3354629 Add support for line_awesome

parent 045feaaa
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,13 @@ file included in module for more details about configuration.
- dashboard_menu_groups : Group headings for individual links in Dashboard.
- dashboard_menu : Individual links to be exposed on dashboard.
### Icons
Following icon libraries are supported. Please visit the relevant project page on how to install and enable them.
- Fontawesome : https://www.drupal.org/project/fontawesome
- Line Awesome : https://www.drupal.org/project/line_awesome
## TROUBLESHOOTING
* If no icons shows up in Dashboard:
......
......@@ -3,6 +3,3 @@ description: Dashboard so simple that even a monkey could use it.
core_version_requirement: ^8.8 || ^9 || ^10
package: Administration
type: module
dependencies:
- fontawesome:fontawesome
<?php
/**
* @file
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
......@@ -30,8 +35,13 @@ function banana_dashboard_help($route_name, RouteMatchInterface $route_match) {
function banana_dashboard_theme($existing, $type, $theme, $path) {
return [
'banana_dashboard' => [
'variables' => ['title' => '', 'dashboard_menu' => '']
]
'variables' => [
'title' => '',
'dashboard_menu' => '',
'icon_class_prefix' => 'fa fa-',
'tag' => 'i',
],
],
];
}
......
access banana dashboard:
title: 'Access Banana Dashboard'
description: 'A custom permission for providing the access to the banana dashboard.'
restrict access: TRUE
administer banana dashbaord:
title: 'Administer Banana Dashboard'
description: 'A custom permission for providing the access to the banana dashboard.'
restrict access: TRUE
\ No newline at end of file
......@@ -4,4 +4,12 @@ banana_dashboard.banana_dash:
_controller: '\Drupal\banana_dashboard\Controller\BananaDashboardController::getBananaDashboard'
_title: 'Dashboard'
requirements:
_permission: 'access banana dashboard'
\ No newline at end of file
_permission: 'access banana dashboard'
banana_dashboard.settings:
path: '/admin/config/system/banana-dashboard-settings'
defaults:
_title: 'Banana Dashboard Settings'
_form: 'Drupal\banana_dashboard\Form\SettingsForm'
requirements:
_permission: 'administer banana dashbaord'
......@@ -20,8 +20,13 @@
"issues": "https://www.drupal.org/project/issues/banana_dashboard",
"source": "http://cgit.drupalcode.org/banana_dashboard"
},
"require": {},
"require-dev": {
"vijaycs85/drupal-quality-checker": "dev-master"
"axelerant/drupal-quality-checker": "^1.3"
},
"config": {
"allow-plugins": {
"phpro/grumphp-shim": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
This diff is collapsed.
# Schema for the configuration files of the Banana dashboard module.
banana_dashboard.settings:
type: config_object
label: 'Banana Dashboard Settings'
mapping:
icon_library:
type: string
label: 'Icon Library'
parameters:
ascii:
failed: vendor/vijaycs85/drupal-quality-checker/resources/ascii/grumpy.txt
succeeded: vendor/vijaycs85/drupal-quality-checker/resources/ascii/happy.txt
git_dir: .
bin_dir: vendor/bin
grumphp:
tasks:
phplint: ~
yamllint: ~
composer: ~
composer_normalize: ~
jsonlint: ~
twigcs:
path: 'src'
ruleset: 'FriendsOfTwig\Twigcs\Ruleset\Official'
exclude:
- core
- modules/contrib
- themes/contrib
- profiles/contrib
phpcpd:
directory: './src'
directory: ['./src']
phpcs:
standard: Drupal
standard:
- phpcs.xml
ignore_patterns:
- .github
- .gitlab
- /config/
- /drush/
- /web/robots.txt
- /web/sites/default/
- bower_components
- node_modules
- vendor
- /vendor
triggered_by:
- php
- module
......@@ -31,4 +41,8 @@ parameters:
- css
- info
- txt
- md
\ No newline at end of file
phpmd:
whitelist_patterns:
- /^src\/(.*)/
ruleset: ['phpmd.xml']
triggered_by: ['php']
phpcs.xml 0 → 100644
<?xml version="1.0" ?>
<!--
Based on Examples for Developers phpcs.xml.dist. Modified for use for Drupal
projects. See https://git.drupalcode.org/project/examples/blob/HEAD/phpcs.xml.dist
for source.
-->
<ruleset name="AxelerantDrupal">
<description>Axelerant baseline rules for PHP CodeSniffer</description>
<file>.</file>
<!-- PHPCS Arguments -->
<arg name="extensions" value="inc,info.yml,install,module,php,profile,test,theme" />
<arg name="colors" />
<!--Allow global variables in settings file.-->
<rule ref="DrupalPractice.CodeAnalysis.VariableAnalysis.UndefinedVariable">
<exclude-pattern>settings(\.[a-zA-Z0-9]+)?\.php</exclude-pattern>
</rule>
<!--Allow section separators in settings.php file.-->
<rule ref="DrupalPractice.Commenting.CommentEmptyLine.SpacingAfter">
<exclude-pattern>settings(\.[a-zA-Z0-9]+)?\.php</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.InlineComment.InvalidEndChar">
<exclude-pattern>settings(\.[a-zA-Z0-9]+)?\.php</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.InlineComment.NoSpaceBefore">
<exclude-pattern>settings(\.[a-zA-Z0-9]+)?\.php</exclude-pattern>
</rule>
<rule ref="Drupal.Commenting.InlineComment.SpacingAfter">
<exclude-pattern>settings(\.[a-zA-Z0-9]+)?\.php</exclude-pattern>
</rule>
<!-- Drupal sniffs -->
<rule ref="Drupal.Arrays.Array">
<!-- Sniff for these errors: CommaLastItem -->
<exclude name="Drupal.Arrays.Array.ArrayClosingIndentation"/>
<exclude name="Drupal.Arrays.Array.ArrayIndentation"/>
<exclude name="Drupal.Arrays.Array.LongLineDeclaration"/>
</rule>
<rule ref="Drupal.Classes.ClassCreateInstance"/>
<rule ref="Drupal.Classes.ClassDeclaration"/>
<rule ref="Drupal.Classes.FullyQualifiedNamespace"/>
<rule ref="Drupal.Classes.InterfaceName"/>
<rule ref="Drupal.Classes.UnusedUseStatement"/>
<rule ref="Drupal.Classes.UseLeadingBackslash"/>
<rule ref="Drupal.CSS.ClassDefinitionNameSpacing"/>
<rule ref="Drupal.CSS.ColourDefinition"/>
<rule ref="Drupal.Commenting.ClassComment">
<exclude name="Drupal.Commenting.ClassComment.Missing"/>
</rule>
<rule ref="Drupal.Commenting.DataTypeNamespace"/>
<rule ref="Drupal.Commenting.DocComment">
<!-- Sniff for these errors: SpacingAfterTagGroup, WrongEnd, SpacingBetween,
ContentAfterOpen, SpacingBeforeShort, TagValueIndent, ShortStartSpace,
SpacingAfter, LongNotCapital -->
<!-- ParamNotFirst still not decided for PHPUnit-based tests.
@see https://www.drupal.org/node/2253915 -->
<exclude name="Drupal.Commenting.DocComment.ParamNotFirst"/>
<exclude name="Drupal.Commenting.DocComment.SpacingBeforeTags"/>
<exclude name="Drupal.Commenting.DocComment.LongFullStop"/>
<exclude name="Drupal.Commenting.DocComment.ShortNotCapital"/>
<exclude name="Drupal.Commenting.DocComment.ShortFullStop"/>
<!-- TagsNotGrouped and ParamGroup have false-positives.
@see https://www.drupal.org/node/2060925 -->
<exclude name="Drupal.Commenting.DocComment.TagsNotGrouped"/>
<exclude name="Drupal.Commenting.DocComment.ParamGroup"/>
<exclude name="Drupal.Commenting.DocComment.ShortSingleLine"/>
<exclude name="Drupal.Commenting.DocComment.TagGroupSpacing"/>
<exclude name="Drupal.Commenting.DocComment.MissingShort"/>
</rule>
<rule ref="Drupal.Commenting.DocCommentStar"/>
<rule ref="Drupal.Commenting.FileComment"/>
<rule ref="Drupal.Commenting.FunctionComment">
<exclude name="Drupal.Commenting.FunctionComment.IncorrectTypeHint"/>
<exclude name="Drupal.Commenting.FunctionComment.InvalidNoReturn"/>
<exclude name="Drupal.Commenting.FunctionComment.InvalidTypeHint"/>
<exclude name="Drupal.Commenting.FunctionComment.Missing"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingParamComment"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingParamType"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingReturnComment"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingReturnType"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamCommentFullStop"/>
<exclude name="Drupal.Commenting.FunctionComment.ParamMissingDefinition"/>
<exclude name="Drupal.Commenting.FunctionComment.TypeHintMissing"/>
</rule>
<rule ref="Drupal.Commenting.VariableComment">
<!-- Sniff for: DuplicateVar, EmptyVar, InlineVariableName -->
<exclude name="Drupal.Commenting.VariableComment.IncorrectVarType"/>
<exclude name="Drupal.Commenting.VariableComment.MissingVar"/>
<exclude name="Drupal.Commenting.VariableComment.VarOrder"/>
<exclude name="Drupal.Commenting.VariableComment.WrongStyle"/>
</rule>
<rule ref="Drupal.Commenting.InlineComment">
<!-- Sniff for: NoSpaceBefore, WrongStyle -->
<exclude name="Drupal.Commenting.InlineComment.DocBlock"/>
<exclude name="Drupal.Commenting.InlineComment.InvalidEndChar"/>
<exclude name="Drupal.Commenting.InlineComment.NotCapital"/>
<exclude name="Drupal.Commenting.InlineComment.SpacingAfter"/>
<exclude name="Drupal.Commenting.InlineComment.SpacingBefore"/>
</rule>
<rule ref="Drupal.Commenting.PostStatementComment"/>
<rule ref="Drupal.ControlStructures.ElseIf"/>
<rule ref="Drupal.ControlStructures.ControlSignature"/>
<rule ref="Drupal.ControlStructures.InlineControlStructure"/>
<rule ref="Drupal.Files.EndFileNewline"/>
<rule ref="Drupal.Files.FileEncoding"/>
<rule ref="Drupal.Files.TxtFileLineLength"/>
<rule ref="Drupal.Formatting.MultiLineAssignment"/>
<rule ref="Drupal.Formatting.MultipleStatementAlignment"/>
<rule ref="Drupal.Formatting.SpaceInlineIf"/>
<rule ref="Drupal.Formatting.SpaceUnaryOperator"/>
<rule ref="Drupal.Functions.DiscouragedFunctions"/>
<rule ref="Drupal.Functions.FunctionDeclaration"/>
<rule ref="Drupal.InfoFiles.AutoAddedKeys"/>
<rule ref="Drupal.InfoFiles.ClassFiles"/>
<rule ref="Drupal.InfoFiles.DuplicateEntry"/>
<rule ref="Drupal.InfoFiles.Required"/>
<rule ref="Drupal.Methods.MethodDeclaration">
<!-- Silence method name underscore warning which is covered already in
Drupal.NamingConventions.ValidFunctionName.ScopeNotCamelCaps. -->
<exclude name="Drupal.Methods.MethodDeclaration.Underscore"/>
</rule>
<rule ref="Drupal.NamingConventions.ValidVariableName">
<!-- Sniff for: LowerStart -->
<exclude name="Drupal.NamingConventions.ValidVariableName.LowerCamelName"/>
</rule>
<rule ref="Drupal.Scope.MethodScope"/>
<rule ref="Drupal.Semantics.EmptyInstall"/>
<rule ref="Drupal.Semantics.FunctionAlias"/>
<rule ref="Drupal.Semantics.FunctionT">
<exclude name="Drupal.Semantics.FunctionT.NotLiteralString"/>
<exclude name="Drupal.Semantics.FunctionT.ConcatString"/>
</rule>
<rule ref="Drupal.Semantics.FunctionWatchdog"/>
<rule ref="Drupal.Semantics.InstallHooks"/>
<rule ref="Drupal.Semantics.LStringTranslatable"/>
<rule ref="Drupal.Semantics.PregSecurity"/>
<rule ref="Drupal.Semantics.TInHookMenu"/>
<rule ref="Drupal.Semantics.TInHookSchema"/>
<rule ref="Drupal.Strings.UnnecessaryStringConcat"/>
<rule ref="Drupal.WhiteSpace.CloseBracketSpacing"/>
<rule ref="Drupal.WhiteSpace.Comma"/>
<rule ref="Drupal.WhiteSpace.EmptyLines"/>
<rule ref="Drupal.WhiteSpace.Namespace"/>
<rule ref="Drupal.WhiteSpace.ObjectOperatorIndent"/>
<rule ref="Drupal.WhiteSpace.ObjectOperatorSpacing"/>
<rule ref="Drupal.WhiteSpace.OpenBracketSpacing"/>
<rule ref="Drupal.WhiteSpace.OpenTagNewline"/>
<rule ref="Drupal.WhiteSpace.ScopeClosingBrace"/>
<rule ref="Drupal.WhiteSpace.ScopeIndent"/>
<!-- Drupal Practice sniffs -->
<rule ref="DrupalPractice.Commenting.ExpectedException"/>
<!-- Generic sniffs -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.CodeAnalysis.EmptyPHPStatement" />
<rule ref="Generic.Files.ByteOrderMark"/>
<rule ref="Generic.Files.LineEndings"/>
<rule ref="Generic.Formatting.SpaceAfterCast"/>
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie">
<properties>
<property name="checkClosures" value="true"/>
</properties>
</rule>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.LowerCaseKeyword"/>
<rule ref="Generic.PHP.UpperCaseConstant"/>
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<!-- Internal sniffs -->
<rule ref="Internal.NoCodeFound">
<!-- No PHP code in *.yml -->
<exclude-pattern>*.yml</exclude-pattern>
</rule>
<!-- MySource sniffs -->
<rule ref="MySource.Debug.DebugCode"/>
<!-- PEAR sniffs -->
<rule ref="PEAR.Files.IncludingFile"/>
<!-- Disable some error messages that we do not want. -->
<rule ref="PEAR.Files.IncludingFile.UseIncludeOnce">
<severity>0</severity>
</rule>
<rule ref="PEAR.Files.IncludingFile.UseInclude">
<severity>0</severity>
</rule>
<rule ref="PEAR.Files.IncludingFile.UseRequireOnce">
<severity>0</severity>
</rule>
<rule ref="PEAR.Files.IncludingFile.UseRequire">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.ValidDefaultValue"/>
<!-- PEAR sniffs -->
<rule ref="PEAR.Functions.FunctionCallSignature"/>
<!-- The sniffs inside PEAR.Functions.FunctionCallSignature silenced below are
also silenced in Drupal CS' ruleset.xml. The code below is a 1-on-1 copy
from that file. -->
<!-- Disable some error messages that we already cover. -->
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceAfterOpenBracket">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.SpaceBeforeCloseBracket">
<severity>0</severity>
</rule>
<!-- Disable some error messages that we do not want. -->
<rule ref="PEAR.Functions.FunctionCallSignature.Indent">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.OpeningIndent">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.ContentAfterOpenBracket">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.CloseBracketLine">
<severity>0</severity>
</rule>
<rule ref="PEAR.Functions.FunctionCallSignature.EmptyLine">
<severity>0</severity>
</rule>
<!-- PSR-2 sniffs -->
<rule ref="PSR2.Classes.PropertyDeclaration">
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore"/>
</rule>
<rule ref="PSR2.Namespaces.NamespaceDeclaration"/>
<rule ref="PSR2.Namespaces.UseDeclaration">
<exclude name="PSR2.Namespaces.UseDeclaration.UseAfterNamespace"/>
</rule>
<!-- Squiz sniffs -->
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
<rule ref="Squiz.Arrays.ArrayDeclaration">
<exclude name="Squiz.Arrays.ArrayDeclaration.NoKeySpecified"/>
<exclude name="Squiz.Arrays.ArrayDeclaration.KeySpecified"/>
</rule>
<!-- Disable some error messages that we do not want. -->
<rule ref="Squiz.Arrays.ArrayDeclaration.CloseBraceNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.DoubleArrowNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.FirstValueNoNewline">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.KeyNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.MultiLineNotAllowed">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.NoComma">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.NoCommaAfterLast">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.NotLowerCase">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.SingleLineNotAllowed">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNotAligned">
<severity>0</severity>
</rule>
<rule ref="Squiz.Arrays.ArrayDeclaration.ValueNoNewline">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration"/>
<!-- Disable some error messages that we already cover. -->
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.AsNotLower">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceAfterOpen">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.SpaceBeforeClose">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForLoopDeclaration"/>
<!-- Disable some error messages that we already cover. -->
<rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterOpen">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingBeforeClose">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration"/>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.BraceOnSameLine">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace">
<severity>0</severity>
</rule>
<!-- Standard yet to be finalized on this (https://www.drupal.org/node/1539712). -->
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.FirstParamSpacing">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.Indent">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.MultiLineFunctionDeclaration.CloseBracketLine">
<severity>0</severity>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
<properties>
<property name="equalsSpacing" value="1"/>
</properties>
</rule>
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.NoSpaceBeforeArg">
<severity>0</severity>
</rule>
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="spacing" value="1"/>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
<properties>
<property name="spacing" value="1"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing" />
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<!-- Zend sniffs -->
<rule ref="Zend.Files.ClosingTag"/>
</ruleset>
<?xml version="1.0"?>
<ruleset name="PHPMD ruleset for Drupal"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
Custom ruleset for Drupal projects at Axelerant
</description>
<!-- Import common rulesets -->
<rule ref="rulesets/codesize.xml"/>
<rule ref="rulesets/design.xml"/>
<rule ref="rulesets/naming.xml"/>
<rule ref="rulesets/unusedcode.xml"/>
<!-- Import entire clean code rule set, modify StaticAccess rule -->
<rule ref="rulesets/cleancode.xml">
<exclude name="StaticAccess"/>
<exclude name="MissingImport"/>
</rule>
<rule ref="rulesets/cleancode.xml/StaticAccess">
<properties>
<property name="exceptions">
<value>
\DateTime,
\DateInterval,
\DateTimeZone,
\Drupal\Component\Plugin\Factory\DefaultFactory,
\Drupal\Component\Utility\Html,
\Drupal\Component\Utility\UrlHelper,
\Drupal\Core\Access\AccessResult,
\Drupal\Core\Url,
\Drupal\Core\Cache\Cache,
\Drupal\Core\Render\Element,
\Drupal\Core\Render\Element\Checkboxes,
\Drupal\Core\Annotation\Action,
\Drupal\Core\Site\Settings,
</value>
</property>
</properties>
</rule>
</ruleset>
......@@ -2,6 +2,8 @@
namespace Drupal\banana_dashboard\Controller;
use Drupal\Core\Config\ImmutableConfig;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\core\Url;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -19,14 +21,22 @@ class BananaDashboardController extends ControllerBase {
*/
protected $pathValidator;
/**
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* {@inheritdoc}
*
* @param \Drupal\Core\Path\PathValidatorInterface $path_validator
* @param \Drupal\Core\Path\PathValidatorInterface $path_validator
* The path validator.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(PathValidatorInterface $path_validator) {
public function __construct(PathValidatorInterface $path_validator, ConfigFactoryInterface $config_factory) {
$this->pathValidator = $path_validator;
$this->configFactory = $config_factory;
}
/**
......@@ -34,8 +44,9 @@ class BananaDashboardController extends ControllerBase {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('path.validator')
);
$container->get('path.validator'),
$container->get('config.factory'),
);
}
/**
......@@ -44,8 +55,10 @@ class BananaDashboardController extends ControllerBase {
* @return array
* A simple renderable array.
*
* @SuppressWarnings(PHPMD.StaticAccess)
*/
public function getBananaDashboard() {
$config = $this->configFactory->get('banana_dashboard.settings');
$dashboard_menu = banana_dashboard_get('dashboard_menu', []);
foreach ($dashboard_menu as $key => $value) {
if (empty($value['url']) || !$this->pathValidator->isValid(substr($value['url'], 1))) {
......@@ -80,10 +93,32 @@ class BananaDashboardController extends ControllerBase {
}
}
return [
'#theme' => 'banana_dashboard',
'#title' => $dashboard['title'],
'#dashboard_menu' => $menu_group,
];
'#theme' => 'banana_dashboard',
'#title' => $dashboard['title'],
'#dashboard_menu' => $menu_group,
'#icon_class_prefix' => $this->getIconClassPrefix($config),
];
}
/**
* Get Icon Class prefix to be used in markup.
*
* @param \Drupal\Core\Config\ImmutableConfig $config
*
* @return string
*/
protected function getIconClassPrefix(ImmutableConfig $config): string {
$icon_library = $config->get('icon_library');
switch ($icon_library) {
case 'line_awesome':
$icon_class_prefix = 'las la-';
break;
case 'fontawesome':
default:
$icon_class_prefix = 'fa fa-';
}
return $icon_class_prefix;
}
}
<?php
namespace Drupal\banana_dashboard\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Configure Banana dashboard settings for this site.
*/
class SettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'banana_dashboard_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['banana_dashboard.settings'];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['icon_library'] = [
'#type' => 'select',
'#title' => $this->t('Icon Library'),
'#default_value' => $this->config('banana_dashboard.settings')->get('icon_library'),
'#options' => [
'fontawesome' => 'Fontawesome',
'line_awesome' => 'Line Awesome',
],
'#description' => $this->t('The Icon library is not a direct dependency for "Banana Dashboard" module.<br/>
Make sure that the library is available on `/admin/banana-dashboard`.<br/>
Visit Icon Library projects for <a href="https://www.drupal.org/project/fontawesome">fontawesome</a> or
<a href="https://www.drupal.org/project/line_awesome">line_awesome</a>
to learn more about how to install and enable the library.'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('banana_dashboard.settings')
->set('icon_library', $form_state->getValue('icon_library'))
->save();
parent::submitForm($form, $form_state);
}
}
......@@ -7,7 +7,7 @@
{% for menu_item in menu_items %}
<li class="dashboard-menu-item">
<a href="{{ menu_item['url'] }}" class="banana-dashboard-menu-link">
<i class="fa fa-{{ menu_item['icon'] }}"></i>
<i class="{{ icon_class_prefix|default('fa fa-') }}{{ menu_item['icon'] }}"></i>
<div class="title">{{ menu_item['title'] }}</div>
</a>
</li>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment