On submit record. Update the category relations.

@param DataContainer $dc
764026
public function onSubmitCallback(DataContainer $dc)
    {
        // Return if the user is allowed to assign categories or the record is not new
        if ($this->permissionChecker->canUserAssignCategories() || $dc->activeRecord->tstamp > 0) {
            return;
        }

        $dc->field = 'categories';

        $relations = new Relations();
        $relations->updateRelatedRecords($this->permissionChecker->getUserDefaultCategories(), $dc);

        // Reset back the field property
        $dc->field = null;
    }
93866
public function onLoadDataContainer(string $table): void
    {
        if (!isset($GLOBALS['TL_DCA'][$table]['fields']) || !\is_array($GLOBALS['TL_DCA'][$table]['fields'])) {
            return;
        }

        $hasTagsFields = false;

        foreach ($GLOBALS['TL_DCA'][$table]['fields'] as $name => &$field) {
            if ('cfgTags' !== $field['inputType']) {
                continue;
            }

            $hasTagsFields = true;
            $manager = $this->registry->get($field['eval']['tagsManager']);

            if ($manager instanceof DcaAwareInterface) {
                $manager->updateDcaField($field);
            }
        }

        // Add assets for backend
        if (TL_MODE === 'BE' && $hasTagsFields) {
            $this->addAssets();
        }
    }
269843
public function deleteMemberWishEntries(\DataContainer $dc) {
		if ($dc->activeRecord) {
			$db = \Database::getInstance();
			//SmS Course Choice
			$db->prepare("DELETE FROM tl_sms_course_choice WHERE id = ?")->execute($dc->activeRecord->id);
			//SmS Exchange
			$db->prepare("DELETE FROM tl_sms_exchange WHERE student = ?")->execute($dc->activeRecord->id);
			//TdW Choice
			$db->prepare("DELETE FROM tl_tdwChoices WHERE student = ?")->execute($dc->activeRecord->id);
		}
	}
1192678
protected function submitAddCity()
    {
        $this->setSubmitted(null, $this->getParam());
        $this->validateComponent('city');
        $this->addCity();
    }
423587
public function update($id, $dbConnection = NULL)
    {
        $connection = DatabaseQuery::checkConnection($dbConnection);

        $updateQuery = $this->updateQuery(self::getTableName($connection), $id);
        $statement = $connection->prepare($updateQuery);
        if ($statement->execute()) {
            return true;
        }
        throw new  DataAlreadyExistException();
    }
351490
protected function updateCategory($category_id)
    {
        if (!$this->isError() && !$this->category->update($category_id, $this->getSubmitted())) {
            $this->errorAndExit($this->text('Unexpected result'));
        }
    }
921098
public function updatePivotRecords()
    {
        $pivots = $this->entityMap->getPivotRelationships();

        foreach ($pivots as $pivot) {
            if (array_key_exists($pivot, $this->relationships)) {
                $this->updatePivotRelation($pivot);
            }
        }
    }
17677
public function updateFromObject(stdClass $object)
    {

        $this->name  = property_exists($object, 'name') ? $object->name : null;
        $this->email = property_exists($object, 'email') ? $object->email : null;
    }
1270451
public function preUpdate(PreUpdateEventArgs $event)
    {
        $entity = $event->getEntity();
        if ($entity instanceof CategorizableInterface) {
            $this
                ->categoryIntegrityFixer
                ->fixCategoriesIntegrity($entity);
        }
    }
911853
public function onLoadCallback(DataContainer $dc)
    {
        if (!$dc->id) {
            return;
        }

        /** @var Input $input */
        $input = $this->framework->getAdapter(Input::class);

        // Handle the edit all modes differently
        if ($input->get('act') === 'editAll' || $input->get('act') === 'overrideAll') {
            $categories = $this->db->fetchColumn('SELECT categories FROM tl_news_archive WHERE limitCategories=1 AND id=?', [$dc->id]);
        } else {
            $categories = $this->db->fetchColumn('SELECT categories FROM tl_news_archive WHERE limitCategories=1 AND id=(SELECT pid FROM tl_news WHERE id=?)', [$dc->id]);
        }

        if (!$categories || 0 === \count($categories = StringUtil::deserialize($categories, true))) {
            return;
        }

        $GLOBALS['TL_DCA'][$dc->table]['fields']['categories']['eval']['rootNodes'] = $categories;
    }
1083831
protected function updateCategories(Collection $data)
	{
		$ids = explode(',', $this->preferences['product_categories']);

		$categories = Collection::make($ids)
			->merge($data)
			->unique()
			->take(self::MAX_TAGS)
			->implode(',');

		$this->preferences['product_categories'] = trim($categories, ',');
	}
1337438
protected function addCategory()
    {
        if (!$this->isError()) {
            $id = $this->category->add($this->getSubmitted());
            if (empty($id)) {
                $this->errorAndExit($this->text('Unexpected result'));
            }
            $this->line($id);
        }
    }
696354
public function updateFromFormData($data)
    {
        $cmsFields = $this->getCMSFields();

        foreach ($data as $field => $datum) {
            $field = $cmsFields->dataFieldByName($field);

            if (!$field) {
                continue;
            }

            $field->setSubmittedValue($datum);
            $field->saveInto($this);
        }
    }
557696
private function reloadNewsCategoriesWidget(DataContainer $dc)
    {
        /**
         * @var Database
         * @var Input    $input
         */
        $db = $this->framework->createInstance(Database::class);
        $input = $this->framework->getAdapter(Input::class);

        $id = $input->get('id');
        $field = $dc->inputName = $input->post('name');

        // Handle the keys in "edit multiple" mode
        if ('editAll' === $input->get('act')) {
            $id = \preg_replace('/.*_([0-9a-zA-Z]+)$/', '$1', $field);
            $field = \preg_replace('/(.*)_[0-9a-zA-Z]+$/', '$1', $field);
        }

        $dc->field = $field;

        // The field does not exist
        if (!isset($GLOBALS['TL_DCA'][$dc->table]['fields'][$field])) {
            $this->logger->log(
                LogLevel::ERROR,
                \sprintf('Field "%s" does not exist in DCA "%s"', $field, $dc->table),
                ['contao' => new ContaoContext(__METHOD__, TL_ERROR)]
            );

            throw new BadRequestHttpException('Bad request');
        }

        $row = null;
        $value = null;

        // Load the value
        if ('overrideAll' !== $input->get('act') && $id > 0 && $db->tableExists($dc->table)) {
            $row = $db->prepare('SELECT * FROM '.$dc->table.' WHERE id=?')->execute($id);

            // The record does not exist
            if ($row->numRows < 1) {
                $this->logger->log(
                    LogLevel::ERROR,
                    \sprintf('A record with the ID "%s" does not exist in table "%s"', $id, $dc->table),
                    ['contao' => new ContaoContext(__METHOD__, TL_ERROR)]
                );

                throw new BadRequestHttpException('Bad request');
            }

            $value = $row->$field;
            $dc->activeRecord = $row;
        }

        // Call the load_callback
        if (\is_array($GLOBALS['TL_DCA'][$dc->table]['fields'][$field]['load_callback'])) {
            /** @var System $systemAdapter */
            $systemAdapter = $this->framework->getAdapter(System::class);

            foreach ($GLOBALS['TL_DCA'][$dc->table]['fields'][$field]['load_callback'] as $callback) {
                if (\is_array($callback)) {
                    $value = $systemAdapter->importStatic($callback[0])->{$callback[1]}($value, $dc);
                } elseif (\is_callable($callback)) {
                    $value = $callback($value, $dc);
                }
            }
        }

        // Set the new value
        $value = $input->post('value', true);

        // Convert the selected values
        if ($value) {
            /** @var StringUtil $stringUtilAdapter */
            $stringUtilAdapter = $this->framework->getAdapter(StringUtil::class);
            $value = $stringUtilAdapter->trimsplit("\t", $value);
            $value = \serialize($value);
        }

        /** @var NewsCategoriesPickerWidget $strClass */
        $strClass = $GLOBALS['BE_FFL']['newsCategoriesPicker'];

        /** @var NewsCategoriesPickerWidget $objWidget */
        $objWidget = new $strClass($strClass::getAttributesFromDca($GLOBALS['TL_DCA'][$dc->table]['fields'][$field], $dc->inputName, $value, $field, $dc->table, $dc));

        throw new ResponseException(new Response($objWidget->generate()));
    }
1074800
public function editLocationStyle(DataContainer $dc)
   	{
   		return ($dc->value < 1) ? '' : ' <a href="contao/main.php?do=c4g_map_locstyles&amp;act=edit&amp;id=' . $dc->value . '&amp;popup=1&amp;nb=1&amp;rt=' . REQUEST_TOKEN . '" title="' . sprintf(specialchars($GLOBALS['TL_LANG']['tl_c4g_maps']['editalias'][1]), $dc->value) . '" style="padding-left:3px" onclick="Backend.openModalIframe({\'width\':768,\'title\':\'' . specialchars(str_replace("'", "\\'", sprintf($GLOBALS['TL_LANG']['tl_c4g_maps']['editalias'][1], $dc->value))) . '\',\'url\':this.href});return false">' . Image::getHtml('alias.gif', $GLOBALS['TL_LANG']['tl_c4g_maps']['editalias'][0], 'style="vertical-align:top"') . '</a>';
   	}
563946
public function updateUserViewedCategory($categoryId = '')
    {
        $sessionUserViewedCategoryId = self::SESSION_ID_USER_VIEW_TOTAL_POST_BY_CATEGORY_FROM_SESSION . $categoryId;
        $this->logger->debug(__FUNCTION__, '$sessionUserViewedCategoryId => ' . json_encode($sessionUserViewedCategoryId));
        $checkSessionUserViewedCategoryValue = $this->hasSessionData($sessionUserViewedCategoryId);
        $this->logger->debug(__FUNCTION__, '$checkSessionUserViewedCategoryValue => ' . json_encode($checkSessionUserViewedCategoryValue));
        if ($checkSessionUserViewedCategoryValue === TRUE) {
            $currentSessionUserViewedCategoryValue = $this->getSessionData($sessionUserViewedCategoryId);
            $this->logger->debug(__FUNCTION__, '$currentSessionUserViewedCategoryValue => ' . json_encode($currentSessionUserViewedCategoryValue));
            if (is_numeric($currentSessionUserViewedCategoryValue)) {
                $viewValue = $currentSessionUserViewedCategoryValue + 1;
            } else {
                $viewValue = 1;
            }
            $this->logger->debug(__FUNCTION__, 'Update Total View Value: ' . $viewValue);
            $this->saveSessionData($sessionUserViewedCategoryId, $viewValue);
        } else {
            $this->saveSessionData($sessionUserViewedCategoryId, 1);
        }
    }
74346
public function deleteFile(\DataContainer $dc)
  {
    $filePath = TL_ROOT . '/' . $this->getFullFilePath($dc->activeRecord->data_file_name, $dc);
    if (file_exists($filePath))
    {
      unlink($filePath);
    }
  }