/** * {@inheritdoc} */ public function optionsForm(&$form, &$form_state) { foreach (Openlayers::getGeometryTypes() as $geometry_type => $geometry) { if (!in_array($geometry_type, array('Point', 'LineString', 'Polygon'))) { continue; } $enabled = (bool) $this->getOption(array($geometry_type, 'count'), FALSE); $form['options'][$geometry_type] = array('#type' => 'fieldset', '#title' => t('Geometry @geometry', array('@geometry' => $geometry)), '#collapsible' => TRUE, '#collapsed' => !$enabled); $form['options'][$geometry_type]['count'] = array('#type' => 'textfield', '#title' => t('Number of features'), '#default_value' => $this->getOption(array($geometry_type, 'count'), 0), '#required' => TRUE); $form['options'][$geometry_type]['setRandomStyle'] = array('#type' => 'checkbox', '#title' => t('Set random style on features ?'), '#default_value' => $this->getOption(array($geometry_type, 'setRandomStyle'), 0)); $form['options'][$geometry_type]['styles'] = array('#type' => 'select', '#title' => t('Styles'), '#empty_option' => t('- Select the Styles -'), '#default_value' => $this->getOption(array($geometry_type, 'styles'), array()), '#description' => t('Select the styles.'), '#options' => Openlayers::loadAllAsOptions('Style'), '#multiple' => TRUE, '#states' => array('visible' => array('input[name="options[' . $geometry_type . '][setRandomStyle]"' => array('checked' => TRUE)))); } }
/** * {@inheritdoc} */ public function optionsFormSubmit($form, &$form_state) { parent::optionsFormSubmit($form, $form_state); $options = $this->getOptions(); foreach (Openlayers::getGeometryTypes() as $geometry_type => $geometry) { if ((bool) $options[$geometry_type]['enabled'] === FALSE) { unset($options[$geometry_type]); } } $this->setOptions($options); $form_state['values']['options'] = $options; parent::optionsFormSubmit($form, $form_state); }