You are here

public function OpenlayersPluginFormBase::buildForm in Openlayers 8.4

Parameters

\Drupal\image\ImageStyleInterface $image_style: The openlayers map.

string $image_effect: The openlayers plugin ID.

Return value

array The form structure.

Throws

\Symfony\Component\HttpKernel\Exception\NotFoundHttpException

Overrides FormInterface::buildForm

4 calls to OpenlayersPluginFormBase::buildForm()
OpenlayersControlPluginAddForm::buildForm in src/Form/OpenlayersControlPluginAddForm.php
Form constructor.
OpenlayersInteractionPluginAddForm::buildForm in src/Form/OpenlayersInteractionPluginAddForm.php
Form constructor.
OpenlayersPluginEditForm::buildForm in src/Form/OpenlayersPluginEditForm.php
Form constructor.
OpenlayersStylePluginAddForm::buildForm in src/Form/OpenlayersStylePluginAddForm.php
Form constructor.
4 methods override OpenlayersPluginFormBase::buildForm()
OpenlayersControlPluginAddForm::buildForm in src/Form/OpenlayersControlPluginAddForm.php
Form constructor.
OpenlayersInteractionPluginAddForm::buildForm in src/Form/OpenlayersInteractionPluginAddForm.php
Form constructor.
OpenlayersPluginEditForm::buildForm in src/Form/OpenlayersPluginEditForm.php
Form constructor.
OpenlayersStylePluginAddForm::buildForm in src/Form/OpenlayersStylePluginAddForm.php
Form constructor.

File

src/Form/OpenlayersPluginFormBase.php, line 54

Class

OpenlayersPluginFormBase
Provides a base form for the settings for Openlayers plugins.

Namespace

Drupal\openlayers\Form

Code

public function buildForm(array $form, FormStateInterface $form_state, OpenlayersMapInterface $map = NULL, $plugin_type = NULL, $plugin = NULL) {
  $this->olMap = $map;
  try {
    $this->olPlugin = $this
      ->preparePlugin($plugin_type, $plugin);
  } catch (PluginNotFoundException $e) {
    throw new NotFoundHttpException("Invalid plugin id: '{$plugin}'.");
  }
  $definition = $this->olPlugin
    ->getPluginDefinition();
  $request = $this
    ->getRequest();
  if (!$this->olPlugin instanceof OpenlayersConfigurablePluginInterface) {
    throw new NotFoundHttpException();
  }
  $form['#attached']['library'][] = 'image/admin';

  //  TODO
  $form['uuid'] = [
    '#type' => 'value',
    '#value' => $this->olPlugin
      ->getUuid(),
  ];
  $form['id'] = [
    '#type' => 'value',
    '#value' => $this->olPlugin
      ->getPluginId(),
  ];
  $form['data'] = [];
  $subform_state = SubformState::createForSubform($form['data'], $form, $form_state);
  $form['data'] = $this->olPlugin
    ->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' => isset($this->olPlugin->ol_id) ? $this->olPlugin->ol_id : $this->olPlugin
      ->getWeight(),
  ];

  // Check the URL for a weight, then the image effect, otherwise use default.
  $form['ol_id'] = [
    '#type' => 'hidden',
    '#value' => isset($definition['ol_id']) ? $definition['ol_id'] : '???',
  ];
  $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;
}