/** * Gets the field list for a record. * * @param GridField $grid * @param DataObjectInterface $record * @return FieldList */ public function getFields(GridField $grid, DataObjectInterface $record) { $cols = $this->getDisplayFields($grid); $fields = new FieldList(); $list = $grid->getList(); $class = $list ? $list->dataClass() : null; foreach ($cols as $col => $info) { $field = null; if ($info instanceof Closure) { $field = call_user_func($info, $record, $col, $grid); } elseif (is_array($info)) { if (isset($info['callback'])) { $field = call_user_func($info['callback'], $record, $col, $grid); } elseif (isset($info['field'])) { if ($info['field'] == 'LiteralField') { $field = new $info['field']($col, null); } else { $field = new $info['field']($col); } } if (!$field instanceof FormField) { throw new Exception(sprintf('The field for column "%s" is not a valid form field', $col)); } } if (!$field && $list instanceof ManyManyList) { $extra = $list->getExtraFields(); if ($extra && array_key_exists($col, $extra)) { $field = Object::create_from_string($extra[$col], $col)->scaffoldFormField(); } } if (!$field) { if (!$this->displayFields) { // If setDisplayFields() not used, utilize $summary_fields // in a way similar to base class // // Allows use of 'MyBool.Nice' and 'MyHTML.NoHTML' so that // GridFields not using inline editing still look good or // revert to looking good in cases where the field isn't // available or is readonly // $colRelation = explode('.', $col); if ($class && ($obj = singleton($class)->dbObject($colRelation[0]))) { $field = $obj->scaffoldFormField(); } else { $field = new ReadonlyField($colRelation[0]); } } else { if ($class && ($obj = singleton($class)->dbObject($col))) { $field = $obj->scaffoldFormField(); } else { $field = new ReadonlyField($col); } } } if (!$field instanceof FormField) { throw new Exception(sprintf('Invalid form field instance for column "%s"', $col)); } // Add CSS class for interactive fields if (!($field->isReadOnly() || $field instanceof LiteralField)) { $field->addExtraClass('editable-column-field'); } $fields->push($field); } return $fields; }