Auto-generate an element alias and adjust existing content in case the element is renamed

@param DataContainer $dc
175527
public function generateAlias (DataContainer $dc)
	{
		$db = Database::getInstance();

		// Generate alias from theme name and title
		$alias = \StringUtil::generateAlias(\ThemeModel::findById($dc->activeRecord->pid)->name . '-' . $dc->activeRecord->title);
		
		if ($alias != $dc->activeRecord->alias)
		{
			// Save alias to database
			$db->prepare("UPDATE tl_elements SET alias=? WHERE id=?")
			   ->execute($alias, $dc->activeRecord->id);
		
			if ($dc->activeRecord->alias)
			{
				// Also change the type (=alias) in tl_content table
				$db->prepare("UPDATE tl_content SET type=? WHERE type=?")
				   ->execute($alias, $dc->activeRecord->alias);
			}
		}
	}
773552
public function getContentElementTemplates(DataContainer $dc)
	{
		$arrTemplates = array();

		// Get the default templates
		foreach (\TemplateLoader::getPrefixedFiles('ce_') as $strTemplate)
		{
			$arrTemplates[$strTemplate][] = 'root';
		}

		$arrCustomized = glob(TL_ROOT . '/templates/ce_*');

		// Add the customized templates
		if (is_array($arrCustomized))
		{
			foreach ($arrCustomized as $strFile)
			{
				$strTemplate = basename($strFile, strrchr($strFile, '.'));
				$arrTemplates[$strTemplate][] = $GLOBALS['TL_LANG']['MSC']['global'];
			}
		}

		// Add the customized theme templates
		$theme = \ThemeModel::findById($dc->activeRecord->pid);
		
		$arrCustomized = glob(TL_ROOT . '/' . $theme->templates . '/' . 'ce_*');
		if (is_array($arrCustomized))
		{
			foreach ($arrCustomized as $strFile)
			{
				$strTemplate = basename($strFile, strrchr($strFile, '.'));
				$arrTemplates[$strTemplate][] = $theme->name;
			}
		}

		// Show the template sources
		foreach ($arrTemplates as $k=>$v)
		{
			$v = array_filter($v, function($a) {
				return $a != 'root';
			});
			if (empty($v))
			{
				$arrTemplates[$k] = $k;
			}
			else
			{
				$arrTemplates[$k] = $k . ' (' . implode(', ', $v) . ')';
			}
		}

		// Sort the template names
		ksort($arrTemplates);
		
		return $arrTemplates;
	}
666496
public function rename($groupName, $newName, $container)
    {
        $groupDn = $this->dn($groupName);

        if ($groupDn) {
            $newRDN = 'CN='.$newName;

            // Determine the container
            $container = array_reverse($container);
            $container = 'OU='.implode(', OU=', $container);

            $dn = $container.', '.$this->adldap->getBaseDn();

            return $this->connection->rename($groupDn, $newRDN, $dn, true);
        }

        return false;
    }
409160
public function setRestrictions($dataContainerName = null, $propertyName = null)
    {
        parent::setRestrictions($dataContainerName);
        $this->propertyName = $propertyName;
    }
1204196
public function showAlreadyUsedHint($dc)
	{
		if ($GLOBALS['_POST'] || \Input::get('act') != 'edit')
		{
			return;
		}

		// Return if the user cannot access the layout module (see #6190)
		if (!$this->User->hasAccess('themes', 'modules') || !$this->User->hasAccess('layout', 'themes'))
		{
			return;
		}

		// Check if the content block is in use
		$objPattern = \PatternModel::findById($dc->id);
		
		while ($objPattern->ptable != 'tl_elements')
		{
			$objPattern = \PatternModel::findById($objPattern->pid);
		}
		
		$objElement = \ElementsModel::findById($objPattern->pid);
		
		if (\ContentModel::countBy('type', $objElement->alias) > 0)
		{
			\Message::addInfo($GLOBALS['TL_LANG']['MSC']['elementInUse']);
		}
	}
