public function setUp() { $this->view = new View(); $this->fields = new Fields(); $this->data = array(array('id' => 2, 'name' => 'Apple')); $_SERVER['REQUEST_URI'] = null; $field = new Field(); $field->setId('test-field-id')->setVisible(true)->setSortable(true)->assignHelperCallback('TableCell.Content', function ($helper, $view) { return 'test-field-value'; })->assignHelperCallback('tablecell.tdclassnames', function ($helper, $view) { return ['test-field-class']; }); $this->fields->add($field); }
/** * Create a field object, configured to render a checkbox for use in selecting * items for the supplied BulkActions object. * * @param BulkActions $bulkActions * @param TableCellHelper $renderer * @return Field * @throws Exception */ public function direct(BulkActions $bulkActions, TableCellHelper $renderer) { $field = new Field(); $key = $bulkActions->getPrimaryKey()->getName(); $field->setId($bulkActions->getId())->setVisible(true); $renderer->getHeaderRenderer()->assign($bulkActions->getId(), function () { return ''; }); $renderer->getContentRenderer()->assign($bulkActions->getId(), function ($helper, array $rowData) use($bulkActions, $key) { /* @var $helper \Dewdrop\Fields\Helper\TableCell\Content */ if (!isset($rowData[$key])) { throw new Exception("{$key} not available in row data for bulk action checkbox render."); } $value = $rowData[$key]; return sprintf('<input class="bulk-checkbox" type="checkbox" name="%s[]" value="%s" %s />', $helper->getView()->escapeHtmlAttr($bulkActions->getId()), $helper->getView()->escapeHtmlAttr($value), in_array($value, $bulkActions->getSelected()) ? 'checked="checked"' : ''); }); return $field; }
protected function setUp() { $this->csvCellHeaderFieldsHelper = new Header(); $this->field = new Field(); $this->field->setId('id')->setLabel('label'); }
/** * Prepare to add a field for the supplied arguments. If $field is a string * we'll create a new CustomField. Otherwise, we'll just directly add the * field object itself. * * @param mixed $field * @param string|null $modelName * @return FieldInterface * @throws Exception */ private function prepareFieldForAdding($field, $modelName = null) { if (is_string($field)) { $id = $field; $field = new CustomField(); $field->setId($id); } if (!$field instanceof FieldInterface) { throw new Exception('Field must be a string or instance of \\Dewdrop\\Fields\\FieldInterface'); } if ($field instanceof DbField) { $this->handleModelsForDbField($field, $modelName); } $field->setFieldsSet($this); return $field; }
/** * Create a Field object for handling deletion of items. * * @param RowEditor $editor * @return Field */ private function createDeleteField(RowEditor $editor) { $field = new Field(); $field->setId('delete')->setEditable(true)->assignHelperCallback('InputFilter', function () { $input = new \Zend\InputFilter\Input('delete'); $input->setAllowEmpty(true); return $input; })->assignHelperCallback('EditControl.Label', function () { return '<span class="glyphicon glyphicon-trash"></span>'; })->assignHelperCallback('EditControl.Control', function () use($editor) { if ($editor->isNew()) { $out = '<button data-is-new="1" class="btn btn-danger btn-delete">'; } elseif ($editor->hasDeleteField()) { $out = '<button data-is-new="0" class="btn btn-danger btn-delete">'; } else { $out = '<button data-is-new="0" class="btn btn-danger btn-delete disabled">'; } $out .= '<span class="glyphicon glyphicon-trash"></span>'; $out .= '</button>'; return $out; }); return $field; }
public function testAddingFieldWithDuplicateIdViaArrayInterfaceWithReplacePreviousField() { $field = new Field(); $field->setId('visible'); $newHash = spl_object_hash($field); $oldHash = spl_object_hash($this->fields->get('visible')); $this->assertEquals($oldHash, spl_object_hash($this->fields->get('visible'))); $this->fields['visible'] = $field; $this->assertEquals($newHash, spl_object_hash($this->fields->get('visible'))); $count = 0; /* @var $field Field */ foreach ($this->fields as $field) { if ('visible' === $field->getId()) { $count += 1; } } $this->assertEquals(1, $count); }
public function testHtmlIdIsEquivalentToId() { $this->field->setId('test'); $this->assertEquals('test', $this->field->getHtmlId()); }
/** * 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; }