You are here

public function DashboardBlockConfigForm::buildForm in Content Planner 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

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

Return value

array The form structure.

Overrides ConfigFormBase::buildForm

File

src/Form/DashboardBlockConfigForm.php, line 64

Class

DashboardBlockConfigForm
Defines a form that configures forms module settings.

Namespace

Drupal\content_planner\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL, $block_id = NULL) {

  // Get plugin definition.
  $plugin_definition = $this->dashboardBlockPluginManager
    ->getDefinition($block_id);
  if (!$plugin_definition) {
    $this
      ->messenger()
      ->addError($this
      ->t('Plugin with @block_id does not exist', [
      '@block_id' => $block_id,
    ]));
    return [];
  }
  $form['block_id'] = [
    '#type' => 'value',
    '#value' => $block_id,
  ];

  // Get block configuration.
  $block_configuration = $this->dashboardSettingsService
    ->getBlockConfiguration($block_id);

  // Build Basic Fields.
  $this
    ->buildBasicFields($form, $form_state, $request, $block_configuration);

  // Create instance.
  $instance = $this
    ->createInstanceFromBlockId($block_id);

  // Build plugin form elements.
  if ($config_specific_fields = $instance
    ->getConfigSpecificFormFields($form_state, $request, $block_configuration)) {
    $form['plugin_specific_config'] = [
      '#type' => 'fieldset',
      '#title' => t('Extra Settings'),
      '#collapsible' => FALSE,
      '#collapsed' => FALSE,
      '#tree' => TRUE,
    ];
    foreach ($config_specific_fields as $field_name => $field_settings) {
      $form['plugin_specific_config'][$field_name] = $field_settings;
    }
  }
  return parent::buildForm($form, $form_state);
}