You are here

public function MapStyleFormBase::buildForm in Openlayers 8.4

Parameters

\Drupal\image\ImageStyleInterface $image_style: The image style.

string $image_effect: The image effect ID.

Return value

array The form structure.

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException

Overrides FormInterface::buildForm

File

src/Form/MapStyleFormBase.php, line 55

Class

MapStyleFormBase
Provides a base form for image effects.

Namespace

Drupal\openlayers\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, OpenlayersMapInterface $map = NULL, $layer = NULL) {
  $request = $this
    ->getRequest();
  $user_input = $form_state
    ->getUserInput();
  $form['#attached']['library'][] = 'openlayers/admin';
  $this->olMap = $map;
  if (isset($this->olMap->layers[$layer])) {
    $this->mapLayer = new MapLayer($this->olMap->layers[$layer], 'update');
  }
  else {
    $this->mapLayer = new MapLayer($layer, 'add');
  }
  $form['uuid'] = [
    '#type' => 'value',
    '#value' => $this->mapLayer
      ->getUuid(),
  ];
  $form['id'] = [
    '#type' => 'value',
    '#value' => $this->mapLayer
      ->id(),
  ];
  $form['data'] = [];
  $subform_state = SubformState::createForSubform($form['data'], $form, $form_state);
  $form['data'] = $this->mapLayer
    ->buildConfigurationForm($form['data'], $subform_state);
  $form['data']['#tree'] = TRUE;

  // Check the URL for a weight, then the image effect, otherwise use default.
  $form['weight'] = [
    '#type' => 'hidden',
    '#value' => 0,
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#button_type' => 'primary',
  ];
  $form['actions']['cancel'] = [
    '#type' => 'link',
    '#title' => $this
      ->t('Cancel'),
    '#url' => $this->olMap
      ->toUrl('edit-form'),
    '#attributes' => [
      'class' => [
        'button',
      ],
    ],
  ];
  return $form;
}