diff --git a/insert.module b/insert.module index a0e9553..d43a649 100644 --- a/insert.module +++ b/insert.module @@ -89,6 +89,16 @@ function insert_styles($reset = FALSE) { return $styles; } + /** + * Get a list of all supported picture groups. + */ +function insert_picture_groups($reset = FALSE) { + if (module_exists('picture')) { + return picture_get_mapping_options(); + } + return array(); +} + /** * Sort the styles. */ @@ -117,6 +127,27 @@ function insert_styles_list() { return $list; } + /** + * Get a list of picture groups suitable for an #options array. + */ +function insert_picture_groups_list() { + $list = insert_picture_groups(); + foreach ($list as $key => $value) { + $list[$key] = 'Picture: ' . $value; + } + return $list; +} + +/** + * Get a list of styles suitable for an #options array. + * Merge of picture groups and styles. + */ +function insert_styles_list_all() { + $list = array_merge(insert_styles_list(), insert_picture_groups_list()); + return $list; +} + + /** * Get a list of all supported field widgets. */ @@ -233,6 +264,36 @@ function insert_element_process($element) { ); } + // Loop through the picture groups, appending to the final list + $picture_groups = insert_picture_groups(); + $insert_picture_groups = (isset($widget_settings['insert_picture_groups']) ? $widget_settings['insert_picture_groups'] : array()); + foreach ($insert_picture_groups as $picture_group_name => $enabled) { + if ($enabled && isset($picture_groups[$picture_group_name])) { + // Setup the image html using similar token format as ckeditor used as + // then it will be parsed using a prebuilt and shared function. + $filepath = parse_url(file_create_url($item['uri'])); + $filepath = $filepath['path']; + $variables = array( + 'path' => $filepath, + 'attributes' => array( + 'data-picture-group' => $picture_group_name, + 'class' => !empty($widget_settings['insert_class']) ? $widget_settings['insert_class'] : '', + ), + ); + $inserted_token = theme_image($variables); + + $element['insert_templates'][$picture_group_name] = array( + '#type' => 'hidden', + '#value' => $inserted_token, + '#id' => $element['#id'] . '-insert-template-' . str_replace('_', '-', $picture_group_name), + '#name' => $element['#name'] . '[insert_template][' . $picture_group_name . ']', + '#attributes' => array('class' => array('insert-template')), + ); + $style_options[$picture_group_name] = 'Picture: ' . $picture_group_name; + } + } + + $element['insert'] = array( '#theme' => 'insert_widget', '#type' => 'markup', @@ -326,13 +387,25 @@ function insert_field_widget_settings_form($field, $instance) { '#weight' => 0, ); + if (insert_picture_groups_list()) { + $form['insert']['insert_picture_groups'] = array( + '#title' => t('Enabled insert picture'), + '#type' => 'checkboxes', + '#options' => insert_picture_groups_list(), + '#default_value' => !isset($settings['insert_picture_groups']) ? '' : $settings['insert_picture_groups'], + '#description' => t('Select which picture groups should be available when sending items to text areas. If no styles are selected, the option to use a style is not displayed.'), + '#theme' => 'insert_field_widget_settings_styles', + '#weight' => 1, + ); + } + $form['insert']['insert_default'] = array( - '#title' => t('Default insert style'), + '#title' => t('Default insert style/picture group'), '#type' => 'select', - '#options' => insert_styles_list(), + '#options' => insert_styles_list_all(), '#default_value' => $settings['insert_default'], '#description' => t('Select the default style which will be selected by default or used if no specific styles above are enabled.'), - '#weight' => 1, + '#weight' => 2, ); $form['insert']['insert_class'] = array(