GridCellProvider::render PHP Method

render() public method

To be used by a GridRow to generate a rendered representation of the element for the given column.
public render ( $request, $row, $column ) : string
$row GridRow
$column GridColumn
return string the rendered representation of the element for the given column
    function render($request, $row, $column)
    {
        $columnId = $column->getId();
        assert(!empty($columnId));
        // Construct a default cell id (null for "nonexistent" new rows)
        $rowId = $row->getId();
        // Potentially null (indicating row not backed in the DB)
        $cellId = isset($rowId) ? $rowId . '-' . $columnId : null;
        // Assign values extracted from the element for the cell.
        $templateMgr = TemplateManager::getManager($request);
        $templateVars = $this->getTemplateVarsFromRowColumn($row, $column);
        foreach ($templateVars as $varName => $varValue) {
            $templateMgr->assign($varName, $varValue);
        }
        $templateMgr->assign(array('id' => $cellId, 'column' => $column, 'actions' => $this->getCellActions($request, $row, $column), 'flags' => $column->getFlags(), 'formLocales' => AppLocale::getSupportedFormLocales()));
        $template = $column->getTemplate();
        assert(!empty($template));
        return $templateMgr->fetch($template);
    }

Usage Example

 /**
  * @see GridCellProvider::render()
  */
 function render($request, $row, $column)
 {
     // Default category rows will only have the first column
     // as label columns.
     if ($column->hasFlag('firstColumn')) {
         // Store the current column template.
         $template = $column->getTemplate();
         // Reset to the default column template.
         $column->setTemplate('controllers/grid/gridCell.tpl');
         // Render the cell.
         $renderedCell = parent::render($request, $row, $column);
         // Restore the original column template.
         $column->setTemplate($template);
         return $renderedCell;
     } else {
         return '';
     }
 }
All Usage Examples Of GridCellProvider::render