示例#1
0
 public function testCanFilterWhenGettingEditableFields()
 {
     /* @var $field Field */
     foreach ($this->fields as $field) {
         $field->setEditable(true);
     }
     $this->assertEquals(4, count($this->fields->getEditableFields()));
     $filter = new CallbackFilter(function (Field $field) {
         return 'visible' === $field->getId();
     });
     $this->assertEquals(1, count($this->fields->getEditableFields($filter)));
 }
示例#2
0
 public function renderAjaxResponse()
 {
     if (!$this->request->isPost() && !$this->request->isGet()) {
         return ['result' => 'error', 'message' => 'AJAX edit requests must be POST or GET'];
     } elseif ($this->request->isPost() && !$this->invalidSubmission) {
         return ['result' => 'success', 'id' => $this->component->getListing()->getPrimaryKey()->getValue(), 'data' => $this->getData()];
     } elseif ($this->request->isGet()) {
         return $this->renderAjaxForm();
     } else {
         $messages = [];
         foreach ($this->fields->getEditableFields() as $field) {
             $messages[$field->getHtmlId()] = $this->rowEditor->getMessages($field);
         }
         return ['result' => 'invalid', 'messages' => $messages];
     }
 }
示例#3
0
 public function renderFieldsInTableRow(Fields $fields, InputFilter $inputFilter, Renderer $renderer)
 {
     $output = '<tr>';
     foreach ($fields->getEditableFields() as $field) {
         $output .= '<td>';
         $output .= $this->renderFieldContent($field, $inputFilter, $renderer, 100, false);
         $output .= '</td>';
     }
     $output .= '</tr>';
     return $output;
 }
示例#4
0
 /**
  * In most common cases, the rows handled by a RowEditor object are linked
  * to one another by foreign key using the linkByField() method.  When this
  * is the case, we can traverse those links in reverse order, saving the
  * rows at the end of the chain of links first so that they can populate
  * the fields on the tables farther up the chain.  Once the field links
  * have been traversed, we can save the other rows safely.
  *
  * If you are not using linkByField(), you may need to provide a custom
  * save callback that takes your situation into account.
  *
  * @return RowEditor
  */
 public function saveRowsByLinks()
 {
     $reverseLinks = array_reverse($this->links, true);
     $savedRows = array();
     // First save Field links in the chain in reverse order
     foreach ($reverseLinks as $modelName => $link) {
         if ($link instanceof FieldLink) {
             $row = $this->getRow($modelName);
             $row->save();
             $link->populateValueFromSavedRow($row);
             $savedRows[] = $modelName;
         }
     }
     // Now save any rows that weren't saved in the first loop
     /* @var $row Row */
     foreach ($this->rowsByName as $modelName => $row) {
         if (!in_array($modelName, $savedRows)) {
             $row->save();
         }
     }
     /* @var $field FieldInterface */
     foreach ($this->fields->getEditableFields() as $field) {
         $this->saveHandlerHelper->save($field);
     }
     return $this;
 }
示例#5
0
 private function decorateFields(Fields $fields, EditControl $renderer)
 {
     $control = $renderer->getControlRenderer();
     /* @var $field FieldInterface */
     foreach ($fields->getEditableFields() as $field) {
         $callback = $control->getFieldAssignment($field);
         $control->assign($field, function () use($callback, $control, $field) {
             return $control->getView()->importEditControl($field, $this->importFile, $this->request, $callback($control, $control->getView()));
         });
     }
     return $fields;
 }