contenir / contenir-view-helper
Contenir View components
Requires
- php: ~8.3.0 || ~8.4.0 || ~8.5.0
- laminas/laminas-cache: ^3.12
- laminas/laminas-cache-storage-adapter-filesystem: ^2.4
- laminas/laminas-config: ^3.9
- laminas/laminas-escaper: ^2.13
- laminas/laminas-form: ^3.21
- laminas/laminas-permissions-acl: ^2.16
- laminas/laminas-servicemanager: ^3.22 || ^4.0
- laminas/laminas-uri: ^2.12
- laminas/laminas-view: ^2.35
- psr/container: ^1.1 || ^2.0
Requires (Dev)
- laminas/laminas-i18n: ^2.33
- php-db/phpdb-qa-tools: 0.1.x-dev
- phpunit/phpunit: ^11.5.42
Suggests
- laminas/laminas-i18n: Required by the laminas-form view helpers that formGroup() renders through
Provides
None
Conflicts
None
Replaces
None
- dev-main / 2.0.x-dev
- v2.0.0
- 1.x-dev
- v1.1.2
- v1.1.1
- v1.1.0.1
- v1.1.0
- v1.0.8
- v1.0.7.1
- v1.0.7
- v1.0.6.5
- v1.0.6.3
- v1.0.6.2
- v1.0.6.1
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2.1
- v1.0.2
- v1.0.1
- v1.0.0
- dev-chore/mago-1.57.0
- dev-ci/push-trigger
- dev-chore/contenir-qa-tools
- dev-chore/tidy
- dev-ci/infection
- dev-ci/contenir-qa-tools
- dev-v2/qa-tools
This package is auto-updated.
Last update: 2026-10-21 04:03:36 UTC
README
laminas-view helpers shared by Contenir CMS sites: text formatting, links, media embeds, BEM form groups, and access to the application's ACL, settings and view cache from view scripts.
Requirements
- PHP 8.3, 8.4 or 8.5
- laminas-view 2.35+, laminas-form 3.21+, laminas-cache 3.12+
laminas/laminas-i18nwhen you useformGroup(), as the laminas-form view helpers it renders through need it
The 1.x releases, which support PHP 8.0 to 8.2, remain available from the
1.x branch and v1.* tags; see UPGRADE-2.0.md.
Installation
composer require contenir/contenir-view-helper
With the Laminas component installer, the Contenir\View module (laminas-mvc)
or Contenir\View\ConfigProvider (Mezzio) registers itself. Otherwise add
Contenir\View to config/modules.config.php, or the ConfigProvider to
your config aggregator.
Usage
Every helper is registered under its class name and a camelCase and
PascalCase alias, so view scripts call $this->truncate(...) or
$this->Truncate(...).
| Helper | Purpose | Docs |
|---|---|---|
dateFormat($date = null, $format = null) |
Format a date string (d M Y by default); null when unparseable |
Text |
truncate($text, $length = 125, $strip = false, $etc = '...', $breakWords = false, $middle = false) |
Shorten text at a word boundary | Text |
fileSize($bytes, $decimals = 2, $system = FileSize::SYSTEM_METRIC) |
1.5MB, or 1.5MiB in the binary system |
Text |
fileType($mimeType) |
PDF or Document |
Text |
richContent($html, $template = []) |
Lay out __SECTION__ / __COL__ markers as grid sections and columns |
Text |
urlFormat($url = null, $format = null) |
Normalise a URL and render chosen parts | Links |
resourceLink($value = null, $defaultCta = null) |
Normalise a CMS link field into link objects | Links |
socialLink($network, $handleOrUrl, $options = []) |
Link to a social network profile | Links |
escapeEmail($email, $mailto = false) |
Obfuscate an email address against harvesters | Links |
image($path, $attributes = [], $pictureAttributes = []) |
Lazy-loaded <picture> served from a CDN |
Media |
srcset($path, $sizes = []) |
srcset value for pre-resized derivatives |
Media |
video($path, $options = [], $controls = false) |
Vimeo/YouTube embed or <video> element |
Media |
icon($name, $options = []) |
Inline an SVG icon | Media |
formGroup($element, $displayAttributes = [], $groupAttributes = [...]) |
Render a laminas-form element as a BEM form group | Forms |
acl(), settings(), cache() |
The application's ACL, settings and view cache | Application services |
<h2><?= $this->escapeHtml($this->truncate($entry->title, 60)) ?></h2> <time><?= $this->dateFormat($entry->published) ?></time> <?= $this->image($entry->image, ['alt' => $entry->title, 'resizeWidth' => 800]) ?> <?php foreach ($this->resourceLink($entry->links) as $link): ?> <a href="<?= $this->escapeHtmlAttr($link->url) ?>"><?= $this->escapeHtml($link->cta) ?></a> <?php endforeach ?>
All helper classes are final. To customise one, register your own helper
under the same alias; see Customising a helper.
Configuration
| Key | Used by | Default |
|---|---|---|
view_cdn.host, view_cdn.method |
image() |
no host; https |
view_helper_config.icon.class |
icon() default wrapper class |
none (icon output bare) |
settings |
settings() |
[] |
service ViewCache (a laminas-cache StorageInterface) |
cache() |
required to use cache() |
service Application\Acl\Acl (an AclInterface) |
acl() |
required to use acl() |
The laminas-mvc Module also sets shared view_manager defaults: an HTML5
doctype, error/404, error/403 and error/index templates, and the JSON
view strategy. See Configuration.
Development
The QA toolchain is contenir/contenir-qa-tools.
Mago is a standalone binary, installed
separately (brew install mago).
composer check # everything below composer cs-check # mago format --check && mago lint composer static-analysis # mago analyze composer test # unit suite: helpers and factories with doubled collaborators, no I/O composer test-integration # integration suite: a real PhpRenderer and plugin manager, temp-directory files composer test-coverage # both suites, clover.xml for Codecov composer mutation-test # Infection mutation testing over both suites (not part of check: about 2 minutes)
License
BSD-3-Clause. See LICENSE.md.