executionContext = $executionContext; } /** * @return IdManager * @deprecated use {@link ExecutionContext::getIdManager()} instead * via {@link ExecutionContext::getExecutingMarkupHandler()} */ static function getOrCreate(): IdManager { return ExecutionContext::getActualOrCreateFromEnv()->getIdManager(); } public function generateNewHtmlIdForComponent(string $componentId, Path $executingPath = null): string { if ($executingPath === null) { try { $executingPath = $this->executionContext ->getExecutingMarkupHandler() ->getExecutingPathOrNull(); } catch (ExceptionNotFound $e) { // ok, dynamic, markup string run ? } } $idScope = $componentId; if ($executingPath !== null) { try { $slotName = $executingPath->getLastNameWithoutExtension(); $idScope = "$idScope-$slotName"; } catch (ExceptionNotFound $e) { // no name (ie root) } } $lastId = self::generateAndGetNewSequenceValueForScope($idScope); return Html::toHtmlId("$idScope-$lastId"); } private function generateAndGetNewSequenceValueForScope(string $scope) { $lastId = $this->lastIdByScope[$scope] ?? null; if ($lastId === null) { $lastId = 1; } else { $lastId = $lastId + 1; } $this->lastIdByScope[$scope] = $lastId; return $lastId; } }