308104
public function onloadCallback($dc)
	{
		if (\Input::get('act') === 'create') {
			return;
		}

		if (\Input::get('act') === 'edit') {
			$this->reloadConfig();
		}

		if ($dc->table === 'tl_content' && class_exists('CeAccess')) {
			$ceAccess = new \CeAccess;
			$ceAccess->filterContentElements($dc);
		}

		if (\Input::get('act') === 'editAll') {
			return $this->createDcaMultiEdit($dc);
		}

		$type = $this->getDcaFieldValue($dc, 'type');
		if (!$type || substr($type, 0, 5) !== 'rsce_') {
			return;
		}

		$data = $this->getDcaFieldValue($dc, 'rsce_data', true);
		if ($data && substr($data, 0, 1) === '{') {
			$this->data = json_decode($data, true);
		}

		$createFromPost = \Input::post('FORM_SUBMIT') === $dc->table;
		$tmpField = null;

		if (\Input::get('field') && substr(\Input::get('field'), 0, 11) === 'rsce_field_') {
			// Ensures that the fileTree oder pageTree field exists
			$tmpField = \Input::get('field');
		}
		elseif (
			\Input::get('target')
			&& ($target = explode('.', \Input::get('target'), 3))
			&& $target[0] === $dc->table
			&& substr($target[1], 0, 11) === 'rsce_field_'
		) {
			// Ensures that the fileTree oder pageTree field exists
			$tmpField = $target[1];
		}
		elseif (\Input::post('name') && substr(\Input::post('name'), 0, 11) === 'rsce_field_') {
			// Ensures that the fileTree oder pageTree field exists
			$tmpField = \Input::post('name');
		}

		$this->createDca($dc, $type, $createFromPost, $tmpField);
	}
232797
public function reduceFilePath($varValue, \DataContainer $dc)
  {
    $doc = $dc->activeRecord;

    $path = \FilesModel::findByUuid($varValue)->path;

    $arrFileNameParts = \Document::splitFileName(substr($path, strlen(\DmsConfig::getBaseDirectory(true))));

    // TODO (#33): reset the new fileType
    // TODO (#33): reset the new fileSize
    // TODO (#33): get version parts from POST ... maybe changed ... or reduce fileName via finding and counting underscores and removing them
    return $arrFileNameParts['fileName'];
  }
971518
public function setDateAdded(DataContainer $dc)
    {
        $modelUtil = $this->container->get('huh.utils.model');

        if (null === $dc || null === ($model = $modelUtil->findModelInstanceByPk($dc->table, $dc->id)) || $model->dateAdded > 0) {
            return null;
        }

        $this->framework->createInstance(Database::class)->prepare("UPDATE $dc->table SET dateAdded=? WHERE id=? AND dateAdded = 0")->execute(time(), $dc->id);
    }
1191197
public function setLocLat($varValue, \DataContainer $dc)
    {
        if ($varValue != 0)
        {
            if (!Utils::validateLat($varValue))
            {
                throw new \Exception($GLOBALS['TL_LANG']['c4g_maps']['geoy_invalid']);
            }
        }
        return $varValue;
    }
1296187
public function createContainer()
    {
        if (empty($this->containerName)) {
            throw new DcGeneralRuntimeException('Required container name is missing');
        }

        if (null === $this->eventDispatcher) {
            throw new DcGeneralRuntimeException('Required event dispatcher is missing');
        }

        /** @var DataDefinitionContainerInterface $definitions */
        $definitions = System::getContainer()->get('cca.dc-general.data-definition-container');

        if ($definitions->hasDefinition($this->containerName)) {
            return clone $definitions->getDefinition($this->containerName);
        }

        /** @var ContainerInterface $dataContainer */
        $dataContainer = (new \ReflectionClass($this->containerClassName))->newInstance($this->containerName);

        // Backwards compatibility.
        $this->getEventDispatcher()->dispatch(
            BuildDataDefinitionEvent::NAME,
            new BuildDataDefinitionEvent($dataContainer)
        );

        $definitions->setDefinition($this->containerName, $dataContainer);

        return clone $dataContainer;
    }
964569
public function adjustAlias($value, $dc)
    {
        // Nothing to adjust if no folderUrls
        if (!Config::get('folderUrl')) {
            return $value;
        }

        // If current page is of type folder, update children
        if ($dc->activeRecord && $dc->activeRecord->type === 'folder') {
            $childRecords = Database::getInstance()->getChildRecords([$dc->id], 'tl_page');
            $this->updateChildren($childRecords);

            return $value;
        }

        $tl_page = new \tl_page();

        // Clean the alias
        $value = $this->cleanAlias($value);

        try {
            $value = $tl_page->generateAlias($value, $dc);
        } catch (\Exception $e) {
            // The alias already exists so add ID just like the original method would
            $value = $value.'-'.$dc->id;

            // Validate the alias once again and throw an error if it exists
            $value = $tl_page->generateAlias($value, $dc);
        }

        return $value;
    }
