You are here

public function ViewBlockBase::getConfigSpecificFormFields in Content Planner 8

Add additonal form elements specific to the Plugin.

Parameters

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

\Symfony\Component\HttpFoundation\Request $request: The request.

array $block_configuration: The block configuration.

Return value

mixed Gets the config form fields.

Overrides DashboardBlockBase::getConfigSpecificFormFields

File

src/Plugin/DashboardBlock/ViewBlockBase.php, line 56

Class

ViewBlockBase
Class ViewBlockBase.

Namespace

Drupal\content_planner\Plugin\DashboardBlock

Code

public function getConfigSpecificFormFields(FormStateInterface &$form_state, Request &$request, array $block_configuration) {
  $form = [];

  // View.
  $view_default_value = $this
    ->getCustomConfigByKey($block_configuration, $this->blockID);
  $view_options = [];
  $views = Views::getAllViews();
  foreach ($views as $view) {
    $displays = $view
      ->get('display');
    if (is_array($displays)) {
      foreach ($displays as $display) {
        $view_options[$view
          ->id() . '.' . $display['id']] = $view
          ->label() . ' (' . $display['display_title'] . ')';
      }
    }
  }
  $form[$this->blockID] = [
    '#type' => 'select',
    '#title' => t('View'),
    '#options' => $view_options,
    '#required' => TRUE,
    '#default_value' => $view_default_value,
  ];
  return $form;
}