Save a single field instance

@param Field $field The field instance to save
@param bool $newRevision Should we create a new revision?
194445
protected function saveField(Field $field, $newRevision)
    {
        // If we create a new revision, this will
        // reinit the field to a non-saved field
        // and create a new row in the database
        if ($newRevision) {
            $field->id = null;
            $field->exists = false;
        }

        $field->revision_id = $this->revision->id;

        $field->save();
    }
900714
public function storeFieldData(VersionInfo $versionInfo, Field $field)
    {
        foreach ($field->value->externalData as $priority => $tag) {
            $insertQuery = $this->connection->createQueryBuilder();
            $insertQuery
                ->insert($this->connection->quoteIdentifier('eztags_attribute_link'))
                ->values(
                    [
                        'keyword_id' => ':keyword_id',
                        'objectattribute_id' => ':objectattribute_id',
                        'objectattribute_version' => ':objectattribute_version',
                        'object_id' => ':object_id',
                        'priority' => ':priority',
                    ]
                )
                ->setParameter(':keyword_id', $tag['id'], PDO::PARAM_INT)
                ->setParameter(':objectattribute_id', $field->id, PDO::PARAM_INT)
                ->setParameter(':objectattribute_version', $versionInfo->versionNo, PDO::PARAM_INT)
                ->setParameter(':object_id', $versionInfo->contentInfo->id, PDO::PARAM_INT)
                ->setParameter(':priority', $priority, PDO::PARAM_INT);

            $insertQuery->execute();
        }
    }
334481
public function insertEntityRevision($revision, FormData $requestData, $subResource = NULL) {
    $entity = $this->createEmptyEntity($revision);
    
    if ($subResource !== NULL && array_key_exists($subResource, $this->customActions)) {
      return $this->callCustomAction($this->customActions[$subResource], array($entity, $requestData, $revision));
    }
    
    $this->updateEntityRevision($entity, $revision, $requestData);
    $this->setOpenTabMetadata($entity);
    
    return $entity;
  }
558037
public function save()
    {
        if (!$this->oxrecommlists__oxtitle->value) {
            throw oxNew(\OxidEsales\Eshop\Core\Exception\ObjectException::class, 'EXCEPTION_RECOMMLIST_NOTITLE');
        }
        $this->onSave();

        return parent::save();
    }
665549
protected function assertField($field)
    {
        if (!$this->hasField($field)) {
            throw new ModelException(sprintf('Unknown field, field "%s" not found in model "%s"', $field, $this->entity));
        }
    }
747779
public function setNewValue(string $field, $value) : void
    {
        $this->assertValidField($field);

        $this->documentChangeSet[$field][1] = $value;
        $this->getDocumentManager()->getUnitOfWork()->setDocumentChangeSet($this->getDocument(), $this->documentChangeSet);
    }
665896
protected function updateFormField($field)
    {
        parent::updateFormField($field);

        if ($this->MinValue) {
            $field->setAttribute('data-rule-min', $this->MinValue);
        }

        if ($this->MaxValue) {
            $field->setAttribute('data-rule-max', $this->MaxValue);
        }
    }
210048
public function addField(Field $field)
    {
        $tmp               = $this->fields->getValue($this->entity);
        $tmp[$field->name] = $field;
        $this->fields->setValue($this->entity, $tmp);

        if ($field->role == 'id') {
            $key = new \ReflectionProperty(Entity::class, 'key');
            $key->setAccessible(true);
            $key->setValue($this->entity, $field->name);
        }
    }
937090
private function assertValidField($field)
    {
        if ( ! isset($this->entityChangeSet[$field])) {
            throw new \InvalidArgumentException(sprintf(
                'Field "%s" is not a valid field of the entity "%s" in PreUpdateEventArgs.',
                $field,
                get_class($this->getEntity())
            ));
        }
    }
826657
public function postSave()
    {
        if ($this->updating) {
            foreach ($this->changedRevisionableFields() as $key => $change) {
                RevisionRepository::create([
                    'revisionable_type' => get_class($this),
                    'revisionable_id'   => $this->getKey(),
                    'key'               => $key,
                    'old_value'         => $this->getDataValue('original', $key),
                    'new_value'         => $this->getDataValue('updated', $key),
                    'user_id'           => $this->getUserId(),
                ]);
            }
        } else {
            RevisionRepository::create([
                'revisionable_type' => get_class($this),
                'revisionable_id'   => $this->getKey(),
                'key'               => 'created_at',
                'old_value'         => null,
                'new_value'         => new DateTime(),
                'user_id'           => $this->getUserId(),
            ]);
        }
    }
1353038
protected function saveRevision($publishRevision)
    {
        if (!$this->revision->exists && !$publishRevision) {
            $this->revision->published = $publishRevision;
        }

        $this->revision->content_id = $this->content->id;
        $this->revision->save();

        if ($publishRevision) {
            $this->unpublishOtherRevisions();
        }
    }
569764
public function isPresenceRequired($field, $newRecord)
    {
        $providers = $this->_providers;
        $data = [];
        $context = compact('data', 'newRecord', 'field', 'providers');

        return !$this->_checkPresence($this->field($field), $context);
    }
1028741
public function createCustomField(Field $field)
		{
			$form_data = array(
				'fieldname' => $field->getName(),
				'fieldtype' => $field->getType(),
				'description' => $field->getDescription()
			);
			$this->call('customfieldcreate', $form_data);

			return TRUE;
		}
1295636
public function storeFileReference(VersionInfo $versionInfo, Field $field)
    {
        $referencedData = $this->getFileReferenceData($field->id, $versionInfo->versionNo);

        if ($referencedData === null) {
            $this->storeNewFieldData($versionInfo, $field);
        } elseif (is_array($referencedData) && !empty(array_diff_assoc($referencedData, $field->value->externalData))) {
            $this->updateFieldData($versionInfo, $field);
        }

        return false;
    }
1365687
public function renameFile($name, $newName)
    {
        foreach ($this->getAllFields() as $field) {
            $path = $this->getFilePath($field, $name);
            $newPath = $this->getFilePath($field, $newName);
            if (file_exists($newPath)) {
                throw new \Exception("File {$newName} already exists");
            }
            rename($path, $newPath);
        }
        if ($name == $this->owner->getAttribute($this->fileField)
            && ($files = $this->getFileList())
        ) {
            $this->owner->updateAttributes([$this->fileField => $newName]);
        }
        return true;
    }
128940
protected function saveRules(CustomField $field, Field $customfield)
    {
        $rules = array_get($field->getRules(), $field->name, []);
        foreach ($rules as $rule) {
            $validator = FieldValidator::query()->where(['name' => $rule])->first();
            $config    = [
                'field_id' => $customfield->id
            ];
            if (is_null($validator)) {
                $validator       = FieldValidator::query()->where(['name' => 'custom'])->firstOrFail();
                $config['value'] = $rule;
            }
            array_set($config, 'validator_id', $validator->id);
            FieldValidatorConfig::query()->firstOrNew($config)->save();
        }
        return true;
    }
1352412
public function storeFileReference(VersionInfo $versionInfo, Field $field)
    {
        $connection = $this->getConnection();

        $insertQuery = $connection->createInsertQuery();
        $insertQuery->insertInto(
            $connection->quoteTable($this->getStorageTable())
        );

        $this->setInsertColumns($insertQuery, $versionInfo, $field);

        $insertQuery->prepare()->execute();

        return false;
    }