From ebed368dc723ec392188283c1460dcb215eed05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Fri, 11 Aug 2017 15:50:57 +0200 Subject: [PATCH 01/95] Update HtmlHelper. --- README.md | 17 ++- src/View/Helper/HtmlHelper.php | 126 +++++------------- tests/TestCase/View/Helper/HtmlHelperTest.php | 59 ++++---- 3 files changed, 78 insertions(+), 124 deletions(-) diff --git a/README.md b/README.md index ff08cb7..e4110c1 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,30 @@ CakePHP 3.x Helpers for Bootstrap CakePHP 3.x Helpers to generate HTML with @Twitter Boostrap style: `Breadcrumbs`, `Flash`, `Form`, `Html`, `Modal`, `Navbar`, `Panel` and `Paginator` helpers available! +Work in progress +================ + +I am currently working on rewritting the helpers for Bootstrap 4, current work status: + +- FlashHelper - 0% +- FormHelper - 0% +- HtmlHelper - 100% +- ModalHelper - 0% +- NavbarHelper - 0% +- PaginatorHelper - 0% +- PanelHelper - 0% + How to... ? =========== #### Installation -If you want the latest **Bootstrap 3** version of the plugin: +If you want the latest **Bootstrap 4** version of the plugin: - Add the plugin to your `composer.json` (see below if you want to use another branch / version): ``` -composer require holt59/cakephp3-bootstrap-helpers:dev-master +composer require holt59/cakephp3-bootstrap-helpers:v4-updated ``` - Load the plugin in your `config/bootstrap.php`: diff --git a/src/View/Helper/HtmlHelper.php b/src/View/Helper/HtmlHelper.php index ffcec6b..93e26cc 100644 --- a/src/View/Helper/HtmlHelper.php +++ b/src/View/Helper/HtmlHelper.php @@ -73,24 +73,23 @@ class HtmlHelper extends \Cake\View\Helper\HtmlHelper { 'javascriptend' => '', // New templates for Bootstrap - 'icon' => '', - 'label' => '{{content}}', - 'badge' => '{{content}}', + 'icon' => '', + 'badge' => '{{content}}', 'alert' => '', 'alertCloseButton' => '', 'alertCloseContent' => '', 'tooltip' => '<{{tag}} data-toggle="{{toggle}}" data-placement="{{placement}}" title="{{tooltip}}"{{attrs}}>{{content}}', 'progressBar' => -'
{{inner}}
', 'progressBarInner' => '{{width}}%', 'progressBarContainer' => '
{{content}}
', - 'dropdownMenu' => '', - 'dropdownMenuItem' => '{{content}}', - 'dropdownMenuHeader' => '', - 'dropdownMenuDivider' => '' + 'dropdownMenu' => '', + 'dropdownMenuItem' => '{{content}}', + 'dropdownMenuHeader' => '', + 'dropdownMenuDivider' => '' ], 'templateClass' => 'Bootstrap\View\EnhancedStringTemplate', 'tooltip' => [ @@ -98,7 +97,7 @@ class HtmlHelper extends \Cake\View\Helper\HtmlHelper { 'placement' => 'right', 'toggle' => 'tooltip' ], - 'label' => [ + 'badge' => [ 'type' => 'default' ], 'alert' => [ @@ -142,39 +141,40 @@ public function link($title, $url = null, array $options = []) { } /** - * Create a Twitter Bootstrap span label. - * - * The second parameter may either be `$type` or `$options` (in which case - * the third parameter is not used, and the label type can be specified in the - * `$options` array). + * @deprecated 4.0.0 Use the badge() instead. + */ + public function label($text, $type = null, $options = []) { + return $this->badge($text, $type, $options); + } + + /** + * Create a Twitter Bootstrap badge. * * ### Options * - * - `tag` The HTML tag to use. - * - `type` The type of the label. - * - `templateVars` Provide template variables for the `label` template. + * - `templateVars` Provide template variables for the `badge` template. * - Other attributes will be assigned to the wrapper element. * - * @param string $text The label text - * @param string|array $type The label type (default, primary, success, warning, + * @param string $text The badge text. + * @param string|array $type The badge type (default, primary, secondary, success, warning, * info, danger) or the array of options (see `$options`). * @param array $options Array of options. See above. Default values are retrieved * from the configuration. * - * @return string The HTML label element. + * @param array $options Array of attributes for the span element. */ - public function label($text, $type = null, $options = []) { + public function badge($text, $type = null, $options = []) { if (is_string($type)) { $options['type'] = $type; } else if (is_array($type)) { $options = $type; } - $options += $this->getConfig('label') + [ + $options += $this->getConfig('badge') + [ 'templateVars' => [] ]; $type = $options['type']; - return $this->formatTemplate('label', [ + return $this->formatTemplate('badge', [ 'type' => $options['type'], 'content' => $text, 'attrs' => $this->templater()->formatAttributes($options, ['type']), @@ -182,39 +182,6 @@ public function label($text, $type = null, $options = []) { ]); } - /** - * Create a Twitter Bootstrap badge. - * - * ### Options - * - * - `templateVars` Provide template variables for the `badge` template. - * - Other attributes will be assigned to the wrapper element. - * - * @param string $text The badge text. - * - * @param array $options Array of attributes for the span element. - */ - public function badge($text, $options = []) { - $options += [ - 'templateVars' => [] - ]; - return $this->formatTemplate('badge', [ - 'content' => $text, - 'attrs' => $this->templater()->formatAttributes($options), - 'templateVars' => $options['templateVars'] - ]); - } - - - /** - * @deprecated 3.3.6 (CakePHP) Use the BreadcrumbsHelper instead. - */ - public function getCrumbList(array $options = [], $startText = false) { - $options['separator'] = ''; - $options = $this->addClass($options, 'breadcrumb'); - return parent::getCrumbList($options, $startText); - } - /** * Create a Twitter Bootstrap style alert block, containing text. * @@ -340,7 +307,7 @@ public function progress($widths, array $options = []) { $width = $this->addClass($width, 'progress-bar-striped'); } if ($width['active']) { - $width = $this->addClass($width, 'active'); + $width = $this->addClass($width, 'progress-bar-striped progress-bar-animated'); } $inner = $this->formatTemplate('progressBarInner', [ 'width' => $width['width'] @@ -433,6 +400,7 @@ public function dropdown(array $menu = [], array $options = []) { } $normalized[] = $value; } + // create content $content = ''; foreach ($normalized as $item) { foreach ($item as $key => $value) { @@ -453,11 +421,17 @@ public function dropdown(array $menu = [], array $options = []) { ]); } if ($key == 'item') { + $title = $value['title']; if (isset($value['url'])) { - $value['title'] = $this->link($value['title'], $value['url']); + $url = $this->Url->build($value['url']); + } + else { + $url = '#'; + $value = $this->addClass($value, 'disabled'); } $content .= $this->formatTemplate('dropdownMenuItem', [ - 'content' => $value['title'], + 'content' => $title, + 'url' => $url, 'attrs' => $this->templater()->formatAttributes($value, ['title', 'url']), 'templateVars' => $value['templateVars'] ]); @@ -476,40 +450,6 @@ public function dropdown(array $menu = [], array $options = []) { ]); } - /** - * Create a formatted collection of elements while - * maintaining proper bootstrappy markup. Useful when - * displaying, for example, a list of products that would require - * more than the maximum number of columns per row. - * - * @deprecated 3.1.0 - * - * @param int|string $breakIndex Divisible index that will trigger a new row - * @param array $data Collection of data used to render each column - * @param callable $determineContent A callback that will be called with the - * data required to render an individual column - * - * @return string - */ - public function splicedRows($breakIndex, array $data, callable $determineContent) { - $rowsHtml = '
'; - - $count = 1; - foreach ($data as $index => $colData) { - $rowsHtml .= $determineContent($colData); - - if ($count % $breakIndex === 0) { - $rowsHtml .= ''; - } - - $count++; - } - - $rowsHtml .= '
'; - return $rowsHtml; - - } - } ?> diff --git a/tests/TestCase/View/Helper/HtmlHelperTest.php b/tests/TestCase/View/Helper/HtmlHelperTest.php index 4188a12..5c8dbe9 100644 --- a/tests/TestCase/View/Helper/HtmlHelperTest.php +++ b/tests/TestCase/View/Helper/HtmlHelperTest.php @@ -83,51 +83,51 @@ public function testIcon() { } - public function testLabel() { + public function testBadge() { $content = 'My Label'; // Standard test $this->assertHtml([ ['span' => [ - 'class' => 'label label-default' + 'class' => 'badge badge-default' ]], 'My Label', '/span' - ], $this->html->label($content)); + ], $this->html->badge($content)); // Type $this->assertHtml([ ['span' => [ - 'class' => 'label label-primary' + 'class' => 'badge badge-primary' ]], 'My Label', '/span' - ], $this->html->label($content, 'primary')); + ], $this->html->badge($content, 'primary')); // Type + Options $options = [ - 'class' => 'my-label-class', - 'id' => 'my-label-id' + 'class' => 'my-badge-class', + 'id' => 'my-badge-id' ]; $this->assertHtml([ ['span' => [ - 'class' => 'label label-primary '.$options['class'], + 'class' => 'badge badge-primary '.$options['class'], 'id' => $options['id'] ]], 'My Label', '/span' - ], $this->html->label($content, 'primary', $options)); + ], $this->html->badge($content, 'primary', $options)); // Only options $options = [ - 'class' => 'my-label-class', - 'id' => 'my-label-id', + 'class' => 'my-badge-class', + 'id' => 'my-badge-id', 'type' => 'primary' ]; $this->assertHtml([ ['span' => [ - 'class' => 'label label-primary '.$options['class'], + 'class' => 'badge badge-primary '.$options['class'], 'id' => $options['id'] ]], 'My Label', '/span' - ], $this->html->label($content, $options)); + ], $this->html->badge($content, $options)); } public function testAlert() { @@ -223,7 +223,7 @@ public function testProgress() { $expected = [ ['div' => ['class' => 'progress']], ['div' => [ - 'class' => 'progress-bar progress-bar-primary', + 'class' => 'progress-bar bg-primary', 'role' => 'progressbar', 'aria-valuenow' => 20, 'aria-valuemin' => 0, @@ -245,7 +245,7 @@ public function testProgress() { $expected = [ ['div' => ['class' => 'progress']], ['div' => [ - 'class' => 'progress-bar progress-bar-primary my-class progress-bar-striped', + 'class' => 'progress-bar bg-primary my-class progress-bar-striped', 'role' => 'progressbar', 'aria-valuenow' => 20, 'aria-valuemin' => 0, @@ -255,7 +255,7 @@ public function testProgress() { ['span' => ['class' => 'sr-only']], '20%', '/span', '/div', ['div' => [ - 'class' => 'progress-bar progress-bar-primary progress-bar-striped', + 'class' => 'progress-bar bg-primary progress-bar-striped', 'role' => 'progressbar', 'aria-valuenow' => 15, 'aria-valuemin' => 0, @@ -266,7 +266,7 @@ public function testProgress() { ['span' => ['class' => 'sr-only']], '15%', '/span', '/div', ['div' => [ - 'class' => 'progress-bar progress-bar-primary progress-bar-striped active', + 'class' => 'progress-bar bg-primary progress-bar-striped progress-bar-animated', 'role' => 'progressbar', 'aria-valuenow' => 10, 'aria-valuemin' => 0, @@ -306,18 +306,19 @@ public function testDropdown() { ]] ]); $expected = [ - ['ul' => ['class' => 'dropdown-menu dropdown-menu-left']], - ['li' => ['role' => 'presentation', 'class' => 'dropdown-header']], 'Header 1', '/li', - ['li' => ['role' => 'separator', 'class' => 'divider']], '/li', - ['li' => ['role' => 'presentation', 'class' => 'dropdown-header']], 'Header 2', '/li', - ['li' => ['role' => 'separator', 'class' => 'divider']], '/li', - ['li' => []], ['a' => ['href' => '#']], 'Link 1', '/a', '/li', - ['li' => ['role' => 'separator', 'class' => 'divider']], '/li', - ['li' => ['role' => 'presentation', 'class' => 'dropdown-header']], 'Header 3', '/li', - ['li' => []], 'Item 1', '/li', - ['li' => []], ['a' => ['href' => '#']], 'Item 2', '/a', '/li', - ['li' => []], 'Item 3', '/li', - ['li' => ['class' => 'my-class-4']], ['a' => ['href' => '#']], 'Item 4', '/a', '/li', + ['div' => ['class' => 'dropdown-menu dropdown-menu-left']], + ['h6' => ['class' => 'dropdown-header']], 'Header 1', '/h6', + ['div' => ['class' => 'dropdown-divider']], '/div', + ['h6' => ['class' => 'dropdown-header']], 'Header 2', '/h6', + ['div' => ['class' => 'dropdown-divider']], '/div', + ['a' => ['href' => '#', 'class' => 'dropdown-item']], 'Link 1', '/a', + ['div' => ['class' => 'dropdown-divider']], '/div', + ['h6' => ['class' => 'dropdown-header']], 'Header 3', '/h6', + ['a' => ['href' => '#', 'class' => 'dropdown-item disabled']], 'Item 1', '/a', + ['a' => ['href' => '#', 'class' => 'dropdown-item']], 'Item 2', '/a', + ['a' => ['href' => '#', 'class' => 'dropdown-item disabled']], 'Item 3', '/a', + ['a' => ['href' => '#', 'class' => 'dropdown-item my-class-4']], 'Item 4', '/a', + '/div' ]; $this->assertHtml($expected, $result); } From ab5d4049a28e1ef5288838a8a367542a0f10970d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Fri, 11 Aug 2017 15:51:36 +0200 Subject: [PATCH 02/95] No change to FlashHelper needed. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e4110c1..36a6c10 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Work in progress I am currently working on rewritting the helpers for Bootstrap 4, current work status: -- FlashHelper - 0% +- FlashHelper - 100% - FormHelper - 0% - HtmlHelper - 100% - ModalHelper - 0% From cb5f28430b8a994e5520a91b4465de28fcd33551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Capelle?= Date: Wed, 6 Sep 2017 11:29:44 +0200 Subject: [PATCH 03/95] Start updating navbar helper. --- src/View/Helper/NavbarHelper.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/View/Helper/NavbarHelper.php b/src/View/Helper/NavbarHelper.php index 1915bb1..ab8ff23 100644 --- a/src/View/Helper/NavbarHelper.php +++ b/src/View/Helper/NavbarHelper.php @@ -62,7 +62,8 @@ class NavbarHelper extends Helper { 'responsiveEnd' => '', 'header' => '', 'toggleButton' => -'', 'brand' => '{{content}}', 'brandImage' => '{{brandname}}', - 'dropdownMenuStart' => '', + 'dropdownMenuStart' => '