chg: [helpers] Added documentation and tweakings
parent
aebbb3ebd8
commit
3806533abb
|
@ -3,11 +3,11 @@
|
|||
* Bootstrap Tabs helper
|
||||
* Options:
|
||||
* [style]
|
||||
* - fill: Should the navigation occupies all space
|
||||
* - justify: Should the navigation be justified (accept: ['center', 'end'])
|
||||
* - pills: Should the tabs be pills
|
||||
* - vertical: Should the navigation be placed on the left side of the content
|
||||
* - vertical-size: How many boostrap cols be used for the navigation (only used when `vertical` is true)
|
||||
* - fill: Should the navigation items occupies all space
|
||||
* - justify: Should the navigation items be justified (accept: ['center', 'end'])
|
||||
* - pills: Should the navigation items be pills
|
||||
* - vertical: Should the navigation bar be placed on the left side of the content
|
||||
* - vertical-size: Specify how many boostrap's `cols` should be used for the navigation (only used when `vertical` is true)
|
||||
* - card: Should the navigation be placed in a bootstrap card
|
||||
* - nav-class: additional class to add to the nav container
|
||||
* - content-class: additional class to add to the content container
|
||||
|
@ -55,8 +55,8 @@ class BootstrapHelper extends Helper
|
|||
class BootstrapTabs extends Helper
|
||||
{
|
||||
private $defaultOptions = [
|
||||
'nav-fill' => false,
|
||||
'nav-justify' => false,
|
||||
'fill' => false,
|
||||
'justify' => false,
|
||||
'pills' => false,
|
||||
'vertical' => false,
|
||||
'vertical-size' => 3,
|
||||
|
@ -71,7 +71,7 @@ class BootstrapTabs extends Helper
|
|||
];
|
||||
|
||||
private $allowedOptionValues = [
|
||||
'nav-justify' => [false, 'center', 'end'],
|
||||
'justify' => [false, 'center', 'end'],
|
||||
];
|
||||
|
||||
private $options = null;
|
||||
|
@ -97,8 +97,8 @@ class BootstrapTabs extends Helper
|
|||
|
||||
];
|
||||
|
||||
if (!empty($this->options['nav-justify'])) {
|
||||
$this->bsClasses['nav'][] = 'justify-content-' . $this->options['nav-justify'];
|
||||
if (!empty($this->options['justify'])) {
|
||||
$this->bsClasses['nav'][] = 'justify-content-' . $this->options['justify'];
|
||||
}
|
||||
|
||||
if ($this->options['pills']) {
|
||||
|
@ -116,10 +116,10 @@ class BootstrapTabs extends Helper
|
|||
}
|
||||
}
|
||||
|
||||
if ($this->options['nav-fill']) {
|
||||
if ($this->options['fill']) {
|
||||
$this->bsClasses['nav'][] = 'nav-fill';
|
||||
}
|
||||
if ($this->options['nav-justify']) {
|
||||
if ($this->options['justify']) {
|
||||
$this->bsClasses['nav'][] = 'nav-justify';
|
||||
}
|
||||
|
||||
|
@ -160,9 +160,6 @@ class BootstrapTabs extends Helper
|
|||
if (empty($this->data['navs'])) {
|
||||
throw new InvalidArgumentException(__('No navigation data provided'));
|
||||
}
|
||||
if ($this->options['card'] && $this->options['vertical']) {
|
||||
throw new InvalidArgumentException(__('`card` option can only be used on horizontal mode'));
|
||||
}
|
||||
}
|
||||
|
||||
private function genTabs()
|
||||
|
@ -198,11 +195,11 @@ class BootstrapTabs extends Helper
|
|||
|
||||
private function genVerticalTabs()
|
||||
{
|
||||
$html = $this->genNode('div', ['class' => ['row']]);;
|
||||
$html .= $this->genNode('div', ['class' => 'col-' . $this->options['vertical-size']]);
|
||||
$html = $this->genNode('div', ['class' => ['row', ($this->options['card'] ? 'card flex-row' : '')]]);
|
||||
$html .= $this->genNode('div', ['class' => ['col-' . $this->options['vertical-size'], ($this->options['card'] ? 'card-header border-right' : '')]]);
|
||||
$html .= $this->genNav();
|
||||
$html .= '</div>';
|
||||
$html .= $this->genNode('div', ['class' => 'col-' . (12 - $this->options['vertical-size'])]);
|
||||
$html .= $this->genNode('div', ['class' => ['col-' . (12 - $this->options['vertical-size']), ($this->options['card'] ? 'card-body2' : '')]]);
|
||||
$html .= $this->genContent();
|
||||
$html .= '</div>';
|
||||
$html .= '</div>';
|
||||
|
|
|
@ -8,31 +8,45 @@ use Cake\Utility\Hash;
|
|||
class StringFromPathHelper extends Helper
|
||||
{
|
||||
private $defaultOptions = [
|
||||
'sanitize' => true,
|
||||
'highlight' => false,
|
||||
'sanitize' => true, // Should the variables to be injected into the string be sanitized. (ignored with the function)
|
||||
'highlight' => false, // Should the extracted data be highlighted
|
||||
];
|
||||
|
||||
public function buildStringFromDataPath(String $str, $data=[], array $dataPaths=[], array $options=[])
|
||||
/**
|
||||
* buildStringFromDataPath Inject data into a string at the correct place
|
||||
*
|
||||
* @param String $str The string that will have its arguements replaced by their value
|
||||
* @param mixed $data The data from which the value of datapath arguement will be taken
|
||||
* @param array $strArgs The arguments to be injected into the string.
|
||||
* - Each argument ca be of mixed type:
|
||||
* - String: A cakephp's Hash datapath used to extract the data
|
||||
* - array: can contain a key of either
|
||||
* - `datapath`: A cakephp's Hash datapath used to extract the data
|
||||
* - `raw`: A raw string to be injecte as-is
|
||||
* - `function`: A function to be executed with its $strArgs being passed
|
||||
* @param array $options Allows to configure the behavior of the function
|
||||
* @return String
|
||||
*/
|
||||
public function buildStringFromDataPath(String $str, $data=[], array $strArgs=[], array $options=[])
|
||||
{
|
||||
$options = array_merge($this->defaultOptions, $options);
|
||||
if (!empty($dataPaths)) {
|
||||
if (!empty($strArgs)) {
|
||||
$extractedVars = [];
|
||||
foreach ($dataPaths as $i => $dataPath) {
|
||||
foreach ($strArgs as $i => $strArg) {
|
||||
$varValue = '';
|
||||
if (is_array($dataPath)) {
|
||||
if (is_array($strArg)) {
|
||||
$varValue = '';
|
||||
if (!empty($dataPath['datapath'])) {
|
||||
$varValue = Hash::get($data, $dataPath['datapath']);
|
||||
} else if (!empty($dataPath['raw'])) {
|
||||
$varValue = $dataPath['raw'];
|
||||
} else if (!empty($dataPath['function'])) {
|
||||
$varValue = $dataPath['function']($data, $dataPath);
|
||||
if (!empty($strArg['datapath'])) {
|
||||
$varValue = Hash::get($data, $strArg['datapath']);
|
||||
} else if (!empty($strArg['raw'])) {
|
||||
$varValue = $strArg['raw'];
|
||||
} else if (!empty($strArg['function'])) {
|
||||
$varValue = $strArg['function']($data, $strArg);
|
||||
}
|
||||
// $extractedVars[] = $varValue;
|
||||
} else {
|
||||
$varValue = Hash::get($data, $dataPath);
|
||||
$varValue = Hash::get($data, $strArg);
|
||||
}
|
||||
if (empty($dataPath['function'])) {
|
||||
if (empty($strArg['function'])) {
|
||||
$varValue = $options['sanitize'] ? h($varValue) : $varValue;
|
||||
}
|
||||
$extractedVars[] = $varValue;
|
||||
|
|
Loading…
Reference in New Issue