You are here

public function DashboardAssignBlockForm::buildForm in Draggable dashboard 8.2

Builds assign block form.

Parameters

array $form: Form array.

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

\Drupal\draggable_dashboard\Entity\DashboardEntityInterface|null $dashboard_entity: Current dashboard.

string $plugin_id: Block plugin id.

int $region: Column to insert block to.

Return value

array

Throws

\Drupal\Component\Plugin\Exception\PluginException

Overrides DashboardBlockFormBase::buildForm

File

src/Form/DashboardAssignBlockForm.php, line 54

Class

DashboardAssignBlockForm
Class DashboardAssignBlockForm

Namespace

Drupal\draggable_dashboard\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, DashboardEntityInterface $dashboard_entity = NULL, $plugin_id = '', $region = 1) {

  // During the initial form build, add this form object to the form state and
  // allow for initial preparation before form building and processing.
  if (!$form_state
    ->has('form_initialized')) {
    $this
      ->init($form_state, $dashboard_entity, $plugin_id);
  }
  $regions = [];
  for ($i = 1; $i <= $dashboard_entity
    ->get('columns'); $i++) {
    $regions[$i] = t('Column') . ' ' . $i;
  }
  $form['column'] = [
    '#type' => 'select',
    '#title' => $this
      ->t('Region'),
    '#description' => $this
      ->t('Select the region where this block should be displayed.'),
    '#default_value' => $region,
    '#required' => TRUE,
    '#options' => $regions,
  ];
  return parent::buildForm($form, $form_state);
}