code quality improvements + add boolean in a ctive link helper to check if url is active without displaying link
This commit is contained in:
@@ -3,7 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace CheeseCake\Controller;
|
||||
|
||||
use App\Controller\AppController as BaseController;
|
||||
use Cake\Controller\Controller;
|
||||
|
||||
class AppController extends BaseController {
|
||||
class AppController extends Controller {
|
||||
}
|
||||
|
||||
@@ -5,12 +5,15 @@ namespace CheeseCake\View\Helper;
|
||||
|
||||
use Cake\Routing\Router;
|
||||
use Cake\View\Helper;
|
||||
use Cake\View\Helper\HtmlHelper;
|
||||
|
||||
/**
|
||||
* ActiveLink helper
|
||||
*
|
||||
* @property HtmlHelper $Html
|
||||
*/
|
||||
class ActiveLinkHelper extends Helper {
|
||||
|
||||
|
||||
/**
|
||||
* Default configuration.
|
||||
*
|
||||
@@ -42,12 +45,12 @@ class ActiveLinkHelper extends Helper {
|
||||
if (!array_key_exists('target', $options) || !$currentUrl) {
|
||||
return $this->Html->link($title, $url, $options);
|
||||
}
|
||||
|
||||
$target = $options['target'];
|
||||
$activeClass = $options['activeClass'] ?? $this->getConfig('activeClass');
|
||||
|
||||
unset($options['target']);
|
||||
unset($options['activeClass']);
|
||||
|
||||
$activeClass = $options['activeClass'] ?? $this->getConfig('activeClass');
|
||||
unset($options['target']);
|
||||
unset($options['activeClass']);
|
||||
|
||||
if (is_string($target)) {
|
||||
return $this->_linkFromStringTarget($currentUrl, $target, $title, $url, $activeClass, $options);
|
||||
}
|
||||
@@ -78,7 +81,7 @@ class ActiveLinkHelper extends Helper {
|
||||
}
|
||||
|
||||
$options['class'] = $this->_addClass($options, $activeClass);
|
||||
|
||||
|
||||
return $this->Html->link($title, $url, $options);
|
||||
}
|
||||
|
||||
@@ -113,18 +116,20 @@ class ActiveLinkHelper extends Helper {
|
||||
|
||||
/**
|
||||
* @param array $providedOptions
|
||||
* @param string $toAdd
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _addClass(array $providedOptions, string $toAdd): string {
|
||||
return array_key_exists('class', $providedOptions) ? $providedOptions['class'] . ' ' . $toAdd : $toAdd;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* @param array $current
|
||||
* @param string $targetString
|
||||
* @param string $title
|
||||
* @param array|string|null $url
|
||||
* @param string $activeClass
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
@@ -138,8 +143,8 @@ class ActiveLinkHelper extends Helper {
|
||||
|
||||
return $this->Html->link($title, $url, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* @param array $current
|
||||
* @param array $targetUrl
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user