/** * Adjust the behavior of the supplied field in the context of the supplied * table renderer so that it draws a "handle" that the user can grab to * drag the row around. Adds some custom JS/CSS to pull that off. * * @param FieldInterface $field * @param TableCell $cellRenderer * @param string $primaryKeyName * @return void */ public function assignToField(FieldInterface $field, TableCell $cellRenderer, $primaryKeyName) { $this->view->headScript()->appendFile($this->view->bowerUrl('/dewdrop/www/js/listing-sortable.js')); $this->view->headLink()->appendStylesheet($this->view->bowerUrl('/dewdrop/www/css/listing-sortable.css')); $cellRenderer->getContentRenderer()->assign($field->getId(), function ($helper, array $rowData) use($primaryKeyName) { /* @var $helper TableCell\Content */ return sprintf('<span data-id="%d" class="handle glyphicon glyphicon-align-justify"></span>', $helper->getView()->escapeHtmlAttr($rowData[$primaryKeyName])); }); }
public function renderFieldContent(FieldInterface $field, InputFilter $inputFilter, Renderer $renderer, $position, $renderLabels = true) { $output = ''; $input = $inputFilter->has($field->getId()) ? $inputFilter->get($field->getId()) : null; $messages = $input ? $input->getMessages() : null; $output .= sprintf($this->renderFormGroupOpenTag(), $messages ? ' has-feedback has-error alert alert-danger' : ''); $controlOutput = $renderer->getControlRenderer()->render($field, $position); if ($renderLabels && $this->controlRequiresLabel($controlOutput)) { $output .= $this->renderLabel($field, $renderer, $input); } $output .= $controlOutput; if ($messages) { $output .= $this->renderMessages($messages); } if ($field->getNote()) { $output .= sprintf('<div class="help-block">%s</div>', $this->view->escapeHtml($field->getNote())); } $output .= '</div>'; return $output; }
/** * Get the validation messages associated with a specific field. * * @param FieldInterface $field * @return array */ public function getMessages(FieldInterface $field) { return $this->getInputFilter()->get($field->getId())->getMessages(); }
/** * Add the supplied field to this collection after another specified field already in the collection. Can be a * FieldInterface object or a string, in which case a new custom field will be added with the supplied string as its * ID. * * The newly added FieldInterface object is returned from this method so that it can be further customized * immediately, using method chaining. Once you've completed calling methods on the FieldInterface object itself, * you can call any \Dewdrop\Fields methods to return execution to that context. * * @param FieldInterface|string $field * @param FieldInterface|string $after * @param string $modelName * @throws Exception * @return FieldInterface */ public function insertAfter($field, $after, $modelName = null) { if ($after instanceof FieldInterface) { $afterId = $after->getId(); } else { $afterId = (string) $after; } if (!$this->has($afterId, $afterPosition)) { throw new Exception("Field with ID \"{$afterId}\" does not exist in this collection"); } $field = $this->prepareFieldForAdding($field, $modelName); array_splice($this->fields, $afterPosition + 1, 0, [$field]); return $field; }
/** * Get the callback that will be used for the given FieldInterface object. * * @param FieldInterface $field * @throws \Dewdrop\Fields\Exception\HelperCallableNotAvailableForField * @return callable */ public function getFieldAssignment(FieldInterface $field) { if (!$this->hasValidName()) { return false; } $id = $field->getId(); if (!array_key_exists($id, $this->assignments)) { if (!$field->hasHelperCallback($this->name)) { $callback = $this->detectCallableForField($field); } else { $callback = $field->getHelperCallback($this->name); } if (!is_callable($callback)) { throw new HelperCallableNotAvailableForField("Field {$id} does not have a callable assigned and one could not be detected."); } $this->assignments[$id] = $this->wrapCallable($callback); } return $this->assignments[$id]; }