openlayers-8.x-4.x-dev/src/Plugin/Style/InlineJS/InlineJS.php
src/Plugin/Style/InlineJS/InlineJS.php
<?php
namespace Drupal\openlayers\Plugin\Style\InlineJS;
use Drupal\Core\Form\FormStateInterface;
use Drupal\openlayers\Types\Style;
/**
* FIX - Insert short comment here.
*
* @OpenlayersPlugin(
* id = "ol_style_inlinejs",
* label = @Translation("Inline JS"),
* description = @Translation("TODO..."),
* service = "openlayers.Style:InlineJS",
* library = "openlayers-plugin-style-inlinejs",
* is_configurable = "true",
* type = "style"
* )
*/
class InlineJS extends Style {
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$attached = array();
if (module_exists('ace_editor')) {
$attached = array(
'library' => array(
array('ace_editor', 'ace'),
),
'js' => array(
drupal_get_path('module', 'openlayers') . '/js/openlayers.editor.js',
),
);
}
else {
\Drupal::service('messenger')->addMessage(t(
'To get syntax highlighting, you should install the module
<a href="@url1">ace_editor</a> and its <a href="@url2">library</a>.',
array(
'@url1' => 'http://drupal.org/project/ace_editor',
'@url2' => 'http://ace.c9.io/',
)
), 'warning');
}
$form['options']['javascript'] = array(
'#type' => 'textarea',
'#title' => t('Javascript'),
'#description' => t('Write here the content of the Javascript function
for the style. The available variable are: <em>feature</em> and <em>resolution</em>.
The function should return an array of ol.style.Style.'
),
'#rows' => 15,
'#default_value' => $this->getOption('javascript'),
'#attributes' => array(
'data-editor' => 'javascript',
),
'#attached' => $attached,
);
return $form;
}
}
