-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a2ee7a
commit b08e771
Showing
6 changed files
with
64 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace HeroesofAbenez\Chat; | ||
|
||
use Nette\Application\UI\Form; | ||
use Nette\Localization\ITranslator; | ||
use Nexendrie\Translation\Translator; | ||
use Nexendrie\Translation\Loaders\NeonLoader; | ||
|
||
/** | ||
* NewChatMessageFormFactory | ||
* | ||
* @author Jakub Konečný | ||
*/ | ||
final class NewChatMessageFormFactory { | ||
/** @var ITranslator */ | ||
protected $translator; | ||
|
||
public function __construct(?ITranslator $translator = null) { | ||
if(is_null($translator)) { | ||
$loader = new NeonLoader(); | ||
$loader->folders = [__DIR__ . "/lang"]; | ||
$translator = new Translator($loader); | ||
} | ||
$this->translator = $translator; | ||
} | ||
|
||
public function create(ChatControl $chatControl): Form { | ||
$form = new Form(); | ||
$form->setTranslator($this->translator); | ||
$form->addText("message") | ||
->setRequired("chat.newMessageForm.messageField.empty"); | ||
$form->addSubmit("send", "chat.newMessageForm.submitButton.label"); | ||
$form->addComponent($chatControl, "chat"); | ||
$form->onSuccess[] = function(Form $form, array $values) { | ||
/** @var ChatControl $chat */ | ||
$chat = $form->getComponent("chat"); | ||
$chat->newMessage($values["message"]); | ||
}; | ||
return $form; | ||
} | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
peopleInRoom: "Lidé v této místnosti:" | ||
newMessageForm: | ||
messageField: | ||
empty: "Zadej zprávu." | ||
submitButton: | ||
label: "Odeslat" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
peopleInRoom: "People in this room:" | ||
newMessageForm: | ||
messageField: | ||
empty: "Enter message." | ||
submitButton: | ||
label: "Send" |