You are here

public function VarbaseContentOverview::blockForm in Varbase Total Control Dashboard 8

Same name and namespace in other branches
  1. 8.6 src/Plugin/Block/VarbaseContentOverview.php \Drupal\varbase_total_control\Plugin\Block\VarbaseContentOverview::blockForm()
  2. 8.5 src/Plugin/Block/VarbaseContentOverview.php \Drupal\varbase_total_control\Plugin\Block\VarbaseContentOverview::blockForm()
  3. 9.0.x src/Plugin/Block/VarbaseContentOverview.php \Drupal\varbase_total_control\Plugin\Block\VarbaseContentOverview::blockForm()

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/VarbaseContentOverview.php, line 120

Class

VarbaseContentOverview
Provides a 'Varbase Content Overview'.

Namespace

Drupal\varbase_total_control\Plugin\Block

Code

public function blockForm($form, FormStateInterface $form_state) {
  $form = parent::blockForm($form, $form_state);
  $config = $this
    ->getConfiguration();
  $types = node_type_get_types();
  $type_defaults = [];
  foreach ($types as $type => $object) {
    $type_options[$type] = $object
      ->get('name');
    if (!array_key_exists($type, $type_defaults)) {
      $type_defaults[$type] = $type;
    }
  }
  $form['varbase_total_control_types_overview'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Show post counts for the following content types'),
    '#options' => $type_defaults,
    '#default_value' => $config['varbase_total_control_types_overview'],
  ];
  $form['varbase_total_control_comments_overview'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Show comment counts for the following content types'),
    '#options' => $type_defaults,
    '#default_value' => $config['varbase_total_control_comments_overview'],
  ];
  $spam_options = [
    0 => t('no'),
    1 => t('Yes'),
  ];
  $form['varbase_total_control_spam_overview'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Include spam counts with comments'),
    '#options' => $spam_options,
    '#default_value' => $config['varbase_total_control_spam_overview'],
  ];
  return $form;
}