884372
public function getOriginalFileNameWidget(\DataContainer $dc)
  {
    $doc = $dc->activeRecord;

    return '
<div class="w50 widget">
  <h3><label for="ctrl_purge">'.$GLOBALS['TL_LANG']['tl_dms_documents']['data_file_name_org'][0].'</label></h3>
  <input type="text" class="tl_text" value="' . $doc->data_file_name . '" disabled="">
  <p class="tl_help tl_tip">'.$GLOBALS['TL_LANG']['tl_dms_documents']['data_file_name_org'][1].'</p>
</div>';
  }
22122
public function appendColumnsetIdToPalette($dc)
	{
		if($GLOBALS['TL_CONFIG']['subcolumns'] != 'bootstrap_customizable') {
			return;
		}

		if($dc->table == 'tl_content') {
			$model = \ContentModel::findByPK($dc->id);

			if($model->sc_type > 0) {
				\MetaPalettes::appendFields($dc->table, 'colsetStart', 'colset', array('columnset_id'));
			}
		}
		else {
			$model = \ModuleModel::findByPk($dc->id);

			if($model->sc_type > 0) {
				if($model->sc_type > 0) {
					$GLOBALS['TL_DCA']['tl_module']['palettes']['subcolumns'] = str_replace(
						'sc_type,',
						'sc_type,columnset_id,',
						$GLOBALS['TL_DCA']['tl_module']['palettes']['subcolumns']
					);
				}
			}
		}
	}
15328
public function rename_table(xmldb_table $xmldb_table, $newname) {
        // Check newname isn't empty
        if (!$newname) {
            throw new ddl_exception('ddlunknownerror', null, 'newname can not be empty');
        }

        $check = new xmldb_table($newname);

        // Check table already renamed
        if (!$this->table_exists($xmldb_table)) {
            if ($this->table_exists($check)) {
                throw new ddl_exception('ddlunknownerror', null, 'table probably already renamed');
            } else {
                throw new ddl_table_missing_exception($xmldb_table->getName());
            }
        }

        // Check new table doesn't exist
        if ($this->table_exists($check)) {
            throw new ddl_exception('ddltablealreadyexists', $check->getName(), 'can not rename table');
        }

        if (!$sqlarr = $this->generator->getRenameTableSQL($xmldb_table, $newname)) {
            throw new ddl_exception('ddlunknownerror', null, 'table rename sql not generated');
        }

        $this->execute_sql_arr($sqlarr);
    }
579263
public function setSourceOptions($value, $dc)
	{
		$db = Database::getInstance();
		
		if ($value == 'video' || $value == 'audio')
		{
			if (!$dc->activeRecord->multiSource)
			{
				// Change multiSource in database
				$db->prepare("UPDATE " . $this->table . " SET multiSource=? WHERE id=?")
				   ->execute(1, $dc->activeRecord->id);
			}
			if ($dc->activeRecord->sortBy != 'html5media')
			{
				// Change sortBy in database
				$db->prepare("UPDATE " . $this->table . " SET sortBy=? WHERE id=?")
				   ->execute('html5media', $dc->activeRecord->id);
			}
			if ($dc->activeRecord->canChangeSortBy)
			{
				// Change canChangeSortBy in database
				$db->prepare("UPDATE " . $this->table . " SET canChangeSortBy=? WHERE id=?")
				   ->execute(0, $dc->activeRecord->id);
			}
		}
		
		return $value;
	}
969171
public function generatePanelName($value, $dataContainer): string
    {
        if (!$value) {
            $value = 'panel_' . $dataContainer->activeRecord->id;
        }

        return $value;
    }
592731
public function setLocLat($varValue, \DataContainer $dc)
    {
        if ($varValue != 0)
        {
            if (!\con4gis\MapsBundle\Resources\contao\classes\Utils::validateLat($varValue))
            {
                throw new \Exception($GLOBALS['TL_LANG']['c4g_maps']['geoy_invalid']);
            }
        }
        return $varValue;
    }