class PhotosAccessPasswordForm in Album Photos 6.0.x
Same name and namespace in other branches
- 8.5 photos_access/src/Form/PhotosAccessPasswordForm.php \Drupal\photos_access\Form\PhotosAccessPasswordForm
- 8.4 photos_access/src/Form/PhotosAccessPasswordForm.php \Drupal\photos_access\Form\PhotosAccessPasswordForm
Defines a form to upload photos to this site.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\photos_access\Form\PhotosAccessPasswordForm
Expanded class hierarchy of PhotosAccessPasswordForm
File
- photos_access/
src/ Form/ PhotosAccessPasswordForm.php, line 15
Namespace
Drupal\photos_access\FormView source
class PhotosAccessPasswordForm extends FormBase {
/**
* The database connection used to check the password.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Construct the PhotosAccessPasswordForm.
*
* @param \Drupal\Core\Database\Connection $connection
* The database connection which will be used to check the password.
*/
public function __construct(Connection $connection) {
$this->connection = $connection;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
// Instantiates this form class.
return new static($container
->get('database'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'photos_access_password';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $node = NULL) {
$form['pass'] = [
'#type' => 'password',
'#title' => $this
->t('Please enter album password'),
'#attributes' => [
'autocomplete' => 'off',
],
];
$form['nid'] = [
'#type' => 'value',
'#value' => $node
->id(),
];
$form['submit'] = [
'#type' => 'submit',
'#value' => $this
->t('Submit'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$node = $this->connection
->query("SELECT pass, nid FROM {photos_access_album} WHERE nid = :nid AND pass = :pass", [
':nid' => $form_state
->getValue('nid'),
':pass' => md5($form_state
->getValue('pass')),
])
->fetchObject();
if (isset($node->pass)) {
$_SESSION[$node->nid . '_' . session_id()] = $node->pass;
// Redirect.
$redirect_url = Url::fromUri('base:node/' . $node->nid)
->toString();
return new RedirectResponse($redirect_url);
}
else {
$form_state
->setErrorByName('pass', $this
->t('Password required'));
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// ...
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PhotosAccessPasswordForm:: |
protected | property | The database connection used to check the password. | |
PhotosAccessPasswordForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
PhotosAccessPasswordForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
PhotosAccessPasswordForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
PhotosAccessPasswordForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
PhotosAccessPasswordForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
PhotosAccessPasswordForm:: |
public | function | Construct the PhotosAccessPasswordForm. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |