Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reset v2 docs create v3 docs tree #224

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions docs/book/v2/helpers/flash-messenger.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# FlashMessenger

The `FlashMessenger` helper is used to render the messages of the
[FlashMessenger MVC plugin](https://docs.laminas.dev/laminas-mvc-plugin-flashmessenger/).

## Basic Usage

When only using the default `namespace` for the `FlashMessenger`, you can do the
following:

```php
// Usable in any of your .phtml files
echo $this->flashMessenger()->render();
```

The first argument of the `render()` function is the `namespace`. If no
`namespace` is defined, the default
`Laminas\Mvc\Controller\Plugin\FlashMessenger::NAMESPACE_DEFAULT` will be used,
which translates to `default`.

```php
// Usable in any of your .phtml files
echo $this->flashMessenger()->render('error');

// Alternatively use one of the pre-defined namespaces
// (aka: use Laminas\Mvc\Controller\Plugin\FlashMessenger;)
echo $this->flashMessenger()->render(FlashMessenger::NAMESPACE_SUCCESS);
```

## CSS Layout

The `FlashMessenger` default rendering adds a CSS class to the generated HTML,
that matches the defined `namespace` that should be rendered. While it may work
well for the default cases, every so often you may want to add specific CSS
classes to the HTML output. This can be done while making use of the second
parameter of the `render()` function.

```php
// Usable in any of your .phtml files
echo $this->flashMessenger()->render('error', ['alert', 'alert-danger']);
```

The output of this example, using the default HTML rendering settings, would
look like this:

```html
<ul class="alert alert-danger">
<li>Some FlashMessenger Content</li>
<li>You, the developer, are AWESOME!</li>
</ul>
```

## HTML Layout

Aside from modifying the rendered CSS classes of the `FlashMessenger`, you are
furthermore able to modify the generated HTML as a whole to create even more
distinct visuals for your flash messages. The default output format is defined
within the source code of the `FlashMessenger` view helper itself.

```php
// Laminas/View/Helper/FlashMessenger.php#L41-L43
protected $messageCloseString = '</li></ul>';
protected $messageOpenFormat = '<ul%s><li>';
protected $messageSeparatorString = '</li><li>';
```

These defaults exactly match what we're trying to do. The placeholder `%s` will
be filled with the CSS classes output.

To change this, all we need to do is call the respective setter methods of these
variables and give them new strings; for example:

```php
// In any of your .phtml files:
echo $this->flashMessenger()
->setMessageOpenFormat('<div%s><p>')
->setMessageSeparatorString('</p><p>')
->setMessageCloseString('</p></div>')
->render('success');
```

The above code sample then would then generate the following output:

```html
<div class="success">
<p>Some FlashMessenger Content</p>
<p>You, who's reading the docs, are AWESOME!</p>
</div>
```

## Sample Modification for Twitter Bootstrap 3

Taking all the above knowledge into account, we can create a nice, highly usable
and user-friendly rendering strategy using the
[Bootstrap front-end framework](http://getbootstrap.com/) version 3 layouts:

```php
// In any of your .phtml files:
$flash = $this->flashMessenger();
$flash->setMessageOpenFormat('<div%s>
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">
&times;
</button>
<ul><li>')
->setMessageSeparatorString('</li><li>')
->setMessageCloseString('</li></ul></div>');

echo $flash->render('error', ['alert', 'alert-dismissible', 'alert-danger']);
echo $flash->render('info', ['alert', 'alert-dismissible', 'alert-info']);
echo $flash->render('default', ['alert', 'alert-dismissible', 'alert-warning']);
echo $flash->render('success', ['alert', 'alert-dismissible', 'alert-success']);
```

The output of the above example would create dismissable `FlashMessages` with
the following HTML markup. The example only covers one type of `FlashMessenger`
output; if you would have several `FlashMessages` available in each of the
rendered `namespaces`, then you would receive the same output multiple times
only having different CSS classes applied.

```html
<div class="alert alert-dismissable alert-success">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
<ul>
<li>Some FlashMessenger Content</li>
<li>You, who's reading the docs, are AWESOME!</li>
</ul>
</div>
```

## Alternative Configuration of the ViewHelper Layout

`Laminas\View\Helper\Service\FlashMessengerFactory` checks the application
configuration, making it possible to set up the `FlashMessenger` strings through
your `module.config.php`, too. The next example will set up the output to be
identical with the above Twitter Bootstrap 3 Example

```php
'view_helper_config' => [
'flashmessenger' => [
'message_open_format' => '<div%s><button type="button" class="close"
data-dismiss="alert" aria-hidden="true">&times;</button><ul><li>',
'message_close_string' => '</li></ul></div>',
'message_separator_string' => '</li><li>',
],
],
```
4 changes: 3 additions & 1 deletion docs/book/v2/helpers/html-object.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

The [HTML `<object>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/object) is used for embedding external media in web pages. The object view helpers take care of embedding media with minimum effort.

There are two initial Object helpers:
There are four initial Object helpers:

- `htmlObject()` Generates markup for embedding a custom Object.
- `htmlPage()` Generates markup for embedding other (X)HTML pages.
- `htmlFlash()` Generates markup for embedding Flash files. _**Deprecated**_
- `htmlQuicktime()` Generates markup for embedding QuickTime files. _**Deprecated**_

All of these helpers share a similar interface. For this reason, this
documentation will only contain examples of two of these helpers.
Expand Down
7 changes: 1 addition & 6 deletions docs/book/v2/helpers/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ for, and rendering, the various HTML `<head>` tags, such as `HeadTitle`,
- [BasePath](base-path.md)
- [Cycle](cycle.md)
- [Doctype](doctype.md)
- [FlashMessenger](flash-messenger.md)
- [Gravatar](gravatar.md) *(Deprecated)*
- [GravatarImage](gravatar-image.md)
- [HeadLink](head-link.md)
Expand Down Expand Up @@ -109,12 +110,6 @@ for, and rendering, the various HTML `<head>` tags, such as `HeadTitle`,
> [Paginator Usage](https://docs.laminas.dev/laminas-paginator/usage/#rendering-pages-with-view-scripts)
> documentation.

> ### FlashMessenger helper
>
> View helper related to **Flash Messenger** is documented in the
> [FLash Messenger View Helper](https://docs.laminas.dev/laminas-mvc-plugin-flashmessenger/view-helper/)
> documentation.

> ### Custom Helpers
>
> For documentation on writing **custom view helpers** see the
Expand Down
26 changes: 26 additions & 0 deletions docs/book/v2/helpers/json.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,29 @@ determine how to handle the content.
```php
<?= $this->json($this->data) ?>
```

> WARNING: **Deprecated**
>
> ### Enabling encoding using Laminas\Json\Expr
>
> **This feature of the Json view helper has been deprecated in version 2.16 and will be removed in version 3.0.**
>
> The JSON helper accepts an array of options that will be passed to `Laminas\Json\Json::encode()` and
> used internally to encode data.
> `Laminas\Json\Json::encode` allows the encoding of native JSON expressions using `Laminas\Json\Expr`
> objects. This option is disabled by default. To enable this option, pass a boolean `true` to the
> `enableJsonExprFinder` key of the options array:
>
> ```php
> <?= $this->json($this->data, ['enableJsonExprFinder' => true]) ?>
> ``
>
> The JSON helper accepts an array of options that will be passed to `Laminas\Json\Json::encode()` and
> used internally to encode data.
> `Laminas\Json\Json::encode` allows the encoding of native JSON expressions using `Laminas\Json\Expr`
> objects. This option is disabled by default. To enable this option, pass a boolean `true` to the
> `enableJsonExprFinder` key of the options array:
>
> ```php
> <?= $this->json($this->data, ['enableJsonExprFinder' => true]) ?>
> ```
Loading