o365-2.0.3/modules/o365_sharepoint_file/src/Form/SearchSharepointForm.php
modules/o365_sharepoint_file/src/Form/SearchSharepointForm.php
<?php
namespace Drupal\o365_sharepoint_file\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
/**
* Provides a o365_files form.
*/
class SearchSharepointForm extends FormBase {
/**
* The request stack.
*
* @var \Symfony\Component\HttpFoundation\RequestStack
*/
protected $requestStack;
/**
* Constructs a SearchSharepointForm object.
*
* @param \Symfony\Component\HttpFoundation\RequestStack $requestStack
* The request stack.
*/
public function __construct(RequestStack $requestStack) {
$this->requestStack = $requestStack;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new self(
$container->get('request_stack')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'o365_sharepoint_search_file';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$keyword = $this->requestStack->getCurrentRequest()->get('keyword');
$form['keyword'] = [
'#title' => $this->t('Search for files'),
'#type' => 'textfield',
'#title_display' => 'invisible',
'#default_value' => ($keyword) ?: '',
];
$form['actions'] = [
'#type' => 'actions',
];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Search files'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state->setRedirect('o365_sharepoint_file.search', ['keyword' => $form_state->getValue('keyword')]);
}
}
