On before write hook.
Check if any translatable field has changed and if permissions are sufficient
@see DataExtension::onBeforeWrite()
501866
public function onBeforeWrite()
    {
        if (!isset(self::$localizedFields[$this->ownerBaseClass])) {
            return;
        }

        $fields = self::$localizedFields[$this->ownerBaseClass];
        foreach ($fields as $field => $localized) {
            foreach (self::get_target_locales() as $locale) {
                $fieldName = self::localized_field($field, $locale);
                if ($this->owner->isChanged($fieldName, 2) && !$this->canTranslate(null, $locale)) {
                    throw new PermissionFailureException(
                        "You're not allowed to edit the locale '$locale' for this object");
                }
            }
        }
    }
127217
function onWritten(writeErr) {
      var flags = fo.getFlags({
        overwrite: optResolver.resolve('overwrite', file),
        append: optResolver.resolve('append', file),
      });
      if (fo.isFatalOverwriteError(writeErr, flags)) {
        return callback(writeErr);
      }

      callback(null, file);
    }
689185
public function onAfterWrite() {
        $store = $this->targetStore();
        if (strlen($store)) {
            Config::inst()->update('File', 'update_filesystem', false);

            // however, lets also ensure the changed filename file update check is run
            // which is otherwise triggered by updateFilesystem
            $changedFields = $this->owner->getChangedFields();

            // $this->owner->IgnorePathChanges gets set by the rename path job
            if (isset($changedFields['Filename']) && !$this->owner->IgnorePathChanges && $this->owner instanceof File) {
                $pathBefore = $changedFields['Filename']['before'];
                $pathAfter = $changedFields['Filename']['after'];

                if($pathBefore && $pathBefore != $pathAfter) {
                    // update links call
                    $this->owner->extend('updateLinks', $pathBefore, $pathAfter);

                    $children = File::get()->filter('ParentID', $this->owner->ID);
                    if ($children->count() > 0) {
                        if (class_exists('QueuedJobService')) {
                            singleton('QueuedJobService')->queueJob(new RenameFolderPathJob($this->owner, $children));
                        } else {
                            $this->updateChildFolderLinks($children, $pathBefore, $pathAfter);
                        }
                    }
                }
            }
        }
        parent::onAfterWrite();
    }
1051551
public function setPreferWrite()
    {
        //====================================================================//
        // Safety Checks ==> Verify a new Field Exists
        if (empty($this->new)) {
            Splash::log()->err("ErrFieldsNoNew");
        } else {
            //====================================================================//
            // Update New Field structure
            $this->new->syncmode = self::MODE_WRITE;
        }

        return $this;
    }
107950
public function onBeforeWrite()
    {
        if (!$this->Sort) {
            $this->Sort = DB::query('SELECT MAX("Sort") + 1 FROM "WorkflowTransition"')->value();
        }

        parent::onBeforeWrite();
    }
836067
public function beforeHook() : void
    {
        $this->commentChar = $this->repository->getConfigOperator()->getSafely('core.commentchar', '#');
        $this->file        = (string)$this->arguments->get('file');
        $this->mode        = (string)$this->arguments->get('mode');
        $this->hash        = (string)$this->arguments->get('hash');

        if (empty($this->file)) {
            throw new \RuntimeException('commit message file argument is missing');
        }

        parent::beforeHook();
    }
877734
public function onAfterWrite() {
		if (!self::$indexing) return;

		// No longer doing the 'ischanged' check to avoid problems with multivalue field NOT being indexed
		//$changes = $this->owner->getChangedFields(true, 2);
			
		$stage = null;
		// if it's being written and a versionable, then save only in the draft
		// repository. 
		if ($this->owner->hasMethod('canBeVersioned') && $this->owner->canBeVersioned($this->owner->baseTable())) {
            $stage = Versioned::current_stage();
		}

		if ($this->canShowInSearch()) {
            // DataObject::write() does _not_ set LastEdited until _after_ onAfterWrite completes
            $this->owner->LastEdited = date('Y-m-d H:i:s');
			$this->reindex($stage);
		}
	}
