You are here

public function NotificationsWidgetBlock::blockForm in Notifications widget 8

Returns the configuration form elements specific to this block plugin.

Blocks that need to add form elements to the normal block configuration form should implement this method.

Parameters

array $form: The form definition array for the block configuration form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The renderable form array representing the entire configuration form.

Overrides BlockPluginTrait::blockForm

File

src/Plugin/Block/NotificationsWidgetBlock.php, line 73

Class

NotificationsWidgetBlock
Provides a block with list of notification items.

Namespace

Drupal\notifications_widget\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $form = parent::blockForm($form, $form_state);

  // Retrieve existing configuration for this block.
  $config = $this
    ->getConfiguration();

  // Add a form field to the existing block configuration form.
  $form['block_notification_type'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Notification Content'),
    '#options' => [
      'As Admin',
      'As Logged-In user',
    ],
    '#default_value' => isset($config['block_notification_type']) ? $config['block_notification_type'] : '',
  ];
  $form['block_notification_logs_display'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Skip Display to own activities'),
    '#default_value' => TRUE,
  ];
  return $form;
}