mscherer 2 years ago
parent
commit
fcfa67c07a

+ 5 - 7
config/app.default.php

@@ -7,10 +7,10 @@ $config = [
 	// Error handling around 404s
 	'Log' => [
 		'debug' => [
-			'scopes' => false,
+			'scopes' => null,
 		],
 		'error' => [
-			'scopes' => false,
+			'scopes' => null,
 		],
 		'404' => [
 			'file' => '404',
@@ -44,14 +44,12 @@ $config = [
 
 	// Helpers
 	'Format' => [
-		'fontIcons' => [],
 		'templates' => [],
 	],
 	'Google' => [
 	],
-
-	// Experimental - careful
-	'Entity' => [
-		'autoMarkNew' => false,
+	'Icon' => [
+		'sets' => [],
+		'map' => [],
 	],
 ];

+ 4 - 4
src/Controller/Admin/FormatController.php

@@ -5,17 +5,17 @@ namespace Tools\Controller\Admin;
 use App\Controller\AppController;
 
 /**
- * Display format helper specific debug info
+ * Display Icon helper specific debug info
  *
  * Needs Configure:
- * - Format.fontIcons
+ * - Icon.sets and Icon.map
  */
-class FormatController extends AppController {
+class IconsController extends AppController {
 
 	/**
 	 * @return \Cake\Http\Response|null|void
 	 */
-	public function icons() {
+	public function index() {
 	}
 
 }

+ 0 - 85
src/View/Helper/FormatHelper.php

@@ -34,32 +34,7 @@ class FormatHelper extends Helper {
 	/**
 	 * @var array
 	 */
-	protected array $_defaultIcons = [
-		'yes' => 'fa fa-check',
-		'no' => 'fa fa-times',
-		'view' => 'fa fa-eye',
-		'edit' => 'fa fa-pen',
-		'add' => 'fa fa-plus',
-		'delete' => 'fa fa-trash',
-		'prev' => 'fa fa-arrow-left',
-		'next' => 'fa fa-arrow-right',
-		'pro' => 'fa fa-thumbs-up',
-		'contra' => 'fa fa-thumbs-down',
-		'male' => 'fa fa-mars',
-		'female' => 'fa fa-venus',
-		'config' => 'fa fa-cogs',
-		'login' => 'fa fa-sign-in-alt',
-		'logout' => 'fa fa-sign-out-alt',
-	];
-
-	/**
-	 * @var array
-	 */
 	protected array $_defaults = [
-		'fontIcons' => null,
-		'iconNamespaces' => [], // Used to disable auto prefixing if detected
-		'iconNamespace' => 'fa', // Used to be icon,
-		'autoPrefix' => true, // For custom icons "prev" becomes "fa-prev" when iconNamespace is "fa"
 		'templates' => [
 			'icon' => '<i class="{{class}}"{{attributes}}></i>',
 			'ok' => '<span class="ok-{{type}}" style="color:{{color}}"{{attributes}}>{{content}}</span>',
@@ -76,8 +51,6 @@ class FormatHelper extends Helper {
 		$defaults = (array)Configure::read('Format') + $this->_defaults;
 		$config += $defaults;
 
-		$config['fontIcons'] = (array)$config['fontIcons'] + $this->_defaultIcons;
-
 		$this->template = new StringTemplate($config['templates']);
 
 		parent::__construct($View, $config);
@@ -248,64 +221,6 @@ class FormatHelper extends Helper {
 	}
 
 	/**
-	 * Renders a font icon.
-	 *
-	 * @param string $type
-	 * @param array<string, mixed> $options
-	 * @param array<string, mixed> $attributes
-	 * @return string
-	 */
-	protected function _fontIcon($type, $options, $attributes) {
-		$iconClass = $type;
-
-		unset($this->_config['class']);
-
-		$options += $this->_config;
-		if ($options['autoPrefix'] && is_string($options['autoPrefix'])) {
-			$iconClass = $options['autoPrefix'] . '-' . $iconClass;
-		} elseif ($options['autoPrefix'] && $options['iconNamespace']) {
-			$iconClass = $options['iconNamespace'] . '-' . $iconClass;
-		}
-		if ($options['iconNamespace']) {
-			$iconClass = $options['iconNamespace'] . ' ' . $iconClass;
-		}
-
-		if (isset($this->_config['fontIcons'][$type])) {
-			$iconClass = $this->_config['fontIcons'][$type];
-		}
-
-		$defaults = [
-			'class' => 'icon icon-' . $type . ' ' . $iconClass,
-			'escape' => true,
-		];
-		$options += $defaults;
-
-		if (!isset($attributes['title'])) {
-			$attributes['title'] = ucfirst($type);
-		}
-		if (!isset($options['translate']) || $options['translate'] !== false) {
-			$attributes['title'] = __($attributes['title']);
-		}
-
-		if (isset($attributes['class'])) {
-			$options['class'] .= ' ' . $attributes['class'];
-			unset($attributes['class']);
-		}
-
-		$attributes += [
-			'data-placement' => 'bottom',
-			'data-toggle' => 'tooltip',
-		];
-		$formatOptions = $attributes + [
-			'escape' => $options['escape'],
-		];
-
-		$options['attributes'] = $this->template->formatAttributes($formatOptions);
-
-		return $this->template->format('icon', $options);
-	}
-
-	/**
 	 * Displays yes/no symbol.
 	 *
 	 * @param int|bool $value Value

+ 4 - 4
templates/Admin/Format/icons.php

@@ -7,14 +7,14 @@
 <div class="row">
 	<div class="col-lg-6">
 		<h1>Font Icons</h1>
-		<p>As configured in app.php (through `Format.fontIcons`)</p>
+		<p>As configured in app.php (through `Icon.map`)</p>
 
 		<?php
-		$icons = $this->Format->getConfig('fontIcons');
+		$icons = $this->Icon->getConfig('map');
 		?>
 		<ul>
-		<?php foreach ($icons as $icon => $class) { ?>
-			<li><?php echo $this->Icon->render($icon); ?> - <?php echo h($icon)?> (<?php echo h($class)?>)</li>
+		<?php foreach ($icons as $name => $icon) { ?>
+			<li><?php echo $this->Icon->render($icon); ?> - <?php echo h($name)?> (<?php echo h($icon)?>)</li>
 		<?php } ?>
 		</ul>
 

+ 1 - 1
templates/Admin/Tools/index.php

@@ -10,7 +10,7 @@
 
 		<h2>Helper debugging</h2>
 		<ul>
-			<li><?php echo $this->Html->link('Format and font icons', ['controller' => 'Format', 'action' => 'icons']); ?></li>
+			<li><?php echo $this->Html->link('Icon helper and font icons', ['controller' => 'Icons', 'action' => 'index']); ?></li>
 		</ul>
 	</div>
 </div>

+ 1 - 1
tests/TestCase/Controller/Admin/FormatControllerTest.php

@@ -8,7 +8,7 @@ use Shim\TestSuite\TestCase;
 use Tools\View\Icon\BootstrapIcon;
 
 /**
- * @uses \Tools\Controller\Admin\FormatController
+ * @uses \Tools\Controller\Admin\IconsController
  */
 class FormatControllerTest extends TestCase {