class AnonymousPublishingClAdminBlocked in Anonymous Publishing 8
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\anonymous_publishing_cl\Form\AnonymousPublishingClAdminBlocked
Expanded class hierarchy of AnonymousPublishingClAdminBlocked
1 string reference to 'AnonymousPublishingClAdminBlocked'
- anonymous_publishing_cl.routing.yml in modules/
anonymous_publishing_cl/ anonymous_publishing_cl.routing.yml - modules/anonymous_publishing_cl/anonymous_publishing_cl.routing.yml
File
- modules/
anonymous_publishing_cl/ src/ Form/ AnonymousPublishingClAdminBlocked.php, line 11
Namespace
Drupal\anonymous_publishing_cl\FormView source
class AnonymousPublishingClAdminBlocked extends FormBase {
/**
* The database connection service.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('database'));
}
/**
* Constructs a \Drupal\anonymous_publishing_cl\Form\AnonymousPublishingClAdminModeration object.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection service.
*/
public function __construct(Connection $database) {
$this->database = $database;
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'anonymous_publishing_cl_admin_blocked';
}
public function buildForm(array $form, FormStateInterface $form_state) {
// Build an 'Update options' form.
$form['options'] = array(
'#type' => 'details',
'#title' => $this
->t('Update options'),
'#open' => TRUE,
'#attributes' => array(
'class' => array(
'container-inline',
),
),
);
$options = array(
'block' => $this
->t("Block the email address"),
'unblock' => $this
->t("Unblock the email address"),
);
$form['options']['operation'] = array(
'#type' => 'select',
'#title' => $this
->t('Action'),
'#title_display' => 'invisible',
'#options' => $options,
'#default_value' => 'publish',
);
$form['options']['submit'] = array(
'#type' => 'submit',
'#value' => $this
->t('Update'),
);
$form['apu_info'] = [
'#markup' => t("<p>The table below shows the email address used to verify, IP-address, generated alias, blocked status for all <em>verified</em> email addresses. To block or unblock some email adresses, check each corresponding line's below and execute the desired action.</p><p>Note than an email address is not listed here until it has been verified. For yet unverified addresses, see the <em>unverified</em> tab.</p>"),
];
$header = array(
'email' => array(
'data' => $this
->t('Verification email'),
),
'ip' => array(
'data' => $this
->t('IP-address'),
),
'alias' => array(
'data' => $this
->t('Byline (if available)'),
'class' => array(
RESPONSIVE_PRIORITY_MEDIUM,
),
),
);
$options = array();
// Fetch all emails.
$rows = $this
->getAllBlockedContents();
// Build the table.
foreach ($rows as $row) {
$options[$row->auid] = array(
'email' => array(
'data' => array(
'#markup' => Html::escape($row->email),
),
),
'ip' => array(
'data' => array(
'#markup' => $row->ipaddress,
),
),
'alias' => array(
'data' => array(
'#markup' => !empty($row->alias) ? Html::escape($row->alias) : $this
->t('- none -'),
),
),
);
}
$form['items'] = array(
'#type' => 'tableselect',
'#header' => $header,
'#options' => $options,
'#empty' => $this
->t('There is no unverified content.'),
);
$form['pager'] = array(
'#type' => 'pager',
);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$form_state
->setValue('items', array_diff($form_state
->getValue('items'), array(
0,
)));
// We can't execute any 'Update options' if no items were selected.
if (count($form_state
->getValue('items')) == 0) {
$form_state
->setErrorByName('', $this
->t('Select one or more items to perform the update on.'));
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$operation = $form_state
->getValue('operation');
$ids = $form_state
->getValue('items');
$blocked = FALSE;
foreach ($ids as $id) {
if ($operation == 'block') {
$blocked = TRUE;
}
$this->database
->update('anonymous_publishing_emails')
->fields('anonymous_publishing_emails', array(
'blocked' => $blocked,
))
->condition('auid', $id)
->execute();
}
$this
->messenger()
->addMessage($this
->t('The update has been performed.'));
}
/**
* Get all contents to moderate.
*
* @param int $test_id
* The test_id to retrieve results of.
*
* @return array
* Array of results grouped by test_class.
*/
protected function getAllBlockedContents() {
$query = $this->database
->select('anonymous_publishing_emails', 'e');
$query
->fields('e');
$query
->orderBy('e.auid');
return $query
->execute()
->fetchAll();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AnonymousPublishingClAdminBlocked:: |
protected | property | The database connection service. | |
AnonymousPublishingClAdminBlocked:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
AnonymousPublishingClAdminBlocked:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
AnonymousPublishingClAdminBlocked:: |
protected | function | Get all contents to moderate. | |
AnonymousPublishingClAdminBlocked:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
AnonymousPublishingClAdminBlocked:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
AnonymousPublishingClAdminBlocked:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
AnonymousPublishingClAdminBlocked:: |
public | function | Constructs a \Drupal\anonymous_publishing_cl\Form\AnonymousPublishingClAdminModeration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
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. | 1 |
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. Overrides UrlGeneratorTrait:: |
|
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. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
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. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
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. | 1 |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |