Transform the named field into a readonly field.

@param string|array|FormField $field
171824
public function makeFieldReadonly($field)
    {
        if (!is_array($field)) {
            $field = [$field];
        }

        foreach ($field as $item) {
            $fieldName = ($item instanceof FormField) ? $item->getName() : $item;
            $srcField = $this->dataFieldByName($fieldName);
            if ($srcField) {
                $this->replaceField($fieldName, $srcField->performReadonlyTransformation());
            } else {
                user_error("Trying to make field '$fieldName' readonly, but it does not exist in the list", E_USER_WARNING);
            }
        }
    }
963714
def derive_readonly(self):
        
        readonly = list(self.readonly)
        for key, value in self.field_config.items():
            if 'readonly' in value and value['readonly']:
                readonly.append(key)

        return readonly
487625
public function updateField($field)
    {
        if (!$field instanceof ObjectField)
        {
            throw new FieldEditorException(print_r($field, true) . " is not of type ObjectField");
        }
        foreach ($this->_fields as $column => $fields)
        {
            foreach ($fields as $index => $f)
            {
                $existing_field = $f->getField();
                if ($existing_field !== null && $field->getField() === $existing_field)
                {
                    // If the field name (f1234) exists merge replace on that.
                    $this->_fields[$column][$index] = $field;
                    return;
                }
            }
        }
        throw new FieldEditorException("Could not find an existing field: {$field->getField()} in this Section");
    }
1123178
public function setField($field)
    {
        if(is_string($field)) {
            $field = new FieldIdentifier($field);
        }
        $this->field = $field;
        return $this;
    }
497084
public function handleField(Field $field)
    {
        $prefix = $this->prefix . strtoupper($field->name);

        if (!isset($field->label)) {
            $field->label = $prefix . '_LABEL';
        }

        if (preg_match('~^([A-Z_]+)$~', $field->label, $match)) {
            $prefix = $match[1];
        }

        if (preg_match('~^([A-Z_]+?)_LABEL$~', $field->label, $match)) {
            $prefix = $match[1];
        }

        if (!isset($field->description)) {
            $field->description = $prefix . '_DESC';
        }

        if (preg_match('~^([A-Z_]+?)_DESC$~', $field->description, $match)) {
            $prefix = $match[1];
        }

        if (!isset($field->hint)) {
            $field->hint = $prefix . '_HINT';
        }

        if (!isset($field->role)) {
            if (isset($this->special[$field->name])) {
                $field->role = $this->special[$field->name];
            }
        }

        if (isset($field->role)) {
            $this->fieldAliases[$field->role] = $field->name;
        }

        $this->reflector->addField($field);
    }
1368593
public function add(FormField $field)
    {
        $segments = $this->getSegments($field->getName());

        $target = &$this->fields;
        while ($segments) {
            if (!\is_array($target)) {
                $target = [];
            }
            $path = array_shift($segments);
            if ('' === $path) {
                $target = &$target[];
            } else {
                $target = &$target[$path];
            }
        }
        $target = $field;
    }
1036330
public function performReadonlyTransformation()
    {
        $field = new CheckboxField_Readonly($this->name, $this->title, $this->value);
        $field->setForm($this->form);
        return $field;
    }
958456
private function readForm()
    {
        foreach ($this->fields as $field) {
            $field->setForm($this);

            if ($field->hasError()) {
                $field->addClass('is-invalid');
            }


            if ($old = $this->request->old($field->getName())) {
                $field->value($old);
            }
        }
    }
938975
public function setField(AbstractFormField $field)
    {
        if (!($field instanceof UploadField)) {
            throw new \Exception('The validator "' . get_class($this) . '" only works on upload fields!');
        }

        $this->field = $field;
        return $this;
    }
905166
def field_from_django_field(cls, field_name, django_field, readonly):
        

        FieldWidget = cls.widget_from_django_field(django_field)
        widget_kwargs = cls.widget_kwargs_for_field(field_name)
        field = cls.DEFAULT_RESOURCE_FIELD(
            attribute=field_name,
            column_name=field_name,
            widget=FieldWidget(**widget_kwargs),
            readonly=readonly,
            default=django_field.default,
        )
        return field
1346796
protected function fieldNameError(FormField $field, $functionName)
    {
        if ($this->form) {
            $errorSuffix = sprintf(
                " in your '%s' form called '%s'",
                get_class($this->form),
                $this->form->getName()
            );
        } else {
            $errorSuffix = '';
        }

        user_error(
            sprintf(
                "%s() I noticed that a field called '%s' appears twice%s",
                $functionName,
                $field->getName(),
                $errorSuffix
            ),
            E_USER_ERROR
        );
    }
114523
public function unsetField($name)
    {
        $this->checkFieldExist($name);
        unset($this->fields[$name], $this->types[$name]);

        return $this;
    }
1218176
public function readField($field, $table)
    {
        $objField = new \stdClass();

        //$this->alert($field->Field);
        preg_match('/[a-zA-Z]+/', $field->Type, $type);
        preg_match('/[0-9]+/', $field->Type, $size);
        preg_match('/([a-zA-Z_0-9]+)_id/', $field->Field, $fk2);

        $types = null;
        if ($type[0] === 'enum') {
            // dump($field->Type);
            preg_match('/\([\'0-9,a-zA-Z]+\)/', $field->Type, $types);
            $types = str_replace(['(', "'",')'], '', $types[0]);
        }

        $objField->name = $field->Field;
        $objField->type = $type[0];
        $objField->inTypes = $types;
        $objField->size = isset($size[0]) ? $size[0] : null;
        $objField->unsigned = strpos($field->Type, 'unsigned') !== false ? true : false;
        $objField->required = $field->Null === 'NO' ? true : false;
        $objField->pk = $field->Key === 'PRI' ? true : false;
        $objField->fk = empty($fk) ? (empty($fk2) ? false : Pluralizer::plural($fk2[1])) : Pluralizer::plural($fk[1]);
        $objField->display = false;
        $objField->unique = $field->Key === 'UNI' ? true : false;
        $objField->default = $field->Default;
        $objField->autoIncrement = strpos($field->Extra, 'auto_increment') !== false ? true : false;
        $objField->validator = $this->generateValidator($objField, $table);
        $objField->filter_set = $this->generateFilterSet($objField);
        $objField->filter = $this->generateFilter($objField);


        $displays = [
                        'name',
                        $table->snakeSingular . '_name',
                        'name_' . $table->snakeSingular,
                        'title',
                        $table->snakeSingular . '_title',
                        'title_' . $table->snakeSingular,
                        'username',
                        'user',
                        'login',
                        'email'
                    ];
        if (!$table->fieldDisplay && in_array($objField->name, $displays)) {
            $table->fieldDisplay = true;
            $objField->display = true;
        }


        return $objField;
    }
1347916
public function performReadonlyTransformation()
    {
        /** @var CompositeField $readOnlyField */
        $readOnlyField = $this->castedCopy(CompositeField::class);
        $blockReducer = $this->getReadOnlyBlockReducer();
        $readOnlyField->setChildren(
            FieldList::create(array_map($blockReducer, $this->getArea()->Elements()->toArray()))
        );

        $readOnlyField = $readOnlyField->performReadonlyTransformation();

        // Ensure field names are unique between elements on parent form but only after transformations have been
        // performed
        /** @var FieldGroup $elementForm */
        foreach ($readOnlyField->getChildren() as $elementForm) {
            $parentName = $elementForm->getName();
            $elementForm->getChildren()->recursiveWalk(function (FormField $field) use ($parentName) {
                $field->setName($parentName . '_' . $field->getName());
            });
        }

        return $readOnlyField
            ->setReadOnly(true)
            ->setName($this->getName())
            ->addExtraClass('elemental-area--read-only');
    }
992014
public function setField($field = null)
    {
        $this->field = null;

        if (!$field = $this->internalResolveField($field)) {
            $this->field = $this->fieldId = null;
        } else {
            $this->fieldId = $field->id;
            $this->field = $field;
        }

        return $this;
    }
286687
function updateReadOnlyFlag(annotationToEdit, readOnlyFields) {
  if (!annotationToEdit || !annotationToEdit.selection || !readOnlyFields) {
    return;
  }

  annotationToEdit.readOnly = SelectionBuilder.hasField(
    annotationToEdit.selection,
    readOnlyFields
  );
}
1372156
public function fieldPosition($field)
    {
        if ($field instanceof FormField) {
            $field = $field->getName();
        }

        $i = 0;
        foreach ($this->dataFields() as $child) {
            if ($child->getName() == $field) {
                return $i;
            }
            $i++;
        }

        return false;
    }