public function OpenlayersSourceFormBase::buildForm in Openlayers 8.4
Overrides Drupal\Core\Entity\EntityFormController::form().
Builds the entity add/edit form.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: An associative array containing the current state of the form.
Return value
array An associative array containing the openlayers_source add/edit form.
Overrides EntityForm::buildForm
File
- src/
Form/ OpenlayersSourceFormBase.php, line 78
Class
- OpenlayersSourceFormBase
- Class OpenlayersSourceFormBase.
Namespace
Drupal\openlayers\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
// Get anything we need from the base class.
$form = parent::buildForm($form, $form_state);
// Drupal provides the entity to us as a class variable. If this is an
// existing entity, it will be populated with existing values as class
// variables. If this is a new entity, it will be a new object with the
// class of our entity. Drupal knows which class to call from the
// annotation on our Source class.
$openlayers_source = $this->entity;
// Build the form.
$form['label'] = [
'#type' => 'textfield',
'#title' => $this
->t('Label'),
'#maxlength' => 255,
'#default_value' => $openlayers_source
->label(),
'#required' => TRUE,
];
$form['id'] = [
'#type' => 'machine_name',
'#title' => $this
->t('Machine name'),
'#default_value' => $openlayers_source
->id(),
'#machine_name' => [
'exists' => [
$this,
'exists',
],
'replace_pattern' => '([^a-z0-9_]+)|(^custom$)',
'error' => 'The machine-readable name must be unique, and can only contain lowercase letters, numbers, and underscores. Additionally, it can not be the reserved word "custom".',
],
'#disabled' => !$openlayers_source
->isNew(),
];
$options = [
'osm' => 'OSM',
'xyz' => 'XYZ',
'stamen' => 'Stamen',
];
$zoom_options = [
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6',
'7' => '7',
'8' => '8',
'9' => '9',
'10' => '10',
'11' => '11',
'12' => '12',
'13' => '13',
'14' => '14',
'15' => '15',
'16' => '16',
'17' => '17',
'18' => '18',
'19' => '19',
'20' => '20',
];
$opaque_options = [
'true' => 'True',
'false' => 'False',
];
$projection_options = [
'aaaa' => 'Aaaaaa',
'bbbb' => 'Bbbbbb',
];
$form['source_type'] = [
'#title' => t('Source Type'),
'#type' => 'select',
'#description' => t(''),
'#options' => $options,
'#default_value' => $openlayers_source->source_type,
];
$form['url'] = [
'#type' => 'textfield',
'#title' => $this
->t('URL'),
'#maxlength' => 255,
'#default_value' => $openlayers_source->url,
];
$form['max_zoom'] = [
'#title' => t('Maximum Zoom'),
'#type' => 'select',
'#description' => t(''),
'#options' => $zoom_options,
'#default_value' => $openlayers_source->max_zoom,
];
$form['min_zoom'] = [
'#title' => t('Minimum Zoom'),
'#type' => 'select',
'#description' => t(''),
'#options' => $zoom_options,
'#default_value' => $openlayers_source->min_zoom,
];
$form['attributions'] = [
'#type' => 'textfield',
'#title' => $this
->t('Attributions'),
'#maxlength' => 255,
'#default_value' => $openlayers_source->attributions,
];
$form['opaque'] = [
'#title' => t('Opaque'),
'#type' => 'select',
'#description' => t(''),
'#options' => $opaque_options,
'#default_value' => $openlayers_source->opaque,
];
$form['projection'] = [
'#title' => t('Projection'),
'#type' => 'select',
'#description' => t(''),
'#options' => $projection_options,
'#default_value' => $openlayers_source->projection,
];
// Return the form.
return $form;
}