/** * Create the Callback validator that will be used to ensure the * RowCollectionEditor is valid. We iterate over all the editors it has, * pass data to the editor via isValid() and return an error message if any * editor fails. * * @return Callback */ protected function createCallbackValidator() { $validator = new Callback(); $validator->setCallback(function () { return $this->rowCollectionEditor->isValid(); }); $validator->setMessage("Some errors were found in your {$this->rowCollectionEditor->getPluralTitle()}.\n Please double-check and try again.", Callback::INVALID_VALUE); return $validator; }
/** * Create the new field object. * * @return Field */ public function createInstance() { $field = new Field(); $field->setId($this->rowCollectionEditor->getId())->setLabel($this->rowCollectionEditor->getTitle())->setEditable(true)->setVisible(false)->assignHelperCallback('SaveHandler', function () { return $this->rowCollectionEditor; })->assignHelperCallback('EditControl.Control', function (EditControl $helper) { $helperName = $this->editViewHelperName; return $helper->getView()->{$helperName}($this->rowCollectionEditor, $this->editViewHelperOptions); })->assignHelperCallback('EditControl.Label', function () { return null; })->assignHelperCallback('InputFilter', function () { return $this->getInputFilterFactory()->createInstance(); })->assignHelperCallback('TableCell.Content', function (TableCell $helper, array $rowData) { $helperName = $this->tableCellViewHelperName; return $helper->getView()->{$helperName}($this->rowCollectionEditor, array_merge(['rowData' => $rowData, 'mapping' => $this->tableCellMapping, 'renderer' => $helper], $this->tableCellViewHelperOptions)); }); return $field; }
/** * Default rendering for a table view context. Expects a count of * items to be present in $rowData in the $mapping index. Renders * that count concatenated with the plural title from the * RowCollectionEditor. * * @param RowCollectionEditor $editor * @param TableCell $renderer * @param array $rowData * @param $mapping * @return string */ public function renderTableView(RowCollectionEditor $editor, TableCell $renderer, array $rowData, $mapping) { $count = $rowData[$mapping]; $view = $renderer->getView(); if (1 === $count) { $title = $editor->getSingularTitle(); } else { $title = $editor->getPluralTitle(); } return sprintf('%d %s', $view->escapeHtml($count), $view->escapeHtml($title)); }