openlayers-8.x-4.x-dev/src/OpenlayersConfigurablePluginBase.php
src/OpenlayersConfigurablePluginBase.php
<?php
namespace Drupal\openlayers;
use Drupal\Core\Form\FormStateInterface;
/**
* Provides a base class for configurable Openlayers plugins.
*
* @see \Drupal\image\Annotation\ImageEffect
* @see \Drupal\image\ConfigurableImageEffectInterface
* @see \Drupal\image\ImageEffectInterface
* @see \Drupal\image\ImageEffectBase
* @see \Drupal\image\ImageEffectManager
* @see plugin_api
*/
abstract class OpenlayersConfigurablePluginBase extends OpenlayersPluginBase implements OpenlayersConfigurablePluginInterface {
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function getEntity() {
if (!isset($this->configuration['entityId'])) {
return NULL;
}
$entity = \Drupal::entityTypeManager()
->getStorage('openlayers_layer')
->load($this->configuration['entityId'])
;
return $entity;
}
public function getExportConfig($configEntity) {
$exportConfig = [
'machine_name' => $configEntity['id'],
'factory_service' => $configEntity['service'],
'options' => [],
];
$types = ['layers', 'controls', 'interactions', 'components']; // TODO - temporary. Should ideally generate this list automatically.
foreach ($types as $type) {
if (!empty($configEntity[$type])) {
foreach ($configEntity[$type] as $key => $item) {
// $exportConfig['options'][$type][] = isset($item['data']['entityId']) ? $item['data']['entityId'] : NULL;
$exportConfig['options'][$type][] = isset($item['id']) ? $item['id'] : NULL;
}
}
}
if (!isset($this->options) || $this->options === NULL) {
$this->options = [];
}
$this->configuration = array_merge($this->configuration, $exportConfig);
$this->options = array_merge($this->options, $exportConfig['options']);
return $exportConfig;
}
}
