Skip to content

Instantly share code, notes, and snippets.

@ogrosko
Created June 1, 2016 14:27
Show Gist options
  • Save ogrosko/b454f05961fe7a1d797cf621ccdadb31 to your computer and use it in GitHub Desktop.
Save ogrosko/b454f05961fe7a1d797cf621ccdadb31 to your computer and use it in GitHub Desktop.
Typo3 checkbox group handling
<?php
namespace BinaryBay\BbBoilerplate\ViewHelpers;
class PageBansViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
/**
* @var array
*/
const PAGE_BAN_FIELD = 'page_ban';
/**
* Return bans incons array classes
* @return array
*/
public function render() {
$icons = array();
$banFields = $GLOBALS['TCA']['pages']['columns'][self::PAGE_BAN_FIELD]['config']['items'];
$page = $GLOBALS['TSFE']->page;
if (!array_key_exists(self::PAGE_BAN_FIELD, $page)) {
throw new \TYPO3\CMS\Fluid\Exception('Page property "'.self::PAGE_BAN_FIELD.'" does not exist. Update your database!', 1459866635);
}
$pageBanVal = $page[self::PAGE_BAN_FIELD];
$pageBanBinaryArr = array_reverse(str_split(decbin($pageBanVal)));
foreach ($pageBanBinaryArr as $key => $isOn) {
if ($isOn === '1') {
$icons[] = $banFields[$key][1];
}
}
return $icons;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment