l10n_server-2.x-dev/l10n_community/src/Form/JumpForm.php
l10n_community/src/Form/JumpForm.php
<?php declare(strict_types=1); namespace Drupal\l10n_community\Form; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; /** * Provides a Localization community UI form. */ class JumpForm extends FormBase { /** * {@inheritdoc} */ public function getFormId() { return 'l10n_community_jump'; } /** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form['project'] = [ '#type' => 'entity_autocomplete', '#target_type' => 'l10n_server_project', "#prefix" => '<strong>' . $this->t('Pick a project to jump to') . '</strong>', ]; $form['actions'] = [ '#type' => 'actions', ]; $form['actions']['submit'] = [ '#type' => 'submit', '#value' => $this->t('Go'), ]; return $form; } /** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { if ($pid = $form_state->getValue('project')) { $project = \Drupal::entityTypeManager() ->getStorage('l10n_server_project') ->load($pid); if ($project) { $url = Url::fromUri('internal:/translate/projects/' . $pid); $form_state->setRedirectUrl($url); } } } }