Correct frontend mapping of TCA 'type'=>'check'

霸气de小男生 提交于 2020-01-05 03:44:04

问题


I currently implement a user right object in TYPO3 7/Extbase. Different rights are mapped as bits of an INT as per (simplified):

'permissions' => array(
 'label' => 'permissions'
 'config' => array(
  'type' => 'check',
  'items' => array(
   array('Permission 1', ''),
   array('Permission 2', '')
  )
 )
),

Modification of this in the Backend works flawlessly and the flags are correctly stored as their corresponding bits in he DB.

How can I achieve similar behaviour in the frontend? Is there a (correct) way of mapping the bit values to fluid checkboxes?


回答1:


You can add custom setter/getter functions that set or return the bits.

in your model:

/**
 * @var int
 */
protected $permissions;

Add something like this:

/**
 * @return int
 */
public function getPermission2() {
  return $this->permissions & 2 > 0 ? 1 : 0;
}

/**
 * @param int $permission2
 */
public function getPermission2($permission2) {
  if ($permission2) {
    $this->permissions = $this->permissions | 2;
  } else {
    $this->permissions = $this->permissions ~ 2;
  }
}

Then you can parameter="permission2" in the f:form.checkbox or {object.permission2} for other fluid viewhelpers.

PS: for permission 1 you need to change the 2 to 1 and for permission 3 it would be 4



来源:https://stackoverflow.com/questions/41569091/correct-frontend-mapping-of-tca-type-check

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!