570688
public function onAfterWrite()
    {
        parent::onAfterWrite();

        if ($this->owner->PasswordEncryption != Security::config()->get('password_encryption_algorithm')) {
            $this->resetPasswordEncryption();
        }
    }
1260956
public function onBeforePublish()
    {
        /**
         * @var DBDatetime $publishDate
         */
        $publishDate = $this->dbObject('PublishDate');
        if (!$publishDate->getValue()) {
            $this->PublishDate = DBDatetime::now()->getValue();
            $this->write();
        }

        $this->Summary = trim($this->Summary);

        $this->extend('onBeforePublish');
    }
135299
protected function before()
    {
        if (    empty($this->client)
            ||  empty($this->clientHash)
            ||  $this->clientHash !== $this->makeSoapClientHash()
        ) {
            $this->initializeClient();
        }
    }
548923
public function onBeforeWrite()
    {
        parent::onBeforeWrite();

        $vars = $this->record;

        if (isset($vars['DirectUpdate'])) {
            // Unset now so that we don't end up in an infinite loop!
            unset($this->record['DirectUpdate']);
            $this->updateWorkflow($vars);
        }
    }
1270639
public function onAfterWrite()
    {
        parent::onAfterWrite();

        // Request via ImportForm where TemplateVersion is already set, so unset it
        $posted = Controller::curr()->getRequest()->postVars();
        if (isset($posted['_CsvFile']) && $this->TemplateVersion) {
            $this->TemplateVersion = null;
        }
        if ($this->numChildren() == 0 && $this->Template && !$this->TemplateVersion) {
            $this->getWorkflowService()->defineFromTemplate($this, $this->Template);
        }
    }
569141
public function onBeforeWrite()
    {
        $maps = array(
            /** URL Mapping */
            'TagAction',
            'TagsAction',
            'ShowAction',
            'AuthorAction',
            'ArchiveAction',
        );
        foreach ($maps as $map) {
            if ($this->owner->$map) {
                $this->owner->$map = singleton('SiteTree')->generateURLSegment($this->owner->$map);
            }
        }
        $newsFolder = Folder::find_or_make(Config::inst()->get($this->class, 'uploads_folder'));
        $this->owner->NewsRootFolderID = $newsFolder->ID;
    }
970504
public function onBeforeWrite() {
		parent::onBeforeWrite();
		if(!$this->isInDb()) {
			$this->_isCreating = true;
			$this->extend('onBeforeCreate');
		}
		if($this->isChanged('MemberID')) {
			$this->extend('onMemberLinked');
		}
	}
512870
public function onBeforeWrite()
    {
        // Set the title of the attendee
        $this->Title = $this->getName();

        // Generate the ticket code
        if ($this->exists() && empty($this->TicketCode)) {
            $this->TicketCode = $this->generateTicketCode();
        }

        if (
            $this->getEmail()
            && $this->getName()
            && !$this->TicketFile()->exists()
            && !$this->TicketQRCode()->exists()
        ) {
            $this->createQRCode();
            $this->createTicketFile();
        }

        if ($fields = $this->Fields()) {
            foreach ($fields as $field) {
                if ($value = $this->{"$field->Name[$field->ID]"}) {
                    //$cache = self::getCacheFactory();
                    //$cache->save(serialize($value), $this->getFieldCacheKey($field));
                    $fields->add($field->ID, array('Value' => $value));
                }
            }
        }

        parent::onBeforeWrite();
    }
792872
public function triggerBeforeFind()
    {
        if (!$this->_beforeFindFired && $this->_type === 'select') {
            $this->_beforeFindFired = true;

            /** @var \Cake\Event\EventDispatcherInterface $repository */
            $repository = $this->getRepository();
            $repository->dispatchEvent('Model.beforeFind', [
                $this,
                new ArrayObject($this->_options),
                !$this->isEagerLoaded()
            ]);
        }
    }
1315126
public function onBeforeWrite()
    {
        $owner = $this->owner;
        if(!$owner->ID && !$owner->SubsiteID){
            $owner->SubsiteID = Subsite::currentSubsiteID();
        }
        parent::onBeforeWrite();
    }