openlayers-8.x-4.x-dev/src/Plugin/Control/Attribution/Attribution.php
src/Plugin/Control/Attribution/Attribution.php
<?php
namespace Drupal\openlayers\Plugin\Control\Attribution;
use Drupal\Core\Form\FormStateInterface;
use Drupal\openlayers\Types\Control;
//use Drupal\Component\Utility\Color;
//use Drupal\Component\Utility\Rectangle;
/**
* Defines the Attribution control for an Openlayers map.
*
* @OpenlayersPlugin(
* id = "ol_control_attribution",
* label = @Translation("Attribution"),
* description = @Translation("An attribution control."),
* service = "openlayers.Control:Attribution",
* library = "openlayers-plugin-control-attribution",
* is_configurable = "true",
* type = "control"
* )
*/
class Attribution extends Control {
/**
* {@inheritdoc}
*/
public function getSummary() {
$summary = [
'#theme' => 'openlayers_control_attribution_summary',
'#data' => $this->configuration,
];
$summary += parent::getSummary();
return $summary;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return [
'className' => 'ol-attribution',
'collapsible' => TRUE,
'collapsed' => FALSE,
'tipLabel' => 'Attributions',
'label' => 'aaaaaaaaaaaaaa',
'collapseLabel' => 'bbbbbbbbbbbbbbbb',
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
foreach($form['options'] as $key => $item) {
$this->configuration[$key] = $form['options'][$key];
}
$form['options']['className'] = [
'#type' => 'textfield',
'#default_value' => $this->configuration['className'],
'#title' => t('Class name'),
'#description' => t('CSS class name.'),
'#size' => 50,
'#maxlength' => 50,
'#required' => FALSE,
];
$form['options']['collapsible'] = array(
'#type' => 'checkbox',
'#title' => $this->t('Collapsible'),
'#description' => t('Specify if attributions can be collapsed.'),
'#default_value' => $this->configuration['collapsible'],
);
$form['options']['collapsed'] = array(
'#type' => 'checkbox',
'#title' => $this->t('Collapsed'),
'#description' => t('Specify if attributions should be collapsed at startup.'),
'#default_value' => $this->configuration['collapsed'], // Specify if attributions can be collapsed.
);
$form['options']['tipLabel'] = [
'#type' => 'textfield',
'#default_value' => $this->configuration['tipLabel'],
'#title' => t('Tip label'),
'#description' => t('Text label to use for the button tip.'),
'#size' => 100,
'#maxlength' => 100,
'#required' => FALSE,
];
$form['options']['label'] = [
'#type' => 'textfield',
'#default_value' => $this->configuration['label'],
'#title' => t('Label'),
'#description' => t('Text label to use for the collapsed attributions button.'),
'#size' => 100,
'#maxlength' => 100,
'#required' => FALSE,
];
$form['options']['collapseLabel'] = [
'#type' => 'textfield',
'#default_value' => $this->configuration['collapseLabel'],
'#title' => t('Collapse label'),
'#description' => t('Text label to use for the expanded attributions button.'),
'#size' => 100,
'#maxlength' => 100,
'#required' => FALSE,
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
foreach($form_state->getValues() as $key => $item) {
$this->configuration[$key] = $form_state->getValue($key);
}
}
}
