[{"value_1":"Dragon fly"},{"value_1":"Agapostemon angelicus"},{"value_1":"Albuna oberthuri"},{"value_1":"Callohesma flavopicta"}]
This is a JSON data i need to use to import for radios in drupal 8 webforms. Iam using hook_webform_options_WEBFORM_OPTIONS_ID_alter() https://www.drupal.org/docs/8/modules/webform/webform-cookbook/how-to-use-options-from-an-external-webservice
I cant use value_1 as a key in radios, cause it is not unique, so I need to somehow copy the value into the key and get the same data on both sides, too look like this.
[{"Dragon fly":"Dragon fly"},{"Agapostemon angelicus":"Agapostemon angelicus"},{"Albuna oberthuri":"Albuna oberthuri"},{"Callohesma flavopicta":"Callohesma flavopicta"}]
there are many lists and many data but the same problem.
This is the code from the module I made followed by instructions:
* Implements hook_webform_options_WEBFORM_OPTIONS_ID_alter().
*/
function my_module_webform_options_external_countries_alter(array &$options, array &$element) {
// Load cached options.
if ($cache = \Drupal::cache()->get('external_countries')) {
$options = $cache->data;
return;
}
// Get data as associative array from the external webservice.
$external_countries_url = 'https://gist.githubusercontent.com/mshafrir/2646763/raw/8b0dbb93521f5d6889502305335104218454c2bf/states_hash.json';
$options = json_decode(file_get_contents($external_countries_url), TRUE);
// Cache options so that we don't have to make continual requests
// to the external webservice.
\Drupal::cache()->set('external_countries', $options);
}