You are here

function _social_event_type_change_topic_icon_ajax in Open Social 10.2.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_event/modules/social_event_type/social_event_type.module \_social_event_type_change_topic_icon_ajax()
  2. 10.0.x modules/social_features/social_event/modules/social_event_type/social_event_type.module \_social_event_type_change_topic_icon_ajax()
  3. 10.1.x modules/social_features/social_event/modules/social_event_type/social_event_type.module \_social_event_type_change_topic_icon_ajax()

Ajax callback to change event type icon.

1 string reference to '_social_event_type_change_topic_icon_ajax'
social_event_type_form_taxonomy_term_event_types_form_alter in modules/social_features/social_event/modules/social_event_type/social_event_type.module
Implements hook_form_FORM_ID_alter().

File

modules/social_features/social_event/modules/social_event_type/social_event_type.module, line 164
The Social event type module.

Code

function _social_event_type_change_topic_icon_ajax(array $form, FormStateInterface $form_state) {
  $response = new AjaxResponse();
  $icon = $form_state
    ->getValue('field_event_type_icon')[0]['value'];
  $replaced = [
    '#type' => 'inline_template',
    '#template' => '<div class="icon-svg-wrapper" data-href="#' . $icon . '"><svg class="selected-svg"><use xlink:href="#' . $icon . '"></use></svg>{{ svg_icons|raw }}</div>',
    '#context' => [
      'svg_icons' => file_get_contents(drupal_get_path('theme', 'socialbase') . '/assets/icons/icons.svg'),
    ],
  ];
  $response
    ->addCommand(new ReplaceCommand('.icon-svg-wrapper', $replaced));
  return $response;
}